axiodb 2.10.22-stable → 2.10.22
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/lib/Docker/Controller/Authentication/Authentication.d.ts +37 -0
- package/lib/Docker/Controller/Authentication/Authentication.js +179 -0
- package/lib/Docker/Controller/Authentication/Authentication.js.map +1 -0
- package/lib/Docker/Helper/bcrypt.helper.d.ts +4 -0
- package/lib/Docker/Helper/bcrypt.helper.js +30 -0
- package/lib/Docker/Helper/bcrypt.helper.js.map +1 -0
- package/lib/Docker/Middlewares/validateToken.middleware.d.ts +3 -0
- package/lib/Docker/Middlewares/validateToken.middleware.js +45 -0
- package/lib/Docker/Middlewares/validateToken.middleware.js.map +1 -0
- package/lib/Docker/Server/Fastify/Fastify.d.ts +10 -0
- package/lib/Docker/Server/Fastify/Fastify.js +72 -0
- package/lib/Docker/Server/Fastify/Fastify.js.map +1 -0
- package/lib/Docker/Server/Fastify/Router/Authentication/Authentication.d.ts +5 -0
- package/lib/Docker/Server/Fastify/Router/Authentication/Authentication.js +34 -0
- package/lib/Docker/Server/Fastify/Router/Authentication/Authentication.js.map +1 -0
- package/lib/Docker/Server/Fastify/Router/Router.d.ts +2 -0
- package/lib/Docker/Server/Fastify/Router/Router.js +37 -0
- package/lib/Docker/Server/Fastify/Router/Router.js.map +1 -0
- package/lib/Docker/Server/GRPC/GRPC.d.ts +10 -0
- package/lib/Docker/Server/GRPC/GRPC.js +111 -0
- package/lib/Docker/Server/GRPC/GRPC.js.map +1 -0
- package/lib/Docker/Server/TCP.d.ts +10 -0
- package/lib/Docker/Server/TCP.js +38 -0
- package/lib/Docker/Server/TCP.js.map +1 -0
- package/lib/Docker/Server/UDP.d.ts +10 -0
- package/lib/Docker/Server/UDP.js +28 -0
- package/lib/Docker/Server/UDP.js.map +1 -0
- package/lib/Docker/Server/Websocket.d.ts +0 -0
- package/lib/Docker/Server/Websocket.js +2 -0
- package/lib/Docker/Server/Websocket.js.map +1 -0
- package/lib/Docker/config/Info.d.ts +30 -0
- package/lib/Docker/config/Info.js +52 -0
- package/lib/Docker/config/Info.js.map +1 -0
- package/lib/Docker/config/Interfaces/RequestInterface.d.ts +8 -0
- package/lib/Docker/config/Interfaces/RequestInterface.js +3 -0
- package/lib/Docker/config/Interfaces/RequestInterface.js.map +1 -0
- package/lib/Docker/config/Keys.d.ts +21 -0
- package/lib/Docker/config/Keys.js +30 -0
- package/lib/Docker/config/Keys.js.map +1 -0
- package/lib/Docker/config/docker.d.ts +1 -0
- package/lib/Docker/config/docker.js +60 -0
- package/lib/Docker/config/docker.js.map +1 -0
- package/lib/Docker/util/SchemaGenerator.util.d.ts +26 -0
- package/lib/Docker/util/SchemaGenerator.util.js +71 -0
- package/lib/Docker/util/SchemaGenerator.util.js.map +1 -0
- package/package.json +1 -1
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import Collection from "axiodb/lib/Operation/Collection/collection.operation";
|
|
2
|
+
interface RegisterRequest {
|
|
3
|
+
username: string;
|
|
4
|
+
password: string;
|
|
5
|
+
email: string;
|
|
6
|
+
name: string;
|
|
7
|
+
}
|
|
8
|
+
interface LoginRequest {
|
|
9
|
+
username: string;
|
|
10
|
+
password: string;
|
|
11
|
+
}
|
|
12
|
+
export default class Authentication {
|
|
13
|
+
static Register(userData: RegisterRequest, CollectionInstance: Collection): Promise<{
|
|
14
|
+
status: boolean;
|
|
15
|
+
title: string;
|
|
16
|
+
message: string;
|
|
17
|
+
statusCode?: undefined;
|
|
18
|
+
data?: undefined;
|
|
19
|
+
} | {
|
|
20
|
+
status: boolean;
|
|
21
|
+
statusCode: import("outers/lib/StatusCode/Code").StatusCode;
|
|
22
|
+
title: string;
|
|
23
|
+
message: string;
|
|
24
|
+
data: {
|
|
25
|
+
username: string;
|
|
26
|
+
password: string;
|
|
27
|
+
};
|
|
28
|
+
} | {
|
|
29
|
+
status: boolean;
|
|
30
|
+
title: string;
|
|
31
|
+
message: string;
|
|
32
|
+
data: unknown;
|
|
33
|
+
statusCode?: undefined;
|
|
34
|
+
}>;
|
|
35
|
+
static Login(userData: LoginRequest, CollectionInstance: Collection): Promise<any>;
|
|
36
|
+
}
|
|
37
|
+
export {};
|
|
@@ -0,0 +1,179 @@
|
|
|
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
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
12
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
13
|
+
};
|
|
14
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
|
+
const outers_1 = require("outers");
|
|
16
|
+
const bcrypt_helper_1 = __importDefault(require("../../Helper/bcrypt.helper"));
|
|
17
|
+
const outers_2 = require("outers");
|
|
18
|
+
const Keys_1 = require("../../config/Keys");
|
|
19
|
+
// Authentication Class to handle all the authentication related operations
|
|
20
|
+
class Authentication {
|
|
21
|
+
// Method to handle user registration management
|
|
22
|
+
static Register(userData, CollectionInstance) {
|
|
23
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
24
|
+
var _a;
|
|
25
|
+
try {
|
|
26
|
+
// check if all fields are filled
|
|
27
|
+
for (const key in userData) {
|
|
28
|
+
if (!userData[key]) {
|
|
29
|
+
throw new Error(`${key} is required`);
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
const { email, username } = userData; // Destructure the userData object
|
|
33
|
+
// check if username already exists
|
|
34
|
+
const existingUser = yield CollectionInstance.query({
|
|
35
|
+
email: email,
|
|
36
|
+
username: username,
|
|
37
|
+
}).exec();
|
|
38
|
+
if (existingUser.statusCode === outers_1.StatusCodes.OK &&
|
|
39
|
+
existingUser.status == true &&
|
|
40
|
+
((_a = existingUser.data.documents) === null || _a === void 0 ? void 0 : _a.length) > 0) {
|
|
41
|
+
return {
|
|
42
|
+
status: false,
|
|
43
|
+
title: "User Already Exists",
|
|
44
|
+
message: "User with this email or username already exists",
|
|
45
|
+
};
|
|
46
|
+
}
|
|
47
|
+
// Hash Password
|
|
48
|
+
const hashedPassword = yield bcrypt_helper_1.default.hashPassword(userData.password);
|
|
49
|
+
// Create User Object
|
|
50
|
+
const user = Object.assign(Object.assign({}, userData), { password: hashedPassword });
|
|
51
|
+
// Create User in Database
|
|
52
|
+
const createdUser = yield CollectionInstance.insert(user);
|
|
53
|
+
if ((createdUser === null || createdUser === void 0 ? void 0 : createdUser.statusCode) !== outers_1.StatusCodes.OK) {
|
|
54
|
+
return {
|
|
55
|
+
status: false,
|
|
56
|
+
title: "Error in Creating User",
|
|
57
|
+
message: "User could not be created in the database",
|
|
58
|
+
};
|
|
59
|
+
}
|
|
60
|
+
return {
|
|
61
|
+
status: true,
|
|
62
|
+
statusCode: outers_1.StatusCodes.OK,
|
|
63
|
+
title: "User Created Successfully",
|
|
64
|
+
message: "User has been created successfully, please login with your credentials",
|
|
65
|
+
data: {
|
|
66
|
+
username: userData.username,
|
|
67
|
+
password: userData.password,
|
|
68
|
+
},
|
|
69
|
+
};
|
|
70
|
+
}
|
|
71
|
+
catch (error) {
|
|
72
|
+
console.error("Error in Registering User", error);
|
|
73
|
+
return {
|
|
74
|
+
status: false,
|
|
75
|
+
title: "Error in Registering User",
|
|
76
|
+
message: "Error in Registering User when creating user",
|
|
77
|
+
data: error,
|
|
78
|
+
};
|
|
79
|
+
}
|
|
80
|
+
});
|
|
81
|
+
}
|
|
82
|
+
// Method to handle user login management
|
|
83
|
+
static Login(userData, CollectionInstance) {
|
|
84
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
85
|
+
var _a, _b, _c;
|
|
86
|
+
try {
|
|
87
|
+
// check if all fields are filled
|
|
88
|
+
for (const key in userData) {
|
|
89
|
+
if (!userData[key]) {
|
|
90
|
+
throw new Error(`${key} is required`);
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
// check if username and password are provided
|
|
94
|
+
if (!userData.username || !userData.password) {
|
|
95
|
+
return {
|
|
96
|
+
status: false,
|
|
97
|
+
title: "Username and Password Required",
|
|
98
|
+
message: "Username and Password are required",
|
|
99
|
+
};
|
|
100
|
+
}
|
|
101
|
+
const { username, password } = userData; // Destructure the userData object
|
|
102
|
+
// check if username already exists
|
|
103
|
+
const existingUser = yield CollectionInstance.query({
|
|
104
|
+
username: username,
|
|
105
|
+
}).exec();
|
|
106
|
+
if (existingUser.statusCode === outers_1.StatusCodes.OK &&
|
|
107
|
+
existingUser.status == true &&
|
|
108
|
+
((_a = existingUser.data.documents) === null || _a === void 0 ? void 0 : _a.length) === 0) {
|
|
109
|
+
return {
|
|
110
|
+
status: false,
|
|
111
|
+
title: "User Not Found",
|
|
112
|
+
message: "User with this username does not exist",
|
|
113
|
+
};
|
|
114
|
+
}
|
|
115
|
+
// check if password is correct
|
|
116
|
+
const isPasswordCorrect = yield bcrypt_helper_1.default.comparePasswords(password, (_b = existingUser.data.documents[0]) === null || _b === void 0 ? void 0 : _b.password);
|
|
117
|
+
if (!isPasswordCorrect) {
|
|
118
|
+
return {
|
|
119
|
+
status: false,
|
|
120
|
+
title: "Incorrect Password",
|
|
121
|
+
message: "Password is incorrect",
|
|
122
|
+
};
|
|
123
|
+
}
|
|
124
|
+
// if AccessToken is already present, return it
|
|
125
|
+
if ((_c = existingUser.data.documents[0]) === null || _c === void 0 ? void 0 : _c.AccessToken) {
|
|
126
|
+
delete existingUser.data.documents[0].password;
|
|
127
|
+
delete existingUser.data.documents[0].AccessToken;
|
|
128
|
+
}
|
|
129
|
+
// generate access token
|
|
130
|
+
const newAccessToken = new outers_2.ClassBased.JWT_Manager(Keys_1.CentralInformation.CentralDB_JWT_Secret).generateLoginToken(existingUser.data.documents[0], 1, "24h");
|
|
131
|
+
if (newAccessToken.status === false) {
|
|
132
|
+
return {
|
|
133
|
+
status: false,
|
|
134
|
+
title: "Token Generation Failed",
|
|
135
|
+
message: "Failed to generate access token",
|
|
136
|
+
};
|
|
137
|
+
}
|
|
138
|
+
// Update in DB
|
|
139
|
+
const updateResponse = yield CollectionInstance.update({
|
|
140
|
+
username: username,
|
|
141
|
+
}).UpdateOne({ AccessToken: newAccessToken.toKen });
|
|
142
|
+
if (updateResponse.status == true &&
|
|
143
|
+
updateResponse.statusCode == outers_1.StatusCodes.OK) {
|
|
144
|
+
// Return success message
|
|
145
|
+
return {
|
|
146
|
+
status: true,
|
|
147
|
+
statusCode: outers_1.StatusCodes.OK,
|
|
148
|
+
title: "User Logged In Successfully",
|
|
149
|
+
message: "User has been logged in successfully",
|
|
150
|
+
data: {
|
|
151
|
+
username: existingUser.data.documents[0].username,
|
|
152
|
+
AccessToken: newAccessToken.toKen,
|
|
153
|
+
willExpireIn: "24h",
|
|
154
|
+
currentTimeStamp: newAccessToken.currentTimeStamp,
|
|
155
|
+
},
|
|
156
|
+
};
|
|
157
|
+
}
|
|
158
|
+
else {
|
|
159
|
+
return {
|
|
160
|
+
status: false,
|
|
161
|
+
title: "Error in Updating Access Token",
|
|
162
|
+
message: "Error in Updating Access Token in the database",
|
|
163
|
+
};
|
|
164
|
+
}
|
|
165
|
+
}
|
|
166
|
+
catch (error) {
|
|
167
|
+
console.error("Error in Login User", error);
|
|
168
|
+
return {
|
|
169
|
+
status: false,
|
|
170
|
+
title: "Error in Login User",
|
|
171
|
+
message: "Error in Login User when creating user",
|
|
172
|
+
data: error,
|
|
173
|
+
};
|
|
174
|
+
}
|
|
175
|
+
});
|
|
176
|
+
}
|
|
177
|
+
}
|
|
178
|
+
exports.default = Authentication;
|
|
179
|
+
//# sourceMappingURL=Authentication.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Authentication.js","sourceRoot":"","sources":["../../../../source/Docker/Controller/Authentication/Authentication.ts"],"names":[],"mappings":";;;;;;;;;;;;;;AACA,mCAAqC;AACrC,+EAAgD;AAChD,mCAAoC;AACpC,4CAAuD;AAcvD,2EAA2E;AAC3E,MAAqB,cAAc;IACjC,gDAAgD;IACzC,MAAM,CAAO,QAAQ,CAC1B,QAAyB,EACzB,kBAA8B;;;YAE9B,IAAI,CAAC;gBACH,iCAAiC;gBACjC,KAAK,MAAM,GAAG,IAAI,QAAQ,EAAE,CAAC;oBAC3B,IAAI,CAAC,QAAQ,CAAC,GAA4B,CAAC,EAAE,CAAC;wBAC5C,MAAM,IAAI,KAAK,CAAC,GAAG,GAAG,cAAc,CAAC,CAAC;oBACxC,CAAC;gBACH,CAAC;gBACD,MAAM,EAAE,KAAK,EAAE,QAAQ,EAAE,GAAG,QAAQ,CAAC,CAAC,kCAAkC;gBACxE,mCAAmC;gBACnC,MAAM,YAAY,GAAG,MAAM,kBAAkB,CAAC,KAAK,CAAC;oBAClD,KAAK,EAAE,KAAK;oBACZ,QAAQ,EAAE,QAAQ;iBACnB,CAAC,CAAC,IAAI,EAAE,CAAC;gBACV,IACE,YAAY,CAAC,UAAU,KAAK,oBAAW,CAAC,EAAE;oBAC1C,YAAY,CAAC,MAAM,IAAI,IAAI;oBAC3B,CAAA,MAAA,YAAY,CAAC,IAAI,CAAC,SAAS,0CAAE,MAAM,IAAG,CAAC,EACvC,CAAC;oBACD,OAAO;wBACL,MAAM,EAAE,KAAK;wBACb,KAAK,EAAE,qBAAqB;wBAC5B,OAAO,EAAE,iDAAiD;qBAC3D,CAAC;gBACJ,CAAC;gBAED,gBAAgB;gBAChB,MAAM,cAAc,GAAG,MAAM,uBAAM,CAAC,YAAY,CAAC,QAAQ,CAAC,QAAQ,CAAC,CAAC;gBAEpE,qBAAqB;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,gDAAgD;qBAC1D,CAAC;gBACJ,CAAC;YACH,CAAC;YAAC,OAAO,KAAK,EAAE,CAAC;gBACf,OAAO,CAAC,KAAK,CAAC,qBAAqB,EAAE,KAAK,CAAC,CAAC;gBAC5C,OAAO;oBACL,MAAM,EAAE,KAAK;oBACb,KAAK,EAAE,qBAAqB;oBAC5B,OAAO,EAAE,wCAAwC;oBACjD,IAAI,EAAE,KAAK;iBACZ,CAAC;YACJ,CAAC;QACH,CAAC;KAAA;CACF;AAzLD,iCAyLC"}
|
|
@@ -0,0 +1,30 @@
|
|
|
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
|
+
const bcryptjs_1 = require("bcryptjs");
|
|
13
|
+
class bcrypt {
|
|
14
|
+
// Method to hash password
|
|
15
|
+
static hashPassword(password) {
|
|
16
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
17
|
+
const saltRounds = yield (0, bcryptjs_1.genSalt)(10);
|
|
18
|
+
const hashedPassword = yield (0, bcryptjs_1.hash)(password, saltRounds);
|
|
19
|
+
return hashedPassword;
|
|
20
|
+
});
|
|
21
|
+
}
|
|
22
|
+
// Method to compare password
|
|
23
|
+
static comparePasswords(password, hashedPassword) {
|
|
24
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
25
|
+
return yield (0, bcryptjs_1.compare)(password, hashedPassword);
|
|
26
|
+
});
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
exports.default = bcrypt;
|
|
30
|
+
//# sourceMappingURL=bcrypt.helper.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"bcrypt.helper.js","sourceRoot":"","sources":["../../../source/Docker/Helper/bcrypt.helper.ts"],"names":[],"mappings":";;;;;;;;;;;AAAA,uCAAkD;AAElD,MAAqB,MAAM;IACzB,0BAA0B;IACnB,MAAM,CAAO,YAAY,CAAC,QAAgB;;YAC/C,MAAM,UAAU,GAAG,MAAM,IAAA,kBAAO,EAAC,EAAE,CAAC,CAAC;YACrC,MAAM,cAAc,GAAG,MAAM,IAAA,eAAI,EAAC,QAAQ,EAAE,UAAU,CAAC,CAAC;YACxD,OAAO,cAAc,CAAC;QACxB,CAAC;KAAA;IAED,8BAA8B;IACvB,MAAM,CAAO,gBAAgB,CAClC,QAAgB,EAChB,cAAsB;;YAEtB,OAAO,MAAM,IAAA,kBAAO,EAAC,QAAQ,EAAE,cAAc,CAAC,CAAC;QACjD,CAAC;KAAA;CACF;AAfD,yBAeC"}
|
|
@@ -0,0 +1,45 @@
|
|
|
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.default = validateToken;
|
|
13
|
+
const outers_1 = require("outers");
|
|
14
|
+
const outers_2 = require("outers");
|
|
15
|
+
const Keys_1 = require("../config/Keys");
|
|
16
|
+
function validateToken(request, reply) {
|
|
17
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
18
|
+
// Get Token from the request headers
|
|
19
|
+
const authToken = request.headers["servicetoken"];
|
|
20
|
+
// Check if the token is valid
|
|
21
|
+
if (!authToken) {
|
|
22
|
+
return reply.status(outers_1.StatusCodes.UNAUTHORIZED).send({
|
|
23
|
+
statusCode: outers_1.StatusCodes.UNAUTHORIZED,
|
|
24
|
+
success: false,
|
|
25
|
+
error: "Unauthorized",
|
|
26
|
+
message: "No service token provided, please provide servicetoken in the header",
|
|
27
|
+
});
|
|
28
|
+
}
|
|
29
|
+
// Decode the token
|
|
30
|
+
const decodedToken = new outers_2.ClassBased.JWT_Manager(Keys_1.CentralInformation.CentralDB_JWT_Secret).decode(authToken);
|
|
31
|
+
// Check if the token is valid or expired
|
|
32
|
+
if (decodedToken.status === "Invalid") {
|
|
33
|
+
return reply.status(outers_1.StatusCodes.UNAUTHORIZED).send({
|
|
34
|
+
statusCode: outers_1.StatusCodes.UNAUTHORIZED,
|
|
35
|
+
success: false,
|
|
36
|
+
error: "Unauthorized",
|
|
37
|
+
message: "Invalid or expired token",
|
|
38
|
+
});
|
|
39
|
+
}
|
|
40
|
+
console.log("Decoded Token", decodedToken.data.data);
|
|
41
|
+
// Set the user data in the request body
|
|
42
|
+
request.body = Object.assign(Object.assign({}, request.body), { user: decodedToken.data.data });
|
|
43
|
+
});
|
|
44
|
+
}
|
|
45
|
+
//# sourceMappingURL=validateToken.middleware.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"validateToken.middleware.js","sourceRoot":"","sources":["../../../source/Docker/Middlewares/validateToken.middleware.ts"],"names":[],"mappings":";;;;;;;;;;;AAMA,gCAsCC;AA3CD,mCAAqC;AAErC,mCAAoC;AACpC,yCAAoD;AAEpD,SAA8B,aAAa,CACzC,OAAoB,EACpB,KAAmB;;QAEnB,qCAAqC;QACrC,MAAM,SAAS,GAAW,OAAO,CAAC,OAAO,CAAC,cAAc,CAAW,CAAC;QAEpE,8BAA8B;QAC9B,IAAI,CAAC,SAAS,EAAE,CAAC;YACf,OAAO,KAAK,CAAC,MAAM,CAAC,oBAAW,CAAC,YAAY,CAAC,CAAC,IAAI,CAAC;gBACjD,UAAU,EAAE,oBAAW,CAAC,YAAY;gBACpC,OAAO,EAAE,KAAK;gBACd,KAAK,EAAE,cAAc;gBACrB,OAAO,EACL,sEAAsE;aACzE,CAAC,CAAC;QACL,CAAC;QACD,mBAAmB;QACnB,MAAM,YAAY,GAAG,IAAI,mBAAU,CAAC,WAAW,CAC7C,yBAAkB,CAAC,oBAAoB,CACxC,CAAC,MAAM,CAAC,SAAS,CAAC,CAAC;QAEpB,yCAAyC;QACzC,IAAI,YAAY,CAAC,MAAM,KAAK,SAAS,EAAE,CAAC;YACtC,OAAO,KAAK,CAAC,MAAM,CAAC,oBAAW,CAAC,YAAY,CAAC,CAAC,IAAI,CAAC;gBACjD,UAAU,EAAE,oBAAW,CAAC,YAAY;gBACpC,OAAO,EAAE,KAAK;gBACd,KAAK,EAAE,cAAc;gBACrB,OAAO,EAAE,0BAA0B;aACpC,CAAC,CAAC;QACL,CAAC;QACD,OAAO,CAAC,GAAG,CAAC,eAAe,EAAE,YAAY,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;QAErD,wCAAwC;QACxC,OAAO,CAAC,IAAI,mCACP,OAAO,CAAC,IAAI,KACf,IAAI,EAAE,YAAY,CAAC,IAAI,CAAC,IAAI,GAC7B,CAAC;IACJ,CAAC;CAAA"}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { AxioDB } from "axiodb";
|
|
2
|
+
import Collection from "axiodb/lib/Operation/Collection/collection.operation";
|
|
3
|
+
import Database from "axiodb/lib/Operation/Database/database.operation";
|
|
4
|
+
interface ServerOptions {
|
|
5
|
+
CentralAuthCollection: Collection;
|
|
6
|
+
CentralDB: Database;
|
|
7
|
+
CentralDBInstance: AxioDB;
|
|
8
|
+
}
|
|
9
|
+
declare const start: (options: ServerOptions) => Promise<void>;
|
|
10
|
+
export default start;
|
|
@@ -0,0 +1,72 @@
|
|
|
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
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
12
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
13
|
+
};
|
|
14
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
|
+
const fastify_1 = __importDefault(require("fastify"));
|
|
16
|
+
const Info_1 = __importDefault(require("../../config/Info"));
|
|
17
|
+
const Keys_1 = require("../../config/Keys");
|
|
18
|
+
// Import all Routes
|
|
19
|
+
const Router_1 = __importDefault(require("./Router/Router"));
|
|
20
|
+
const rate_limit_1 = __importDefault(require("@fastify/rate-limit"));
|
|
21
|
+
const outers_1 = require("outers");
|
|
22
|
+
// Start the server
|
|
23
|
+
const start = (options) => __awaiter(void 0, void 0, void 0, function* () {
|
|
24
|
+
// Create a Fastify instance
|
|
25
|
+
const fastify = (0, fastify_1.default)({
|
|
26
|
+
logger: true, // Enable logging
|
|
27
|
+
});
|
|
28
|
+
const PORT = Number(Keys_1.ServerPorts.HTTP) || 27018;
|
|
29
|
+
// Register the rate limit plugin with custom error response
|
|
30
|
+
// This will limit the number of requests to 100 per minute
|
|
31
|
+
yield fastify.register(rate_limit_1.default, {
|
|
32
|
+
max: 100, // Max number of requests
|
|
33
|
+
timeWindow: "1 minute", // Time window for the max
|
|
34
|
+
errorResponseBuilder: function (req, context) {
|
|
35
|
+
return {
|
|
36
|
+
statusCode: outers_1.StatusCodes.TOO_MANY_REQUESTS,
|
|
37
|
+
success: false,
|
|
38
|
+
error: "Too Many Requests",
|
|
39
|
+
message: `You have reached the limit of ${context.max} requests in ${context.after}. Try again later.`,
|
|
40
|
+
};
|
|
41
|
+
},
|
|
42
|
+
});
|
|
43
|
+
// Register routes with a prefix
|
|
44
|
+
fastify.register(Router_1.default, {
|
|
45
|
+
prefix: "/services",
|
|
46
|
+
DBInstances: options,
|
|
47
|
+
});
|
|
48
|
+
// Define a simple important route
|
|
49
|
+
fastify.get("/", (_request, _reply) => __awaiter(void 0, void 0, void 0, function* () {
|
|
50
|
+
return { message: "Hello, from AxioDB Docker Container" };
|
|
51
|
+
}));
|
|
52
|
+
fastify.get("/status", (_request, reply) => __awaiter(void 0, void 0, void 0, function* () {
|
|
53
|
+
return reply.status(outers_1.StatusCodes.OK).send({
|
|
54
|
+
status: "OK",
|
|
55
|
+
message: "AxioDB is running",
|
|
56
|
+
});
|
|
57
|
+
}));
|
|
58
|
+
// Define a route to get the version information
|
|
59
|
+
fastify.get("/info", (_request, _reply) => __awaiter(void 0, void 0, void 0, function* () {
|
|
60
|
+
const { DB_Info, OS_Info, Runtime_Info } = yield (0, Info_1.default)();
|
|
61
|
+
return { DB_Info, OS_Info, Runtime_Info };
|
|
62
|
+
}));
|
|
63
|
+
try {
|
|
64
|
+
yield fastify.listen({ port: PORT, host: "0.0.0.0" });
|
|
65
|
+
console.log(`REST API Server is running at http://localhost:${PORT}`);
|
|
66
|
+
}
|
|
67
|
+
catch (err) {
|
|
68
|
+
fastify.log.error(err);
|
|
69
|
+
}
|
|
70
|
+
});
|
|
71
|
+
exports.default = start;
|
|
72
|
+
//# sourceMappingURL=Fastify.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Fastify.js","sourceRoot":"","sources":["../../../../source/Docker/Server/Fastify/Fastify.ts"],"names":[],"mappings":";;;;;;;;;;;;;;AAAA,sDAA8B;AAC9B,6DAA2C;AAC3C,4CAAgD;AAKhD,oBAAoB;AACpB,6DAAgD;AAChD,qEAAmD;AACnD,mCAAqC;AASrC,mBAAmB;AACnB,MAAM,KAAK,GAAG,CAAO,OAAsB,EAAE,EAAE;IAC7C,4BAA4B;IAC5B,MAAM,OAAO,GAAG,IAAA,iBAAO,EAAC;QACtB,MAAM,EAAE,IAAI,EAAE,iBAAiB;KAChC,CAAC,CAAC;IAEH,MAAM,IAAI,GAAW,MAAM,CAAC,kBAAW,CAAC,IAAI,CAAC,IAAI,KAAK,CAAC;IAEvD,4DAA4D;IAC5D,2DAA2D;IAC3D,MAAM,OAAO,CAAC,QAAQ,CAAC,oBAAgB,EAAE;QACvC,GAAG,EAAE,GAAG,EAAE,yBAAyB;QACnC,UAAU,EAAE,UAAU,EAAE,0BAA0B;QAClD,oBAAoB,EAAE,UAAU,GAAG,EAAE,OAAO;YAC1C,OAAO;gBACL,UAAU,EAAE,oBAAW,CAAC,iBAAiB;gBACzC,OAAO,EAAE,KAAK;gBACd,KAAK,EAAE,mBAAmB;gBAC1B,OAAO,EAAE,iCAAiC,OAAO,CAAC,GAAG,gBAAgB,OAAO,CAAC,KAAK,oBAAoB;aACvG,CAAC;QACJ,CAAC;KACF,CAAC,CAAC;IAEH,gCAAgC;IAChC,OAAO,CAAC,QAAQ,CAAC,gBAAiB,EAAE;QAClC,MAAM,EAAE,WAAW;QACnB,WAAW,EAAE,OAAO;KACrB,CAAC,CAAC;IAEH,kCAAkC;IAClC,OAAO,CAAC,GAAG,CAAC,GAAG,EAAE,CAAO,QAAa,EAAE,MAAW,EAAE,EAAE;QACpD,OAAO,EAAE,OAAO,EAAE,qCAAqC,EAAE,CAAC;IAC5D,CAAC,CAAA,CAAC,CAAC;IAEH,OAAO,CAAC,GAAG,CAAC,SAAS,EAAE,CAAO,QAAa,EAAE,KAAU,EAAE,EAAE;QACzD,OAAO,KAAK,CAAC,MAAM,CAAC,oBAAW,CAAC,EAAE,CAAC,CAAC,IAAI,CAAC;YACvC,MAAM,EAAE,IAAI;YACZ,OAAO,EAAE,mBAAmB;SAC7B,CAAC,CAAC;IACL,CAAC,CAAA,CAAC,CAAC;IAEH,gDAAgD;IAChD,OAAO,CAAC,GAAG,CAAC,OAAO,EAAE,CAAO,QAAa,EAAE,MAAW,EAAE,EAAE;QACxD,MAAM,EAAE,OAAO,EAAE,OAAO,EAAE,YAAY,EAAE,GAAG,MAAM,IAAA,cAAU,GAAE,CAAC;QAC9D,OAAO,EAAE,OAAO,EAAE,OAAO,EAAE,YAAY,EAAE,CAAC;IAC5C,CAAC,CAAA,CAAC,CAAC;IAEH,IAAI,CAAC;QACH,MAAM,OAAO,CAAC,MAAM,CAAC,EAAE,IAAI,EAAE,IAAI,EAAE,IAAI,EAAE,SAAS,EAAE,CAAC,CAAC;QACtD,OAAO,CAAC,GAAG,CAAC,kDAAkD,IAAI,EAAE,CAAC,CAAC;IACxE,CAAC;IAAC,OAAO,GAAG,EAAE,CAAC;QACb,OAAO,CAAC,GAAG,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC;IACzB,CAAC;AACH,CAAC,CAAA,CAAC;AAEF,kBAAe,KAAK,CAAC"}
|
|
@@ -0,0 +1,34 @@
|
|
|
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
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
12
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
13
|
+
};
|
|
14
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
|
+
exports.default = userAuthentication;
|
|
16
|
+
// Import Controllers
|
|
17
|
+
const Authentication_1 = __importDefault(require("../../../../Controller/Authentication/Authentication"));
|
|
18
|
+
// Method to handle user Authentication management
|
|
19
|
+
function userAuthentication(fastify, options) {
|
|
20
|
+
const { CentralAuthCollection } = options;
|
|
21
|
+
// Route to handle user registration
|
|
22
|
+
fastify.post("/register", (request, reply) => __awaiter(this, void 0, void 0, function* () {
|
|
23
|
+
const userData = request.body;
|
|
24
|
+
const result = yield Authentication_1.default.Register(userData, CentralAuthCollection);
|
|
25
|
+
return reply.status(result.status ? 201 : 400).send(result);
|
|
26
|
+
}));
|
|
27
|
+
// Route to handle user login
|
|
28
|
+
fastify.post("/login", (request, reply) => __awaiter(this, void 0, void 0, function* () {
|
|
29
|
+
const userData = request.body;
|
|
30
|
+
const result = yield Authentication_1.default.Login(userData, CentralAuthCollection);
|
|
31
|
+
return reply.status(result.status ? 200 : 401).send(result);
|
|
32
|
+
}));
|
|
33
|
+
}
|
|
34
|
+
//# sourceMappingURL=Authentication.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Authentication.js","sourceRoot":"","sources":["../../../../../../source/Docker/Server/Fastify/Router/Authentication/Authentication.ts"],"names":[],"mappings":";;;;;;;;;;;;;;AAOA,qCAuBC;AA5BD,qBAAqB;AACrB,0GAAkF;AAGlF,kDAAkD;AAClD,SAAwB,kBAAkB,CACxC,OAAwB,EACxB,OAA8C;IAE9C,MAAM,EAAE,qBAAqB,EAAE,GAAG,OAAO,CAAC;IAC1C,oCAAoC;IACpC,OAAO,CAAC,IAAI,CAAC,WAAW,EAAE,CAAO,OAAY,EAAE,KAAU,EAAE,EAAE;QAC3D,MAAM,QAAQ,GAAG,OAAO,CAAC,IAAI,CAAC;QAE9B,MAAM,MAAM,GAAG,MAAM,wBAAc,CAAC,QAAQ,CAC1C,QAAQ,EACR,qBAAqB,CACtB,CAAC;QACF,OAAO,KAAK,CAAC,MAAM,CAAC,MAAM,CAAC,MAAM,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC;IAC9D,CAAC,CAAA,CAAC,CAAC;IAEH,6BAA6B;IAC7B,OAAO,CAAC,IAAI,CAAC,QAAQ,EAAE,CAAO,OAAY,EAAE,KAAU,EAAE,EAAE;QACxD,MAAM,QAAQ,GAAG,OAAO,CAAC,IAAI,CAAC;QAE9B,MAAM,MAAM,GAAG,MAAM,wBAAc,CAAC,KAAK,CAAC,QAAQ,EAAE,qBAAqB,CAAC,CAAC;QAC3E,OAAO,KAAK,CAAC,MAAM,CAAC,MAAM,CAAC,MAAM,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC;IAC9D,CAAC,CAAA,CAAC,CAAC;AACL,CAAC"}
|
|
@@ -0,0 +1,37 @@
|
|
|
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
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
12
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
13
|
+
};
|
|
14
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
|
+
exports.default = MainServiceRoutes;
|
|
16
|
+
const Authentication_1 = __importDefault(require("./Authentication/Authentication"));
|
|
17
|
+
const validateToken_middleware_1 = __importDefault(require("../../../Middlewares/validateToken.middleware"));
|
|
18
|
+
// Main Service Routes to link all the routes to the main service
|
|
19
|
+
function MainServiceRoutes(fastify, options) {
|
|
20
|
+
const { DBInstances } = options;
|
|
21
|
+
// Register the Authentication routes
|
|
22
|
+
fastify.register(Authentication_1.default, {
|
|
23
|
+
prefix: "/auth",
|
|
24
|
+
CentralAuthCollection: DBInstances.CentralAuthCollection,
|
|
25
|
+
});
|
|
26
|
+
// Register DB instances for the central service
|
|
27
|
+
fastify.register(function (instance, opts) {
|
|
28
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
29
|
+
// Register the Middleware for the /auth routes
|
|
30
|
+
instance.addHook("preHandler", (request, reply) => __awaiter(this, void 0, void 0, function* () { return (0, validateToken_middleware_1.default)(request, reply); }));
|
|
31
|
+
});
|
|
32
|
+
}, {
|
|
33
|
+
prefix: "/central",
|
|
34
|
+
CentralAuthCollection: DBInstances.CentralAuthCollection,
|
|
35
|
+
});
|
|
36
|
+
}
|
|
37
|
+
//# sourceMappingURL=Router.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Router.js","sourceRoot":"","sources":["../../../../../source/Docker/Server/Fastify/Router/Router.ts"],"names":[],"mappings":";;;;;;;;;;;;;;AAMA,oCAyBC;AA9BD,qFAAiE;AACjE,6GAA0E;AAG1E,iEAAiE;AACjE,SAAwB,iBAAiB,CACvC,OAAwB,EACxB,OAAY;IAEZ,MAAM,EAAE,WAAW,EAAE,GAAG,OAAO,CAAC;IAEhC,qCAAqC;IACrC,OAAO,CAAC,QAAQ,CAAC,wBAAkB,EAAE;QACnC,MAAM,EAAE,OAAO;QACf,qBAAqB,EAAE,WAAW,CAAC,qBAAqB;KACzD,CAAC,CAAC;IAEH,gDAAgD;IAChD,OAAO,CAAC,QAAQ,CACd,UAAgB,QAAyB,EAAE,IAAS;;YAClD,+CAA+C;YAC/C,QAAQ,CAAC,OAAO,CAAC,YAAY,EAAE,CAAO,OAAO,EAAE,KAAK,EAAE,EAAE,gDACtD,OAAA,IAAA,kCAAa,EAAC,OAAsB,EAAE,KAAK,CAAC,CAAA,GAAA,CAC7C,CAAC;QACJ,CAAC;KAAA,EACD;QACE,MAAM,EAAE,UAAU;QAClB,qBAAqB,EAAE,WAAW,CAAC,qBAAqB;KACzD,CACF,CAAC;AACJ,CAAC"}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import Collection from "axiodb/lib/Operation/Collection/collection.operation";
|
|
2
|
+
import Database from "axiodb/lib/Operation/Database/database.operation";
|
|
3
|
+
import { AxioDB } from "axiodb";
|
|
4
|
+
interface ServerOptions {
|
|
5
|
+
CentralAuthCollection: Collection;
|
|
6
|
+
CentralDB: Database;
|
|
7
|
+
CentralDBInstance: AxioDB;
|
|
8
|
+
}
|
|
9
|
+
declare const GRPC_SERVER: (options?: ServerOptions) => Promise<void>;
|
|
10
|
+
export default GRPC_SERVER;
|
|
@@ -0,0 +1,111 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || (function () {
|
|
19
|
+
var ownKeys = function(o) {
|
|
20
|
+
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
21
|
+
var ar = [];
|
|
22
|
+
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
23
|
+
return ar;
|
|
24
|
+
};
|
|
25
|
+
return ownKeys(o);
|
|
26
|
+
};
|
|
27
|
+
return function (mod) {
|
|
28
|
+
if (mod && mod.__esModule) return mod;
|
|
29
|
+
var result = {};
|
|
30
|
+
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
31
|
+
__setModuleDefault(result, mod);
|
|
32
|
+
return result;
|
|
33
|
+
};
|
|
34
|
+
})();
|
|
35
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
36
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
37
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
38
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
39
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
40
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
41
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
42
|
+
});
|
|
43
|
+
};
|
|
44
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
45
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
46
|
+
};
|
|
47
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
48
|
+
const grpc = __importStar(require("@grpc/grpc-js"));
|
|
49
|
+
const protoLoader = __importStar(require("@grpc/proto-loader"));
|
|
50
|
+
const path_1 = __importDefault(require("path"));
|
|
51
|
+
const Keys_1 = require("../../config/Keys");
|
|
52
|
+
const GRPC_SERVER = (options) => __awaiter(void 0, void 0, void 0, function* () {
|
|
53
|
+
// Define the path to your proto file
|
|
54
|
+
const PROTO_PATH = path_1.default.resolve(__dirname, "Protos/service.proto");
|
|
55
|
+
// Load the proto file
|
|
56
|
+
const packageDefinition = protoLoader.loadSync(PROTO_PATH, {
|
|
57
|
+
keepCase: true,
|
|
58
|
+
longs: String,
|
|
59
|
+
enums: String,
|
|
60
|
+
defaults: true,
|
|
61
|
+
oneofs: true,
|
|
62
|
+
});
|
|
63
|
+
// Load the package definition
|
|
64
|
+
const protoDescriptor = grpc.loadPackageDefinition(packageDefinition);
|
|
65
|
+
// Use the correct package name from the proto file
|
|
66
|
+
const serviceProto = protoDescriptor.axio_db;
|
|
67
|
+
// Create a minimal implementation that just acknowledges requests
|
|
68
|
+
const serviceImplementation = {
|
|
69
|
+
Get: (call, callback) => {
|
|
70
|
+
callback(null, { success: true, value: "", error_message: "" });
|
|
71
|
+
},
|
|
72
|
+
Set: (call, callback) => {
|
|
73
|
+
callback(null, { success: true, error_message: "" });
|
|
74
|
+
},
|
|
75
|
+
Delete: (call, callback) => {
|
|
76
|
+
callback(null, { success: true, error_message: "" });
|
|
77
|
+
},
|
|
78
|
+
Exists: (call, callback) => {
|
|
79
|
+
callback(null, { exists: false });
|
|
80
|
+
},
|
|
81
|
+
Keys: (call, callback) => {
|
|
82
|
+
callback(null, { keys: [] });
|
|
83
|
+
},
|
|
84
|
+
};
|
|
85
|
+
// Create a new gRPC server
|
|
86
|
+
const server = new grpc.Server();
|
|
87
|
+
// Add the service implementation to the server
|
|
88
|
+
// @ts-ignore - Suppressing TypeScript error for dynamic service binding
|
|
89
|
+
server.addService(serviceProto.AxioDBService.service, serviceImplementation);
|
|
90
|
+
// Define the server address and port
|
|
91
|
+
const serverAddress = `0.0.0.0:${Keys_1.ServerPorts.GRPC}`;
|
|
92
|
+
// Start the server
|
|
93
|
+
server.bindAsync(serverAddress, grpc.ServerCredentials.createInsecure(), (error, port) => {
|
|
94
|
+
if (error) {
|
|
95
|
+
console.error("Failed to bind server:", error);
|
|
96
|
+
return;
|
|
97
|
+
}
|
|
98
|
+
server.start();
|
|
99
|
+
console.log(`gRPC server started, listening on ${serverAddress}`);
|
|
100
|
+
});
|
|
101
|
+
// Handle graceful shutdown
|
|
102
|
+
process.on("SIGINT", () => {
|
|
103
|
+
console.log("Shutting down gRPC server...");
|
|
104
|
+
server.tryShutdown(() => {
|
|
105
|
+
console.log("Server shut down successfully");
|
|
106
|
+
process.exit(0);
|
|
107
|
+
});
|
|
108
|
+
});
|
|
109
|
+
});
|
|
110
|
+
exports.default = GRPC_SERVER;
|
|
111
|
+
//# sourceMappingURL=GRPC.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"GRPC.js","sourceRoot":"","sources":["../../../../source/Docker/Server/GRPC/GRPC.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,oDAAsC;AACtC,gEAAkD;AAClD,gDAAwB;AACxB,4CAAgD;AAYhD,MAAM,WAAW,GAAG,CAAO,OAAuB,EAAE,EAAE;IACpD,qCAAqC;IACrC,MAAM,UAAU,GAAG,cAAI,CAAC,OAAO,CAAC,SAAS,EAAE,sBAAsB,CAAC,CAAC;IAEnE,sBAAsB;IACtB,MAAM,iBAAiB,GAAG,WAAW,CAAC,QAAQ,CAAC,UAAU,EAAE;QACzD,QAAQ,EAAE,IAAI;QACd,KAAK,EAAE,MAAM;QACb,KAAK,EAAE,MAAM;QACb,QAAQ,EAA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AC;IAE7E,qCAAqC;IACrC,MAAM,aAAa,GAAG,WAAW,kBAAW,CAAC,IAAI,EAAE,CAAC;IAEpD,mBAAmB;IACnB,MAAM,CAAC,SAAS,CACd,aAAa,EACb,IAAI,CAAC,iBAAiB,CAAC,cAAc,EAAE,EACvC,CAAC,KAAK,EAAE,IAAI,EAAE,EAAE;QACd,IAAI,KAAK,EAAE,CAAC;YACV,OAAO,CAAC,KAAK,CAAC,wBAAwB,EAAE,KAAK,CAAC,CAAC;YAC/C,OAAO;QACT,CAAC;QAED,MAAM,CAAC,KAAK,EAAE,CAAC;QACf,OAAO,CAAC,GAAG,CAAC,qCAAqC,aAAa,EAAE,CAAC,CAAC;IACpE,CAAC,CACF,CAAC;IAEF,2BAA2B;IAC3B,OAAO,CAAC,EAAE,CAAC,QAAQ,EAAE,GAAG,EAAE;QACxB,OAAO,CAAC,GAAG,CAAC,8BAA8B,CAAC,CAAC;QAC5C,MAAM,CAAC,WAAW,CAAC,GAAG,EAAE;YACtB,OAAO,CAAC,GAAG,CAAC,+BAA+B,CAAC,CAAC;YAC7C,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;QAClB,CAAC,CAAC,CAAC;IACL,CAAC,CAAC,CAAC;AACL,CAAC,CAAA,CAAC;AAEF,kBAAe,WAAW,CAAC"}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import Collection from "axiodb/lib/Operation/Collection/collection.operation";
|
|
2
|
+
import Database from "axiodb/lib/Operation/Database/database.operation";
|
|
3
|
+
import { AxioDB } from "axiodb";
|
|
4
|
+
interface ServerOptions {
|
|
5
|
+
CentralAuthCollection: Collection;
|
|
6
|
+
CentralDB: Database;
|
|
7
|
+
CentralDBInstance: AxioDB;
|
|
8
|
+
}
|
|
9
|
+
declare const tcpServer: (options?: ServerOptions) => Promise<void>;
|
|
10
|
+
export default tcpServer;
|
|
@@ -0,0 +1,38 @@
|
|
|
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
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
12
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
13
|
+
};
|
|
14
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
|
+
// Import TCP Server Configuration
|
|
16
|
+
const node_net_1 = __importDefault(require("node:net"));
|
|
17
|
+
const Keys_1 = require("../config/Keys");
|
|
18
|
+
const PORT = Number(Keys_1.ServerPorts.TCP) || 27018;
|
|
19
|
+
const tcpServer = (options) => __awaiter(void 0, void 0, void 0, function* () {
|
|
20
|
+
const server = node_net_1.default.createServer((socket) => {
|
|
21
|
+
console.log("Client connected");
|
|
22
|
+
socket.on("data", (Command) => {
|
|
23
|
+
console.log("Received from client:", Command.toString());
|
|
24
|
+
socket.write(`Echo: ${Command}`);
|
|
25
|
+
});
|
|
26
|
+
socket.on("end", () => {
|
|
27
|
+
console.log("Client disconnected");
|
|
28
|
+
});
|
|
29
|
+
socket.on("error", (err) => {
|
|
30
|
+
console.error("Socket Error:", err.message);
|
|
31
|
+
});
|
|
32
|
+
});
|
|
33
|
+
server.listen(PORT, () => {
|
|
34
|
+
console.log(`TCP Server listening on port ${PORT}`);
|
|
35
|
+
});
|
|
36
|
+
});
|
|
37
|
+
exports.default = tcpServer;
|
|
38
|
+
//# sourceMappingURL=TCP.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"TCP.js","sourceRoot":"","sources":["../../../source/Docker/Server/TCP.ts"],"names":[],"mappings":";;;;;;;;;;;;;;AAAA,kCAAkC;AAClC,wDAA2B;AAC3B,yCAA6C;AAI7C,MAAM,IAAI,GAAW,MAAM,CAAC,kBAAW,CAAC,GAAG,CAAC,IAAI,KAAK,CAAC;AAStD,MAAM,SAAS,GAAG,CAAO,OAAuB,EAAE,EAAE;IAClD,MAAM,MAAM,GAAG,kBAAG,CAAC,YAAY,CAAC,CAAC,MAAM,EAAE,EAAE;QACzC,OAAO,CAAC,GAAG,CAAC,kBAAkB,CAAC,CAAC;QAEhC,MAAM,CAAC,EAAE,CAAC,MAAM,EAAE,CAAC,OAAe,EAAE,EAAE;YACpC,OAAO,CAAC,GAAG,CAAC,uBAAuB,EAAE,OAAO,CAAC,QAAQ,EAAE,CAAC,CAAC;YACzD,MAAM,CAAC,KAAK,CAAC,SAAS,OAAO,EAAE,CAAC,CAAC;QACnC,CAAC,CAAC,CAAC;QAEH,MAAM,CAAC,EAAE,CAAC,KAAK,EAAE,GAAG,EAAE;YACpB,OAAO,CAAC,GAAG,CAAC,qBAAqB,CAAC,CAAC;QACrC,CAAC,CAAC,CAAC;QAEH,MAAM,CAAC,EAAE,CAAC,OAAO,EAAE,CAAC,GAAU,EAAE,EAAE;YAChC,OAAO,CAAC,KAAK,CAAC,eAAe,EAAE,GAAG,CAAC,OAAO,CAAC,CAAC;QAC9C,CAAC,CAAC,CAAC;IACL,CAAC,CAAC,CAAC;IAEH,MAAM,CAAC,MAAM,CAAC,IAAI,EAAE,GAAG,EAAE;QACvB,OAAO,CAAC,GAAG,CAAC,gCAAgC,IAAI,EAAE,CAAC,CAAC;IACtD,CAAC,CAAC,CAAC;AACL,CAAC,CAAA,CAAC;AAEF,kBAAe,SAAS,CAAC"}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import Collection from "axiodb/lib/Operation/Collection/collection.operation";
|
|
2
|
+
import Database from "axiodb/lib/Operation/Database/database.operation";
|
|
3
|
+
import { AxioDB } from "axiodb";
|
|
4
|
+
interface ServerOptions {
|
|
5
|
+
CentralAuthCollection: Collection;
|
|
6
|
+
CentralDB: Database;
|
|
7
|
+
CentralDBInstance: AxioDB;
|
|
8
|
+
}
|
|
9
|
+
export declare const udpServer: (options?: ServerOptions) => void;
|
|
10
|
+
export {};
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.udpServer = void 0;
|
|
4
|
+
const dgram_1 = require("dgram");
|
|
5
|
+
const Keys_1 = require("../config/Keys");
|
|
6
|
+
const udpServer = (options) => {
|
|
7
|
+
const server = (0, dgram_1.createSocket)("udp4");
|
|
8
|
+
server.on("message", (Command, rinfo) => {
|
|
9
|
+
console.log(`UDP Server received: ${Command.toString()} from ${rinfo.address}:${rinfo.port}`);
|
|
10
|
+
server.send(Command, rinfo.port, rinfo.address, (err) => {
|
|
11
|
+
if (err) {
|
|
12
|
+
console.error("Error sending response:", err);
|
|
13
|
+
}
|
|
14
|
+
else {
|
|
15
|
+
console.log("Response sent");
|
|
16
|
+
}
|
|
17
|
+
});
|
|
18
|
+
});
|
|
19
|
+
server.on("error", (err) => {
|
|
20
|
+
console.error(`UDP Server error: ${err.message}`);
|
|
21
|
+
server.close();
|
|
22
|
+
});
|
|
23
|
+
server.bind(Keys_1.ServerPorts.UDP, () => {
|
|
24
|
+
console.log(`UDP Server listening on port ${Keys_1.ServerPorts.UDP}`);
|
|
25
|
+
});
|
|
26
|
+
};
|
|
27
|
+
exports.udpServer = udpServer;
|
|
28
|
+
//# sourceMappingURL=UDP.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"UDP.js","sourceRoot":"","sources":["../../../source/Docker/Server/UDP.ts"],"names":[],"mappings":";;;AAAA,iCAAqC;AACrC,yCAA6C;AAWtC,MAAM,SAAS,GAAG,CAAC,OAAuB,EAAE,EAAE;IACnD,MAAM,MAAM,GAAG,IAAA,oBAAY,EAAC,MAAM,CAAC,CAAC;IAEpC,MAAM,CAAC,EAAE,CACP,SAAS,EACT,CAAC,OAAe,EAAE,KAAwC,EAAE,EAAE;QAC5D,OAAO,CAAC,GAAG,CACT,wBAAwB,OAAO,CAAC,QAAQ,EAAE,SAAS,KAAK,CAAC,OAAO,IAAI,KAAK,CAAC,IAAI,EAAE,CACjF,CAAC;QACF,MAAM,CAAC,IAAI,CAAC,OAAO,EAAE,KAAK,CAAC,IAAI,EAAE,KAAK,CAAC,OAAO,EAAE,CAAC,GAAG,EAAE,EAAE;YACtD,IAAI,GAAG,EAAE,CAAC;gBACR,OAAO,CAAC,KAAK,CAAC,yBAAyB,EAAE,GAAG,CAAC,CAAC;YAChD,CAAC;iBAAM,CAAC;gBACN,OAAO,CAAC,GAAG,CAAC,eAAe,CAAC,CAAC;YAC/B,CAAC;QACH,CAAC,CAAC,CAAC;IACL,CAAC,CACF,CAAC;IAEF,MAAM,CAAC,EAAE,CAAC,OAAO,EAAE,CAAC,GAAU,EAAE,EAAE;QAChC,OAAO,CAAC,KAAK,CAAC,qBAAqB,GAAG,CAAC,OAAO,EAAE,CAAC,CAAC;QAClD,MAAM,CAAC,KAAK,EAAE,CAAC;IACjB,CAAC,CAAC,CAAC;IAEH,MAAM,CAAC,IAAI,CAAC,kBAAW,CAAC,GAAG,EAAE,GAAG,EAAE;QAChC,OAAO,CAAC,GAAG,CAAC,gCAAgC,kBAAW,CAAC,GAAG,EAAE,CAAC,CAAC;IACjE,CAAC,CAAC,CAAC;AACL,CAAC,CAAC;AA3BW,QAAA,SAAS,aA2BpB"}
|
|
File without changes
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Websocket.js","sourceRoot":"","sources":["../../../source/Docker/Server/Websocket.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
declare const _default: () => Promise<{
|
|
2
|
+
DB_Info: {
|
|
3
|
+
AxioDB_Version: any;
|
|
4
|
+
AxioDB_Docker_Version: any;
|
|
5
|
+
Author: any;
|
|
6
|
+
License: any;
|
|
7
|
+
Latest_Update: any;
|
|
8
|
+
};
|
|
9
|
+
OS_Info: {
|
|
10
|
+
OS: NodeJS.Platform;
|
|
11
|
+
Architecture: NodeJS.Architecture;
|
|
12
|
+
Memory: string | number;
|
|
13
|
+
Uptime: number;
|
|
14
|
+
Load_Average: string;
|
|
15
|
+
Free_Memory: number;
|
|
16
|
+
Total_Memory: number;
|
|
17
|
+
CPU_Usage: NodeJS.CpuUsage;
|
|
18
|
+
CPU_Usage_Percent: number;
|
|
19
|
+
};
|
|
20
|
+
Runtime_Info: {
|
|
21
|
+
Node_Version: string;
|
|
22
|
+
NPM_Version: string | undefined;
|
|
23
|
+
V8_Version: string;
|
|
24
|
+
OpenSSL_Version: string;
|
|
25
|
+
Zlib_Version: string;
|
|
26
|
+
Libuv_Version: string | undefined;
|
|
27
|
+
WebServer_Version: any;
|
|
28
|
+
};
|
|
29
|
+
}>;
|
|
30
|
+
export default _default;
|
|
@@ -0,0 +1,52 @@
|
|
|
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
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
12
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
13
|
+
};
|
|
14
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
|
+
const promises_1 = require("node:fs/promises");
|
|
16
|
+
const node_os_1 = __importDefault(require("node:os"));
|
|
17
|
+
exports.default = () => __awaiter(void 0, void 0, void 0, function* () {
|
|
18
|
+
// Read the version from the version file
|
|
19
|
+
const versionData = yield (0, promises_1.readFile)("package.json", "utf-8");
|
|
20
|
+
const versionJson = JSON.parse(versionData);
|
|
21
|
+
const DB_Info = {
|
|
22
|
+
AxioDB_Version: versionJson.dependencies["axiodb"],
|
|
23
|
+
AxioDB_Docker_Version: versionJson.version,
|
|
24
|
+
Author: versionJson.author,
|
|
25
|
+
License: versionJson.license,
|
|
26
|
+
Latest_Update: versionJson.Published,
|
|
27
|
+
};
|
|
28
|
+
const OS_Info = {
|
|
29
|
+
OS: process.platform,
|
|
30
|
+
Architecture: process.arch,
|
|
31
|
+
Memory: process.memoryUsage()
|
|
32
|
+
? process.memoryUsage().heapTotal / 1024 / 1024
|
|
33
|
+
: "N/A",
|
|
34
|
+
Uptime: process.uptime() / 60,
|
|
35
|
+
Load_Average: node_os_1.default.loadavg() ? node_os_1.default.loadavg().toString() : "N/A",
|
|
36
|
+
Free_Memory: node_os_1.default.freemem() / 1024 / 1024,
|
|
37
|
+
Total_Memory: node_os_1.default.totalmem() / 1024 / 1024,
|
|
38
|
+
CPU_Usage: process.cpuUsage(),
|
|
39
|
+
CPU_Usage_Percent: (process.cpuUsage().user + process.cpuUsage().system) / 1000,
|
|
40
|
+
};
|
|
41
|
+
const Runtime_Info = {
|
|
42
|
+
Node_Version: process.versions.node,
|
|
43
|
+
NPM_Version: process.versions.npm,
|
|
44
|
+
V8_Version: process.versions.v8,
|
|
45
|
+
OpenSSL_Version: process.versions.openssl,
|
|
46
|
+
Zlib_Version: process.versions.zlib,
|
|
47
|
+
Libuv_Version: process.versions.libuv,
|
|
48
|
+
WebServer_Version: versionJson.dependencies.fastify,
|
|
49
|
+
};
|
|
50
|
+
return { DB_Info, OS_Info, Runtime_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Q,EAAE;QAC7B,iBAAiB,EACf,CAAC,OAAO,CAAC,QAAQ,EAAE,CAAC,IAAI,GAAG,OAAO,CAAC,QAAQ,EAAE,CAAC,MAAM,CAAC,GAAG,IAAI;KAC/D,CAAC;IACF,MAAM,YAAY,GAAG;QACnB,YAAY,EAAE,OAAO,CAAC,QAAQ,CAAC,IAAI;QACnC,WAAW,EAAE,OAAO,CAAC,QAAQ,CAAC,GAAG;QACjC,UAAU,EAAE,OAAO,CAAC,QAAQ,CAAC,EAAE;QAC/B,eAAe,EAAE,OAAO,CAAC,QAAQ,CAAC,OAAO;QACzC,YAAY,EAAE,OAAO,CAAC,QAAQ,CAAC,IAAI;QACnC,aAAa,EAAE,OAAO,CAAC,QAAQ,CAAC,KAAK;QACrC,iBAAiB,EAAE,WAAW,CAAC,YAAY,CAAC,OAAO;KACpD,CAAC;IACF,OAAO,EAAE,OAAO,EAAE,OAAO,EAAE,YAAY,EAAE,CAAC;AAC5C,CAAC,CAAA,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"RequestInterface.js","sourceRoot":"","sources":["../../../../source/Docker/config/Interfaces/RequestInterface.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
export declare enum ServerPorts {
|
|
2
|
+
HTTP = 27018,
|
|
3
|
+
TCP = 27019,
|
|
4
|
+
GRPC = 27020,
|
|
5
|
+
WEBSOCKET = 27021,
|
|
6
|
+
UDP = 27022
|
|
7
|
+
}
|
|
8
|
+
export declare const CentralDB_Auth_UserCollection_Schema: {
|
|
9
|
+
name: string[];
|
|
10
|
+
email: string[];
|
|
11
|
+
username: string[];
|
|
12
|
+
password: string[];
|
|
13
|
+
AccessToken: string[];
|
|
14
|
+
};
|
|
15
|
+
export declare const CentralInformation: {
|
|
16
|
+
CentralDB_InstanceName: string;
|
|
17
|
+
CentralDB_Name: string;
|
|
18
|
+
CentralDB_JWT_Secret: string;
|
|
19
|
+
CentralDB_Collection_Auth: string;
|
|
20
|
+
CentralDB_Auth_UserCollection_Schema: Record<string, any>;
|
|
21
|
+
};
|
|
@@ -0,0 +1,30 @@
|
|
|
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.CentralInformation = exports.CentralDB_Auth_UserCollection_Schema = exports.ServerPorts = void 0;
|
|
7
|
+
const SchemaGenerator_util_1 = __importDefault(require("../util/SchemaGenerator.util"));
|
|
8
|
+
var ServerPorts;
|
|
9
|
+
(function (ServerPorts) {
|
|
10
|
+
ServerPorts[ServerPorts["HTTP"] = 27018] = "HTTP";
|
|
11
|
+
ServerPorts[ServerPorts["TCP"] = 27019] = "TCP";
|
|
12
|
+
ServerPorts[ServerPorts["GRPC"] = 27020] = "GRPC";
|
|
13
|
+
ServerPorts[ServerPorts["WEBSOCKET"] = 27021] = "WEBSOCKET";
|
|
14
|
+
ServerPorts[ServerPorts["UDP"] = 27022] = "UDP";
|
|
15
|
+
})(ServerPorts || (exports.ServerPorts = ServerPorts = {}));
|
|
16
|
+
exports.CentralDB_Auth_UserCollection_Schema = {
|
|
17
|
+
name: ["required"],
|
|
18
|
+
email: ["required"],
|
|
19
|
+
username: ["required"],
|
|
20
|
+
password: ["required"],
|
|
21
|
+
AccessToken: ["optional"],
|
|
22
|
+
};
|
|
23
|
+
exports.CentralInformation = {
|
|
24
|
+
CentralDB_InstanceName: "AxioDB_Central_Information",
|
|
25
|
+
CentralDB_Name: "AxioDB_Central_DB",
|
|
26
|
+
CentralDB_JWT_Secret: "AxioDB_Central_Secret",
|
|
27
|
+
CentralDB_Collection_Auth: "AxioDB_Central_Collection_Auth",
|
|
28
|
+
CentralDB_Auth_UserCollection_Schema: (0, SchemaGenerator_util_1.default)(exports.CentralDB_Auth_UserCollection_Schema),
|
|
29
|
+
};
|
|
30
|
+
//# sourceMappingURL=Keys.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Keys.js","sourceRoot":"","sources":["../../../source/Docker/config/Keys.ts"],"names":[],"mappings":";;;;;;AAAA,wFAA0D;AAE1D,IAAY,WAMX;AAND,WAAY,WAAW;IACrB,iDAAY,CAAA;IACZ,+CAAW,CAAA;IACX,iDAAY,CAAA;IACZ,2DAAiB,CAAA;IACjB,+CAAW,CAAA;AACb,CAAC,EANW,WAAW,2BAAX,WAAW,QAMtB;AAEY,QAAA,oCAAoC,GAAG;IAClD,IAAI,EAAE,CAAC,UAAU,CAAC;IAClB,KAAK,EAAE,CAAC,UAAU,CAAC;IACnB,QAAQ,EAAE,CAAC,UAAU,CAAC;IACtB,QAAQ,EAAE,CAAC,UAAU,CAAC;IACtB,WAAW,EAAE,CAAC,UAAU,CAAC;CAC1B,CAAC;AAEW,QAAA,kBAAkB,GAAG;IAChC,sBAAsB,EAAE,4BAA4B;IACpD,cAAc,EAAE,mBAAmB;IACnC,oBAAoB,EAAE,uBAAuB;IAC7C,yBAAyB,EAAE,gCAAgC;IAC3D,oCAAoC,EAAE,IAAA,8BAAc,EAClD,4CAAoC,CACrC;CACF,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,60 @@
|
|
|
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
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
12
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
13
|
+
};
|
|
14
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
|
+
// Import all Servers
|
|
16
|
+
const Fastify_1 = __importDefault(require("../Server/Fastify/Fastify"));
|
|
17
|
+
const TCP_1 = __importDefault(require("../Server/TCP"));
|
|
18
|
+
const GRPC_1 = __importDefault(require("../Server/GRPC/GRPC"));
|
|
19
|
+
const UDP_1 = require("../Server/UDP");
|
|
20
|
+
const outers_1 = require("outers");
|
|
21
|
+
// Import AxioDB for Storing the Fastify Server Related Information & Authentication
|
|
22
|
+
const axiodb_1 = require("axiodb");
|
|
23
|
+
const Keys_1 = require("./Keys");
|
|
24
|
+
const main = () => __awaiter(void 0, void 0, void 0, function* () {
|
|
25
|
+
/// Create Central Database Instance
|
|
26
|
+
const centralAxioDBInstance = new axiodb_1.AxioDB(Keys_1.CentralInformation.CentralDB_InstanceName, ".");
|
|
27
|
+
outers_1.Console.green("Central AxioDB Instance Created");
|
|
28
|
+
/// Create Central Database
|
|
29
|
+
const centralDB = yield centralAxioDBInstance.createDB(Keys_1.CentralInformation.CentralDB_Name);
|
|
30
|
+
outers_1.Console.green("Central AxioDB Database Created");
|
|
31
|
+
const centralAuthCollection = yield centralDB.createCollection(Keys_1.CentralInformation.CentralDB_Collection_Auth, Keys_1.CentralInformation.CentralDB_Auth_UserCollection_Schema);
|
|
32
|
+
outers_1.Console.green("Central Auth Collection Created");
|
|
33
|
+
/// Start All Servers ========================== X ==========================
|
|
34
|
+
// Start Fastify Server
|
|
35
|
+
(0, Fastify_1.default)({
|
|
36
|
+
CentralAuthCollection: centralAuthCollection,
|
|
37
|
+
CentralDB: centralDB,
|
|
38
|
+
CentralDBInstance: centralAxioDBInstance,
|
|
39
|
+
});
|
|
40
|
+
// Start TCP Server
|
|
41
|
+
(0, TCP_1.default)({
|
|
42
|
+
CentralAuthCollection: centralAuthCollection,
|
|
43
|
+
CentralDB: centralDB,
|
|
44
|
+
CentralDBInstance: centralAxioDBInstance,
|
|
45
|
+
});
|
|
46
|
+
// Start GRPC Server
|
|
47
|
+
(0, GRPC_1.default)({
|
|
48
|
+
CentralAuthCollection: centralAuthCollection,
|
|
49
|
+
CentralDB: centralDB,
|
|
50
|
+
CentralDBInstance: centralAxioDBInstance,
|
|
51
|
+
});
|
|
52
|
+
// Start UDP Server
|
|
53
|
+
(0, UDP_1.udpServer)({
|
|
54
|
+
CentralAuthCollection: centralAuthCollection,
|
|
55
|
+
CentralDB: centralDB,
|
|
56
|
+
CentralDBInstance: centralAxioDBInstance,
|
|
57
|
+
});
|
|
58
|
+
});
|
|
59
|
+
main(); // Start the main function
|
|
60
|
+
//# sourceMappingURL=docker.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"docker.js","sourceRoot":"","sources":["../../../source/Docker/config/docker.ts"],"names":[],"mappings":";;;;;;;;;;;;;;AAAA,qBAAqB;AACrB,wEAAkD;AAClD,wDAAsC;AACtC,+DAA8C;AAC9C,uCAA0C;AAC1C,mCAAiC;AAEjC,oFAAoF;AACpF,mCAAgC;AAChC,iCAA4C;AAE5C,MAAM,IAAI,GAAG,GAAS,EAAE;IACtB,oCAAoC;IACpC,MAAM,qBAAqB,GAAW,IAAI,eAAM,CAC9C,yBAAkB,CAAC,sBAAsB,EACzC,GAAG,CACJ,CAAC;IACF,gBAAO,CAAC,KAAK,CAAC,iCAAiC,CAAC,CAAC;IACjD,2BAA2B;IAC3B,MAAM,SAAS,GAAG,MAAM,qBAAqB,CAAC,QAAQ,CACpD,yBAAkB,CAAC,cAAc,CAClC,CAAC;IACF,gBAAO,CAAC,KAAK,CAAC,iCAAiC,CAAC,CAAC;IACjD,MAAM,qBAAqB,GAAG,MAAM,SAAS,CAAC,gBAAgB,CAC5D,yBAAkB,CAAC,yBAAyB,EAC5C,yBAAkB,CAAC,oCAAoC,CACxD,CAAC;IACF,gBAAO,CAAC,KAAK,CAAC,iCAAiC,CAAC,CAAC;IAEjD,6EAA6E;IAE7E,uBAAuB;IACvB,IAAA,iBAAS,EAAC;QACR,qBAAqB,EAAE,qBAAqB;QAC5C,SAAS,EAAE,SAAS;QACpB,iBAAiB,EAAE,qBAAqB;KACzC,CAAC,CAAC;IAEH,mBAAmB;IACnB,IAAA,aAAS,EAAC;QACR,qBAAqB,EAAE,qBAAqB;QAC5C,SAAS,EAAE,SAAS;QACpB,iBAAiB,EAAE,qBAAqB;KACzC,CAAC,CAAC;IAEH,oBAAoB;IACpB,IAAA,cAAW,EAAC;QACV,qBAAqB,EAAE,qBAAqB;QAC5C,SAAS,EAAE,SAAS;QACpB,iBAAiB,EAAE,qBAAqB;KACzC,CAAC,CAAC;IAEH,mBAAmB;IACnB,IAAA,eAAS,EAAC;QACR,qBAAqB,EAAE,qBAAqB;QAC5C,SAAS,EAAE,SAAS;QACpB,iBAAiB,EAAE,qBAAqB;KACzC,CAAC,CAAC;AACL,CAAC,CAAA,CAAC;AACF,IAAI,EAAE,CAAC,CAAC,0BAA0B"}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Defines the structure for schema input.
|
|
3
|
+
* Each key corresponds to a field name and its value is an array.
|
|
4
|
+
* The first element is the type (e.g., "string", "number") followed by validation modifiers.
|
|
5
|
+
*/
|
|
6
|
+
export type SchemaInput = {
|
|
7
|
+
[key: string]: [...string[]];
|
|
8
|
+
};
|
|
9
|
+
/**
|
|
10
|
+
* Dynamically generates a validation schema object using SchemaTypes.
|
|
11
|
+
*
|
|
12
|
+
* @param input - An object where keys are field names and values are arrays
|
|
13
|
+
* containing the type as the first element followed by validation modifiers.
|
|
14
|
+
*
|
|
15
|
+
* @example
|
|
16
|
+
* ```ts
|
|
17
|
+
* const schema = generateSchema({
|
|
18
|
+
* username: ['string', 'required', 'min:3', 'max:30'],
|
|
19
|
+
* email: ['string', 'required', 'email'],
|
|
20
|
+
* age: ['number', 'min:18', 'default:21']
|
|
21
|
+
* });
|
|
22
|
+
* ```
|
|
23
|
+
*
|
|
24
|
+
* @returns A schema object with dynamically built validation rules.
|
|
25
|
+
*/
|
|
26
|
+
export default function generateSchema(input: SchemaInput): Record<string, any>;
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.default = generateSchema;
|
|
4
|
+
const axiodb_1 = require("axiodb");
|
|
5
|
+
/**
|
|
6
|
+
* Dynamically generates a validation schema object using SchemaTypes.
|
|
7
|
+
*
|
|
8
|
+
* @param input - An object where keys are field names and values are arrays
|
|
9
|
+
* containing the type as the first element followed by validation modifiers.
|
|
10
|
+
*
|
|
11
|
+
* @example
|
|
12
|
+
* ```ts
|
|
13
|
+
* const schema = generateSchema({
|
|
14
|
+
* username: ['string', 'required', 'min:3', 'max:30'],
|
|
15
|
+
* email: ['string', 'required', 'email'],
|
|
16
|
+
* age: ['number', 'min:18', 'default:21']
|
|
17
|
+
* });
|
|
18
|
+
* ```
|
|
19
|
+
*
|
|
20
|
+
* @returns A schema object with dynamically built validation rules.
|
|
21
|
+
*/
|
|
22
|
+
function generateSchema(input) {
|
|
23
|
+
const schema = {};
|
|
24
|
+
for (const [key, value] of Object.entries(input)) {
|
|
25
|
+
const [type, ...modifiers] = value;
|
|
26
|
+
const schemaFunction = axiodb_1.SchemaTypes[type];
|
|
27
|
+
let field = schemaFunction ? schemaFunction() : null;
|
|
28
|
+
if (!field) {
|
|
29
|
+
throw new Error(`Unsupported type '${type}' for key '${key}'.`);
|
|
30
|
+
}
|
|
31
|
+
for (const mod of modifiers) {
|
|
32
|
+
if (mod === "required")
|
|
33
|
+
field = field.required();
|
|
34
|
+
else if (mod === "optional")
|
|
35
|
+
field = field.optional();
|
|
36
|
+
else if (mod === "email")
|
|
37
|
+
field = field.email();
|
|
38
|
+
else if (mod === "alphanum")
|
|
39
|
+
field = field.alphanum();
|
|
40
|
+
else if (mod === "trim")
|
|
41
|
+
field = field.trim();
|
|
42
|
+
else if (mod === "allow:null")
|
|
43
|
+
field = field.allow(null);
|
|
44
|
+
else if (mod.startsWith("min:"))
|
|
45
|
+
field = field.min(Number(mod.split(":")[1]));
|
|
46
|
+
else if (mod.startsWith("max:"))
|
|
47
|
+
field = field.max(Number(mod.split(":")[1]));
|
|
48
|
+
else if (mod.startsWith("length:"))
|
|
49
|
+
field = field.length(Number(mod.split(":")[1]));
|
|
50
|
+
else if (mod.startsWith("default:")) {
|
|
51
|
+
const val = mod.split(":")[1];
|
|
52
|
+
field = field.default(isNaN(Number(val)) ? val : Number(val));
|
|
53
|
+
}
|
|
54
|
+
else if (mod.startsWith("valid:")) {
|
|
55
|
+
const vals = mod.split(":")[1].split(",");
|
|
56
|
+
field = field.valid(...vals);
|
|
57
|
+
}
|
|
58
|
+
else if (mod.startsWith("invalid:")) {
|
|
59
|
+
const vals = mod.split(":")[1].split(",");
|
|
60
|
+
field = field.invalid(...vals);
|
|
61
|
+
}
|
|
62
|
+
else if (mod.startsWith("pattern:")) {
|
|
63
|
+
const pattern = mod.split(":")[1];
|
|
64
|
+
field = field.pattern(new RegExp(pattern));
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
schema[key] = field;
|
|
68
|
+
}
|
|
69
|
+
return schema;
|
|
70
|
+
}
|
|
71
|
+
//# sourceMappingURL=SchemaGenerator.util.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"SchemaGenerator.util.js","sourceRoot":"","sources":["../../../source/Docker/util/SchemaGenerator.util.ts"],"names":[],"mappings":";;AA4BA,iCA8CC;AA1ED,mCAAqC;AAWrC;;;;;;;;;;;;;;;;GAgBG;AACH,SAAwB,cAAc,CACpC,KAAkB;IAElB,MAAM,MAAM,GAAwB,EAAE,CAAC;IAEvC,KAAK,MAAM,CAAC,GAAG,EAAE,KAAK,CAAC,IAAI,MAAM,CAAC,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,KAAK,CAAC,OAAO,CAAC,IAAI,MAAM,CAAC,OAAO,CAAC,CAAC,CAAC;YAC7C,CAAC;QACH,CAAC;QAED,MAAM,CAAC,GAAG,CAAC,GAAG,KAAK,CAAC;IACtB,CAAC;IAED,OAAO,MAAM,CAAC;AAChB,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "axiodb",
|
|
3
|
-
"version": "2.10.22
|
|
3
|
+
"version": "2.10.22",
|
|
4
4
|
"description": "A blazing-fast, lightweight, and scalable nodejs package based DBMS for modern applications. Supports schemas, encryption, and advanced query capabilities.",
|
|
5
5
|
"main": "./lib/config/DB.js",
|
|
6
6
|
"types": "./lib/config/DB.d.ts",
|