@meru2802/aux-server 1.0.0
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/README.md +168 -0
- package/dist/config/index.d.ts +37 -0
- package/dist/config/index.d.ts.map +1 -0
- package/dist/config/index.js +76 -0
- package/dist/config/swagger.d.ts +2 -0
- package/dist/config/swagger.d.ts.map +1 -0
- package/dist/config/swagger.js +267 -0
- package/dist/controllers/BaseController.d.ts +16 -0
- package/dist/controllers/BaseController.d.ts.map +1 -0
- package/dist/controllers/BaseController.js +28 -0
- package/dist/controllers/apiController.d.ts +8 -0
- package/dist/controllers/apiController.d.ts.map +1 -0
- package/dist/controllers/apiController.js +60 -0
- package/dist/controllers/coreController.d.ts +11 -0
- package/dist/controllers/coreController.d.ts.map +1 -0
- package/dist/controllers/coreController.js +470 -0
- package/dist/controllers/healthController.d.ts +9 -0
- package/dist/controllers/healthController.d.ts.map +1 -0
- package/dist/controllers/healthController.js +35 -0
- package/dist/index.d.ts +13 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +97 -0
- package/dist/lib/utils/index.d.ts +10 -0
- package/dist/lib/utils/index.d.ts.map +1 -0
- package/dist/lib/utils/index.js +78 -0
- package/dist/lib/utils/index.test.d.ts +3 -0
- package/dist/lib/utils/index.test.d.ts.map +1 -0
- package/dist/lib/utils/index.test.js +197 -0
- package/dist/middleware/BaseMiddleware.d.ts +13 -0
- package/dist/middleware/BaseMiddleware.d.ts.map +1 -0
- package/dist/middleware/BaseMiddleware.js +22 -0
- package/dist/middleware/authMiddleware.d.ts +9 -0
- package/dist/middleware/authMiddleware.d.ts.map +1 -0
- package/dist/middleware/authMiddleware.js +287 -0
- package/dist/middleware/index.d.ts +11 -0
- package/dist/middleware/index.d.ts.map +1 -0
- package/dist/middleware/index.js +125 -0
- package/dist/routes/apiRoutes.d.ts +5 -0
- package/dist/routes/apiRoutes.d.ts.map +1 -0
- package/dist/routes/apiRoutes.js +46 -0
- package/dist/routes/coreRoutes.d.ts +5 -0
- package/dist/routes/coreRoutes.d.ts.map +1 -0
- package/dist/routes/coreRoutes.js +158 -0
- package/dist/routes/healthRoutes.d.ts +4 -0
- package/dist/routes/healthRoutes.d.ts.map +1 -0
- package/dist/routes/healthRoutes.js +63 -0
- package/dist/routes/index.d.ts +3 -0
- package/dist/routes/index.d.ts.map +1 -0
- package/dist/routes/index.js +31 -0
- package/dist/routes/swaggerRoutes.d.ts +3 -0
- package/dist/routes/swaggerRoutes.d.ts.map +1 -0
- package/dist/routes/swaggerRoutes.js +35 -0
- package/dist/services/ApplicationService.d.ts +26 -0
- package/dist/services/ApplicationService.d.ts.map +1 -0
- package/dist/services/ApplicationService.js +46 -0
- package/dist/services/DatabaseService.d.ts +17 -0
- package/dist/services/DatabaseService.d.ts.map +1 -0
- package/dist/services/DatabaseService.js +38 -0
- package/dist/services/HttpServerService.d.ts +29 -0
- package/dist/services/HttpServerService.d.ts.map +1 -0
- package/dist/services/HttpServerService.js +101 -0
- package/dist/services/ServiceContainer.d.ts +26 -0
- package/dist/services/ServiceContainer.d.ts.map +1 -0
- package/dist/services/ServiceContainer.js +39 -0
- package/dist/services/WebSocketService.d.ts +27 -0
- package/dist/services/WebSocketService.d.ts.map +1 -0
- package/dist/services/WebSocketService.js +180 -0
- package/dist/types/index.d.ts +218 -0
- package/dist/types/index.d.ts.map +1 -0
- package/dist/types/index.js +19 -0
- package/dist/types/schemas/index.d.ts +31 -0
- package/dist/types/schemas/index.d.ts.map +1 -0
- package/dist/types/schemas/index.js +226 -0
- package/package.json +55 -0
|
@@ -0,0 +1,125 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.asyncHandler = exports.setupMiddleware = exports.notFoundHandler = exports.errorHandler = exports.requestLogger = void 0;
|
|
7
|
+
exports.validateData = validateData;
|
|
8
|
+
const cors_1 = __importDefault(require("cors"));
|
|
9
|
+
const helmet_1 = __importDefault(require("helmet"));
|
|
10
|
+
const express_1 = __importDefault(require("express"));
|
|
11
|
+
const cookie_parser_1 = __importDefault(require("cookie-parser"));
|
|
12
|
+
function validateData(schema) {
|
|
13
|
+
return (req, res, next) => {
|
|
14
|
+
try {
|
|
15
|
+
if (!req.body) {
|
|
16
|
+
res.status(400).json({
|
|
17
|
+
error: "InvalidRequestBodyException",
|
|
18
|
+
code: 400,
|
|
19
|
+
path: req.path,
|
|
20
|
+
message: ["Request body is required"],
|
|
21
|
+
timestamp: new Date().toISOString(),
|
|
22
|
+
});
|
|
23
|
+
return;
|
|
24
|
+
}
|
|
25
|
+
const result = schema.safeParse(req.body);
|
|
26
|
+
if (!result.success) {
|
|
27
|
+
console.error("Validation error:", {
|
|
28
|
+
path: req.path,
|
|
29
|
+
method: req.method,
|
|
30
|
+
errors: result.error.issues,
|
|
31
|
+
body: req.body,
|
|
32
|
+
});
|
|
33
|
+
res.status(400).json({
|
|
34
|
+
error: "InvalidRequestBodyException",
|
|
35
|
+
code: 400,
|
|
36
|
+
path: req.path,
|
|
37
|
+
message: result.error.issues.map((issue) => `${issue.path.join(".")}: ${issue.message}`),
|
|
38
|
+
timestamp: new Date().toISOString(),
|
|
39
|
+
});
|
|
40
|
+
return;
|
|
41
|
+
}
|
|
42
|
+
req.body = result.data;
|
|
43
|
+
next();
|
|
44
|
+
}
|
|
45
|
+
catch (error) {
|
|
46
|
+
console.error("Unexpected error in data validation:", {
|
|
47
|
+
path: req.path,
|
|
48
|
+
method: req.method,
|
|
49
|
+
error: error instanceof Error ? error.message : String(error),
|
|
50
|
+
body: req.body,
|
|
51
|
+
});
|
|
52
|
+
res.status(500).json({
|
|
53
|
+
error: "InternalServerError",
|
|
54
|
+
code: 500,
|
|
55
|
+
path: req.path,
|
|
56
|
+
message: ["An unexpected error occurred during request validation"],
|
|
57
|
+
timestamp: new Date().toISOString(),
|
|
58
|
+
});
|
|
59
|
+
}
|
|
60
|
+
};
|
|
61
|
+
}
|
|
62
|
+
const requestLogger = (req, res, next) => {
|
|
63
|
+
console.log(`${new Date().toISOString()} - ${req.method} ${req.path}`);
|
|
64
|
+
next();
|
|
65
|
+
};
|
|
66
|
+
exports.requestLogger = requestLogger;
|
|
67
|
+
const errorHandler = (error, req, res, next) => {
|
|
68
|
+
console.error("Global error handler:", {
|
|
69
|
+
path: req.path,
|
|
70
|
+
method: req.method,
|
|
71
|
+
error: error.message,
|
|
72
|
+
stack: error.stack,
|
|
73
|
+
body: req.body,
|
|
74
|
+
params: req.params,
|
|
75
|
+
query: req.query,
|
|
76
|
+
timestamp: new Date().toISOString(),
|
|
77
|
+
});
|
|
78
|
+
const isDevelopment = process.env.NODE_ENV === "development";
|
|
79
|
+
res.status(500).json({
|
|
80
|
+
error: "InternalServerError",
|
|
81
|
+
code: 500,
|
|
82
|
+
path: req.path,
|
|
83
|
+
message: isDevelopment
|
|
84
|
+
? [error.message]
|
|
85
|
+
: ["An internal server error occurred"],
|
|
86
|
+
timestamp: new Date().toISOString(),
|
|
87
|
+
...(isDevelopment && { stack: error.stack }),
|
|
88
|
+
});
|
|
89
|
+
};
|
|
90
|
+
exports.errorHandler = errorHandler;
|
|
91
|
+
const notFoundHandler = (req, res) => {
|
|
92
|
+
res.status(404).json({
|
|
93
|
+
error: "Endpoint not found",
|
|
94
|
+
timestamp: new Date().toISOString(),
|
|
95
|
+
path: req.path,
|
|
96
|
+
method: req.method,
|
|
97
|
+
});
|
|
98
|
+
};
|
|
99
|
+
exports.notFoundHandler = notFoundHandler;
|
|
100
|
+
const setupMiddleware = (app, corsOptions) => {
|
|
101
|
+
app.use((0, helmet_1.default)());
|
|
102
|
+
app.use((0, cors_1.default)(corsOptions));
|
|
103
|
+
app.use(express_1.default.json({ limit: "10mb" }));
|
|
104
|
+
app.use(express_1.default.urlencoded({ extended: true }));
|
|
105
|
+
app.use((0, cookie_parser_1.default)());
|
|
106
|
+
app.use(exports.requestLogger);
|
|
107
|
+
};
|
|
108
|
+
exports.setupMiddleware = setupMiddleware;
|
|
109
|
+
const asyncHandler = (fn) => {
|
|
110
|
+
return (req, res, next) => {
|
|
111
|
+
Promise.resolve(fn(req, res, next)).catch((error) => {
|
|
112
|
+
console.error("Unhandled async error:", {
|
|
113
|
+
path: req.path,
|
|
114
|
+
method: req.method,
|
|
115
|
+
error: error instanceof Error ? error.message : String(error),
|
|
116
|
+
stack: error instanceof Error ? error.stack : undefined,
|
|
117
|
+
body: req.body,
|
|
118
|
+
params: req.params,
|
|
119
|
+
query: req.query,
|
|
120
|
+
});
|
|
121
|
+
next(error);
|
|
122
|
+
});
|
|
123
|
+
};
|
|
124
|
+
};
|
|
125
|
+
exports.asyncHandler = asyncHandler;
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import { Router } from "express";
|
|
2
|
+
import { ApiController } from "../controllers/apiController";
|
|
3
|
+
import { AuthMiddleware } from "../middleware/authMiddleware";
|
|
4
|
+
export declare const createApiRoutes: (apiController: ApiController, authMiddleware: AuthMiddleware) => Router;
|
|
5
|
+
//# sourceMappingURL=apiRoutes.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"apiRoutes.d.ts","sourceRoot":"","sources":["../../src/routes/apiRoutes.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,SAAS,CAAC;AACjC,OAAO,EAAE,aAAa,EAAE,MAAM,8BAA8B,CAAC;AAE7D,OAAO,EAAE,cAAc,EAAE,MAAM,8BAA8B,CAAC;AAG9D,eAAO,MAAM,eAAe,GAC1B,eAAe,aAAa,EAC5B,gBAAgB,cAAc,KAC7B,MA6CF,CAAC"}
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.createApiRoutes = void 0;
|
|
4
|
+
const express_1 = require("express");
|
|
5
|
+
const middleware_1 = require("../middleware");
|
|
6
|
+
const schemas_1 = require("../types/schemas");
|
|
7
|
+
const createApiRoutes = (apiController, authMiddleware) => {
|
|
8
|
+
const router = (0, express_1.Router)();
|
|
9
|
+
/**
|
|
10
|
+
* @swagger
|
|
11
|
+
* /api/generate-connect-urls:
|
|
12
|
+
* post:
|
|
13
|
+
* tags:
|
|
14
|
+
* - API
|
|
15
|
+
* summary: Get connection URLs for a mesh node
|
|
16
|
+
* description: Generates authenticated URLs for control, terminal, and file system access to a specific mesh node
|
|
17
|
+
* requestBody:
|
|
18
|
+
* required: true
|
|
19
|
+
* content:
|
|
20
|
+
* application/json:
|
|
21
|
+
* schema:
|
|
22
|
+
* $ref: '#/components/schemas/ConnectUrlsRequest'
|
|
23
|
+
* example:
|
|
24
|
+
* meshNodeId: "node//abc123def456"
|
|
25
|
+
* userId: "john.doe"
|
|
26
|
+
* responses:
|
|
27
|
+
* 200:
|
|
28
|
+
* description: Connection URLs generated successfully
|
|
29
|
+
* content:
|
|
30
|
+
* application/json:
|
|
31
|
+
* schema:
|
|
32
|
+
* $ref: '#/components/schemas/ConnectUrlsResponse'
|
|
33
|
+
* example:
|
|
34
|
+
* control: "https://meshcentral.example.com/?login=token&gotonode=node123&viewmode=11&hide=31"
|
|
35
|
+
* terminal: "https://meshcentral.example.com/?login=token&gotonode=node123&viewmode=12&hide=31"
|
|
36
|
+
* file_system: "https://meshcentral.example.com/?login=token&gotonode=node123&viewmode=13&hide=31"
|
|
37
|
+
* timestamp: "2023-12-01T10:30:00.000Z"
|
|
38
|
+
* 400:
|
|
39
|
+
* $ref: '#/components/responses/BadRequest'
|
|
40
|
+
* 500:
|
|
41
|
+
* $ref: '#/components/responses/InternalServerError'
|
|
42
|
+
*/
|
|
43
|
+
router.post("/generate-connect-urls", (0, middleware_1.asyncHandler)(authMiddleware.icebergAuth), (0, middleware_1.validateData)(schemas_1.generateConnectUrlsSchema), (0, middleware_1.asyncHandler)(apiController.getConnectUrls));
|
|
44
|
+
return router;
|
|
45
|
+
};
|
|
46
|
+
exports.createApiRoutes = createApiRoutes;
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import { Router } from "express";
|
|
2
|
+
import { CoreController } from "../controllers/coreController";
|
|
3
|
+
import { AuthMiddleware } from "../middleware/authMiddleware";
|
|
4
|
+
export declare const createCoreRoutes: (coreController: CoreController, authMiddleware: AuthMiddleware) => Router;
|
|
5
|
+
//# sourceMappingURL=coreRoutes.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"coreRoutes.d.ts","sourceRoot":"","sources":["../../src/routes/coreRoutes.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,SAAS,CAAC;AAEjC,OAAO,EAAE,cAAc,EAAE,MAAM,+BAA+B,CAAC;AAC/D,OAAO,EAAE,cAAc,EAAE,MAAM,8BAA8B,CAAC;AAU9D,eAAO,MAAM,gBAAgB,GAC3B,gBAAgB,cAAc,EAC9B,gBAAgB,cAAc,KAC7B,MA+KF,CAAC"}
|
|
@@ -0,0 +1,158 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.createCoreRoutes = void 0;
|
|
4
|
+
const express_1 = require("express");
|
|
5
|
+
const middleware_1 = require("../middleware");
|
|
6
|
+
const schemas_1 = require("../types/schemas");
|
|
7
|
+
const createCoreRoutes = (coreController, authMiddleware) => {
|
|
8
|
+
const router = (0, express_1.Router)();
|
|
9
|
+
/**
|
|
10
|
+
* @swagger
|
|
11
|
+
* /core/generate-download-link:
|
|
12
|
+
* post:
|
|
13
|
+
* tags:
|
|
14
|
+
* - Core
|
|
15
|
+
* summary: Get download link for a device group
|
|
16
|
+
* description: Generates a download link for MeshCentral agent based on device group name
|
|
17
|
+
* requestBody:
|
|
18
|
+
* required: true
|
|
19
|
+
* content:
|
|
20
|
+
* application/json:
|
|
21
|
+
* schema:
|
|
22
|
+
* $ref: '#/components/schemas/DownloadLinkRequest'
|
|
23
|
+
* example:
|
|
24
|
+
* deviceGroupName: "production-servers"
|
|
25
|
+
* responses:
|
|
26
|
+
* 200:
|
|
27
|
+
* description: Download link generated successfully
|
|
28
|
+
* content:
|
|
29
|
+
* application/json:
|
|
30
|
+
* schema:
|
|
31
|
+
* $ref: '#/components/schemas/DownloadLinkResponse'
|
|
32
|
+
* example:
|
|
33
|
+
* download_link: "https://meshcentral.example.com/meshagents?id=10006&meshid=abc123&ac=02"
|
|
34
|
+
* timestamp: "2023-12-01T10:30:00.000Z"
|
|
35
|
+
* 400:
|
|
36
|
+
* $ref: '#/components/responses/BadRequest'
|
|
37
|
+
* 500:
|
|
38
|
+
* $ref: '#/components/responses/InternalServerError'
|
|
39
|
+
*/
|
|
40
|
+
router.post("/generate-download-link", authMiddleware.hmacAuth, (0, middleware_1.validateData)(schemas_1.generateDownloadLinkSchema), (0, middleware_1.asyncHandler)(coreController.getDownloadLink));
|
|
41
|
+
/**
|
|
42
|
+
* @swagger
|
|
43
|
+
* /core/create-device-group:
|
|
44
|
+
* post:
|
|
45
|
+
* tags:
|
|
46
|
+
* - Core
|
|
47
|
+
* summary: Create a new device group
|
|
48
|
+
* description: Creates a new device group (mesh) in MeshCentral
|
|
49
|
+
* requestBody:
|
|
50
|
+
* required: true
|
|
51
|
+
* content:
|
|
52
|
+
* application/json:
|
|
53
|
+
* schema:
|
|
54
|
+
* type: object
|
|
55
|
+
* properties:
|
|
56
|
+
* deviceGroupName:
|
|
57
|
+
* type: string
|
|
58
|
+
* description: Name of the device group to create
|
|
59
|
+
* example: "production-servers"
|
|
60
|
+
* description:
|
|
61
|
+
* type: string
|
|
62
|
+
* description: Optional description for the device group
|
|
63
|
+
* example: "Production server mesh"
|
|
64
|
+
* required:
|
|
65
|
+
* - deviceGroupName
|
|
66
|
+
* responses:
|
|
67
|
+
* 200:
|
|
68
|
+
* description: Device group created successfully
|
|
69
|
+
* content:
|
|
70
|
+
* application/json:
|
|
71
|
+
* schema:
|
|
72
|
+
* type: object
|
|
73
|
+
* properties:
|
|
74
|
+
* result:
|
|
75
|
+
* type: string
|
|
76
|
+
* example: "ok"
|
|
77
|
+
* mesh_id:
|
|
78
|
+
* type: string
|
|
79
|
+
* example: "mesh//abc123def456"
|
|
80
|
+
* timestamp:
|
|
81
|
+
* type: string
|
|
82
|
+
* format: date-time
|
|
83
|
+
* example: "2023-12-01T10:30:00.000Z"
|
|
84
|
+
* 400:
|
|
85
|
+
* $ref: '#/components/responses/BadRequest'
|
|
86
|
+
* 500:
|
|
87
|
+
* $ref: '#/components/responses/InternalServerError'
|
|
88
|
+
*/
|
|
89
|
+
router.post("/create-device-group", authMiddleware.hmacAuth, (0, middleware_1.validateData)(schemas_1.createDeviceGroupSchema), (0, middleware_1.asyncHandler)(coreController.createDeviceGroup));
|
|
90
|
+
/**
|
|
91
|
+
* @swagger
|
|
92
|
+
* /core/add-user-to-group:
|
|
93
|
+
* post:
|
|
94
|
+
* tags:
|
|
95
|
+
* - Core
|
|
96
|
+
* summary: Add users to a device group
|
|
97
|
+
* description: Adds multiple users to a specified device group in MeshCentral
|
|
98
|
+
* requestBody:
|
|
99
|
+
* required: true
|
|
100
|
+
* content:
|
|
101
|
+
* application/json:
|
|
102
|
+
* schema:
|
|
103
|
+
* type: object
|
|
104
|
+
* properties:
|
|
105
|
+
* deviceGroupName:
|
|
106
|
+
* type: string
|
|
107
|
+
* description: Name of the device group (required if deviceGroupId not provided)
|
|
108
|
+
* example: "production-servers"
|
|
109
|
+
* deviceGroupId:
|
|
110
|
+
* type: string
|
|
111
|
+
* description: ID of the device group (required if deviceGroupName not provided)
|
|
112
|
+
* example: "mesh//abc123def456"
|
|
113
|
+
* users:
|
|
114
|
+
* type: array
|
|
115
|
+
* items:
|
|
116
|
+
* type: string
|
|
117
|
+
* description: Array of usernames to add to the device group
|
|
118
|
+
* example: ["john.doe", "jane.smith", "admin"]
|
|
119
|
+
* required:
|
|
120
|
+
* - users
|
|
121
|
+
* responses:
|
|
122
|
+
* 200:
|
|
123
|
+
* description: Users added to device group successfully
|
|
124
|
+
* content:
|
|
125
|
+
* application/json:
|
|
126
|
+
* schema:
|
|
127
|
+
* type: object
|
|
128
|
+
* properties:
|
|
129
|
+
* result:
|
|
130
|
+
* type: string
|
|
131
|
+
* enum: ["success", "partial"]
|
|
132
|
+
* example: "success"
|
|
133
|
+
* users_added:
|
|
134
|
+
* type: array
|
|
135
|
+
* items:
|
|
136
|
+
* type: string
|
|
137
|
+
* description: List of successfully added users
|
|
138
|
+
* example: ["john.doe", "jane.smith"]
|
|
139
|
+
* failed_users:
|
|
140
|
+
* type: array
|
|
141
|
+
* items:
|
|
142
|
+
* type: string
|
|
143
|
+
* description: List of users that failed to be added (optional)
|
|
144
|
+
* example: ["invalid.user"]
|
|
145
|
+
* timestamp:
|
|
146
|
+
* type: string
|
|
147
|
+
* format: date-time
|
|
148
|
+
* example: "2023-12-01T10:30:00.000Z"
|
|
149
|
+
* 400:
|
|
150
|
+
* $ref: '#/components/responses/BadRequest'
|
|
151
|
+
* 500:
|
|
152
|
+
* $ref: '#/components/responses/InternalServerError'
|
|
153
|
+
*/
|
|
154
|
+
router.post("/add-user-to-group", authMiddleware.hmacAuth, (0, middleware_1.validateData)(schemas_1.addUserToGroupSchema), (0, middleware_1.asyncHandler)(coreController.addUserToGroup));
|
|
155
|
+
router.post("/endpoint/get-install-script", authMiddleware.hmacAuth, (0, middleware_1.validateData)(schemas_1.getEndpointInstallScriptSchema), coreController.getEndpointInstallScript);
|
|
156
|
+
return router;
|
|
157
|
+
};
|
|
158
|
+
exports.createCoreRoutes = createCoreRoutes;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"healthRoutes.d.ts","sourceRoot":"","sources":["../../src/routes/healthRoutes.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,SAAS,CAAC;AACjC,OAAO,EAAE,gBAAgB,EAAE,MAAM,iCAAiC,CAAC;AAGnE,eAAO,MAAM,kBAAkB,GAC7B,kBAAkB,gBAAgB,KACjC,MA2DF,CAAC"}
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.createHealthRoutes = void 0;
|
|
4
|
+
const express_1 = require("express");
|
|
5
|
+
const middleware_1 = require("../middleware");
|
|
6
|
+
const createHealthRoutes = (healthController) => {
|
|
7
|
+
const router = (0, express_1.Router)();
|
|
8
|
+
/**
|
|
9
|
+
* @swagger
|
|
10
|
+
* /health:
|
|
11
|
+
* get:
|
|
12
|
+
* tags:
|
|
13
|
+
* - Health
|
|
14
|
+
* summary: Health check endpoint
|
|
15
|
+
* description: Basic health check endpoint for load balancers and monitoring systems
|
|
16
|
+
* responses:
|
|
17
|
+
* 200:
|
|
18
|
+
* description: Service is healthy
|
|
19
|
+
* content:
|
|
20
|
+
* application/json:
|
|
21
|
+
* schema:
|
|
22
|
+
* $ref: '#/components/schemas/HealthResponse'
|
|
23
|
+
* example:
|
|
24
|
+
* status: "healthy"
|
|
25
|
+
* timestamp: "2023-12-01T10:30:00.000Z"
|
|
26
|
+
* meshConnection: true
|
|
27
|
+
* dbConnection: true
|
|
28
|
+
* 500:
|
|
29
|
+
* $ref: '#/components/responses/InternalServerError'
|
|
30
|
+
*/
|
|
31
|
+
router.get("/health", (0, middleware_1.asyncHandler)(healthController.health));
|
|
32
|
+
/**
|
|
33
|
+
* @swagger
|
|
34
|
+
* /status:
|
|
35
|
+
* get:
|
|
36
|
+
* tags:
|
|
37
|
+
* - Health
|
|
38
|
+
* summary: Detailed service status
|
|
39
|
+
* description: Provides detailed status information about the service including version, uptime, and connection statuses
|
|
40
|
+
* responses:
|
|
41
|
+
* 200:
|
|
42
|
+
* description: Detailed service status information
|
|
43
|
+
* content:
|
|
44
|
+
* application/json:
|
|
45
|
+
* schema:
|
|
46
|
+
* $ref: '#/components/schemas/StatusResponse'
|
|
47
|
+
* example:
|
|
48
|
+
* service: "aux-server"
|
|
49
|
+
* version: "1.0.0"
|
|
50
|
+
* meshCentral:
|
|
51
|
+
* connected: true
|
|
52
|
+
* server: "meshcentral.example.com"
|
|
53
|
+
* database:
|
|
54
|
+
* connected: true
|
|
55
|
+
* host: "localhost"
|
|
56
|
+
* uptime: 3600
|
|
57
|
+
* 500:
|
|
58
|
+
* $ref: '#/components/responses/InternalServerError'
|
|
59
|
+
*/
|
|
60
|
+
router.get("/status", (0, middleware_1.asyncHandler)(healthController.status));
|
|
61
|
+
return router;
|
|
62
|
+
};
|
|
63
|
+
exports.createHealthRoutes = createHealthRoutes;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/routes/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,SAAS,CAAC;AAetC,eAAO,MAAM,WAAW,GAAI,KAAK,WAAW,KAAG,IAuB9C,CAAC"}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.setupRoutes = void 0;
|
|
4
|
+
const healthRoutes_1 = require("./healthRoutes");
|
|
5
|
+
const coreRoutes_1 = require("./coreRoutes");
|
|
6
|
+
const apiRoutes_1 = require("./apiRoutes");
|
|
7
|
+
const swaggerRoutes_1 = require("./swaggerRoutes");
|
|
8
|
+
const healthController_1 = require("../controllers/healthController");
|
|
9
|
+
const apiController_1 = require("../controllers/apiController");
|
|
10
|
+
const coreController_1 = require("../controllers/coreController");
|
|
11
|
+
const authMiddleware_1 = require("../middleware/authMiddleware");
|
|
12
|
+
const middleware_1 = require("../middleware");
|
|
13
|
+
const setupRoutes = (app) => {
|
|
14
|
+
const healthController = new healthController_1.HealthController();
|
|
15
|
+
const apiController = new apiController_1.ApiController();
|
|
16
|
+
const coreController = new coreController_1.CoreController();
|
|
17
|
+
const authMiddleware = new authMiddleware_1.AuthMiddleware();
|
|
18
|
+
const healthRoutes = (0, healthRoutes_1.createHealthRoutes)(healthController);
|
|
19
|
+
const coreRoute = (0, coreRoutes_1.createCoreRoutes)(coreController, authMiddleware);
|
|
20
|
+
const apiRoutes = (0, apiRoutes_1.createApiRoutes)(apiController, authMiddleware);
|
|
21
|
+
const swaggerRoutes = (0, swaggerRoutes_1.createSwaggerRoutes)();
|
|
22
|
+
app.use("/", healthRoutes);
|
|
23
|
+
app.use("/api", apiRoutes);
|
|
24
|
+
app.use("/core", coreRoute);
|
|
25
|
+
app.use("/docs", swaggerRoutes);
|
|
26
|
+
app.use("*", middleware_1.notFoundHandler);
|
|
27
|
+
app.use(middleware_1.errorHandler);
|
|
28
|
+
app.healthController = healthController;
|
|
29
|
+
app.apiController = apiController;
|
|
30
|
+
};
|
|
31
|
+
exports.setupRoutes = setupRoutes;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"swaggerRoutes.d.ts","sourceRoot":"","sources":["../../src/routes/swaggerRoutes.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,SAAS,CAAC;AAIjC,eAAO,MAAM,mBAAmB,QAAO,MA8BtC,CAAC"}
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.createSwaggerRoutes = void 0;
|
|
7
|
+
const express_1 = require("express");
|
|
8
|
+
const swagger_ui_express_1 = __importDefault(require("swagger-ui-express"));
|
|
9
|
+
const swagger_1 = require("../config/swagger");
|
|
10
|
+
const createSwaggerRoutes = () => {
|
|
11
|
+
const router = (0, express_1.Router)();
|
|
12
|
+
router.use("/", swagger_ui_express_1.default.serve);
|
|
13
|
+
router.get("/", swagger_ui_express_1.default.setup(swagger_1.swaggerSpec, {
|
|
14
|
+
customSiteTitle: "Aux Server API Documentation",
|
|
15
|
+
customCss: `
|
|
16
|
+
.swagger-ui .topbar { display: none }
|
|
17
|
+
.swagger-ui .info .title { color: #3b82f6; }
|
|
18
|
+
`,
|
|
19
|
+
customCssUrl: undefined,
|
|
20
|
+
swaggerOptions: {
|
|
21
|
+
persistAuthorization: true,
|
|
22
|
+
displayRequestDuration: true,
|
|
23
|
+
docExpansion: "none",
|
|
24
|
+
filter: true,
|
|
25
|
+
showRequestHeaders: true,
|
|
26
|
+
tryItOutEnabled: true,
|
|
27
|
+
},
|
|
28
|
+
}));
|
|
29
|
+
router.get("/json", (req, res) => {
|
|
30
|
+
res.setHeader("Content-Type", "application/json");
|
|
31
|
+
res.send(swagger_1.swaggerSpec);
|
|
32
|
+
});
|
|
33
|
+
return router;
|
|
34
|
+
};
|
|
35
|
+
exports.createSwaggerRoutes = createSwaggerRoutes;
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { Config } from "../types";
|
|
2
|
+
import { IDatabaseService } from "./DatabaseService";
|
|
3
|
+
import { IWebSocketService } from "./WebSocketService";
|
|
4
|
+
import { IHttpServerService } from "./HttpServerService";
|
|
5
|
+
export interface IApplicationService {
|
|
6
|
+
getDatabaseService(): IDatabaseService;
|
|
7
|
+
getWebSocketService(): IWebSocketService;
|
|
8
|
+
getHttpServerService(): IHttpServerService;
|
|
9
|
+
start(port?: number): Promise<void>;
|
|
10
|
+
stop(): Promise<void>;
|
|
11
|
+
isHealthy(): Promise<boolean>;
|
|
12
|
+
}
|
|
13
|
+
export declare class ApplicationService implements IApplicationService {
|
|
14
|
+
private databaseService;
|
|
15
|
+
private webSocketService;
|
|
16
|
+
private httpServerService;
|
|
17
|
+
private config;
|
|
18
|
+
constructor(config: Config);
|
|
19
|
+
start(port?: number): Promise<void>;
|
|
20
|
+
stop(): Promise<void>;
|
|
21
|
+
isHealthy(): Promise<boolean>;
|
|
22
|
+
getDatabaseService(): IDatabaseService;
|
|
23
|
+
getWebSocketService(): IWebSocketService;
|
|
24
|
+
getHttpServerService(): IHttpServerService;
|
|
25
|
+
}
|
|
26
|
+
//# sourceMappingURL=ApplicationService.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ApplicationService.d.ts","sourceRoot":"","sources":["../../src/services/ApplicationService.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,UAAU,CAAC;AAClC,OAAO,EAAE,gBAAgB,EAAmB,MAAM,mBAAmB,CAAC;AACtE,OAAO,EAAE,iBAAiB,EAAoB,MAAM,oBAAoB,CAAC;AACzE,OAAO,EAAE,kBAAkB,EAAqB,MAAM,qBAAqB,CAAC;AAE5E,MAAM,WAAW,mBAAmB;IAClC,kBAAkB,IAAI,gBAAgB,CAAC;IACvC,mBAAmB,IAAI,iBAAiB,CAAC;IACzC,oBAAoB,IAAI,kBAAkB,CAAC;IAC3C,KAAK,CAAC,IAAI,CAAC,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;IACpC,IAAI,IAAI,OAAO,CAAC,IAAI,CAAC,CAAC;IACtB,SAAS,IAAI,OAAO,CAAC,OAAO,CAAC,CAAC;CAC/B;AAED,qBAAa,kBAAmB,YAAW,mBAAmB;IAC5D,OAAO,CAAC,eAAe,CAAmB;IAC1C,OAAO,CAAC,gBAAgB,CAAoB;IAC5C,OAAO,CAAC,iBAAiB,CAAqB;IAC9C,OAAO,CAAC,MAAM,CAAS;gBAEX,MAAM,EAAE,MAAM;IAOb,KAAK,CAAC,IAAI,GAAE,MAAa,GAAG,OAAO,CAAC,IAAI,CAAC;IAWzC,IAAI,IAAI,OAAO,CAAC,IAAI,CAAC;IASrB,SAAS,IAAI,OAAO,CAAC,OAAO,CAAC;IAMnC,kBAAkB,IAAI,gBAAgB;IAItC,mBAAmB,IAAI,iBAAiB;IAIxC,oBAAoB,IAAI,kBAAkB;CAGlD"}
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.ApplicationService = void 0;
|
|
4
|
+
const DatabaseService_1 = require("./DatabaseService");
|
|
5
|
+
const WebSocketService_1 = require("./WebSocketService");
|
|
6
|
+
const HttpServerService_1 = require("./HttpServerService");
|
|
7
|
+
class ApplicationService {
|
|
8
|
+
constructor(config) {
|
|
9
|
+
this.config = config;
|
|
10
|
+
this.databaseService = new DatabaseService_1.DatabaseService(this.config.dbConfig);
|
|
11
|
+
this.webSocketService = new WebSocketService_1.WebSocketService(this.config);
|
|
12
|
+
this.httpServerService = new HttpServerService_1.HttpServerService(this.config);
|
|
13
|
+
}
|
|
14
|
+
async start(port = 3003) {
|
|
15
|
+
try {
|
|
16
|
+
await this.httpServerService.start(port);
|
|
17
|
+
this.webSocketService.connect().catch(() => { });
|
|
18
|
+
}
|
|
19
|
+
catch (error) {
|
|
20
|
+
console.error("Failed to start server:", error);
|
|
21
|
+
await this.stop();
|
|
22
|
+
throw error;
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
async stop() {
|
|
26
|
+
const shutdownPromises = [
|
|
27
|
+
this.httpServerService.stop().catch(() => { }),
|
|
28
|
+
this.webSocketService.disconnect().catch(() => { }),
|
|
29
|
+
this.databaseService.disconnect().catch(() => { }),
|
|
30
|
+
];
|
|
31
|
+
await Promise.all(shutdownPromises);
|
|
32
|
+
}
|
|
33
|
+
async isHealthy() {
|
|
34
|
+
return (this.httpServerService.isRunning() && this.databaseService.isConnected());
|
|
35
|
+
}
|
|
36
|
+
getDatabaseService() {
|
|
37
|
+
return this.databaseService;
|
|
38
|
+
}
|
|
39
|
+
getWebSocketService() {
|
|
40
|
+
return this.webSocketService;
|
|
41
|
+
}
|
|
42
|
+
getHttpServerService() {
|
|
43
|
+
return this.httpServerService;
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
exports.ApplicationService = ApplicationService;
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { Pool } from "pg";
|
|
2
|
+
import { Config } from "../types";
|
|
3
|
+
export interface IDatabaseService {
|
|
4
|
+
getPool(): Pool;
|
|
5
|
+
isConnected(): boolean;
|
|
6
|
+
disconnect(): Promise<void>;
|
|
7
|
+
}
|
|
8
|
+
export declare class DatabaseService implements IDatabaseService {
|
|
9
|
+
private pool;
|
|
10
|
+
private config;
|
|
11
|
+
constructor(config: Config["dbConfig"]);
|
|
12
|
+
private createPool;
|
|
13
|
+
disconnect(): Promise<void>;
|
|
14
|
+
getPool(): Pool;
|
|
15
|
+
isConnected(): boolean;
|
|
16
|
+
}
|
|
17
|
+
//# sourceMappingURL=DatabaseService.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"DatabaseService.d.ts","sourceRoot":"","sources":["../../src/services/DatabaseService.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,IAAI,EAAE,MAAM,IAAI,CAAC;AAC1B,OAAO,EAAE,MAAM,EAAE,MAAM,UAAU,CAAC;AAElC,MAAM,WAAW,gBAAgB;IAC/B,OAAO,IAAI,IAAI,CAAC;IAChB,WAAW,IAAI,OAAO,CAAC;IACvB,UAAU,IAAI,OAAO,CAAC,IAAI,CAAC,CAAC;CAC7B;AAED,qBAAa,eAAgB,YAAW,gBAAgB;IACtD,OAAO,CAAC,IAAI,CAAO;IACnB,OAAO,CAAC,MAAM,CAAqB;gBAEvB,MAAM,EAAE,MAAM,CAAC,UAAU,CAAC;IAKtC,OAAO,CAAC,UAAU;IAaL,UAAU,IAAI,OAAO,CAAC,IAAI,CAAC;IASjC,OAAO,IAAI,IAAI;IAIf,WAAW,IAAI,OAAO;CAG9B"}
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.DatabaseService = void 0;
|
|
4
|
+
const pg_1 = require("pg");
|
|
5
|
+
class DatabaseService {
|
|
6
|
+
constructor(config) {
|
|
7
|
+
this.config = config;
|
|
8
|
+
this.pool = this.createPool();
|
|
9
|
+
}
|
|
10
|
+
createPool() {
|
|
11
|
+
return new pg_1.Pool({
|
|
12
|
+
host: this.config.host,
|
|
13
|
+
port: this.config.port,
|
|
14
|
+
user: this.config.user,
|
|
15
|
+
password: this.config.password,
|
|
16
|
+
database: this.config.database,
|
|
17
|
+
max: 20,
|
|
18
|
+
idleTimeoutMillis: 30000,
|
|
19
|
+
connectionTimeoutMillis: 2000,
|
|
20
|
+
});
|
|
21
|
+
}
|
|
22
|
+
async disconnect() {
|
|
23
|
+
try {
|
|
24
|
+
await this.pool.end();
|
|
25
|
+
}
|
|
26
|
+
catch (error) {
|
|
27
|
+
console.error("Error closing database connection:", error);
|
|
28
|
+
throw error;
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
getPool() {
|
|
32
|
+
return this.pool;
|
|
33
|
+
}
|
|
34
|
+
isConnected() {
|
|
35
|
+
return !this.pool.ended;
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
exports.DatabaseService = DatabaseService;
|