@xrystal/core 3.17.0 → 3.17.2
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/package.json
CHANGED
|
@@ -11,13 +11,21 @@ export default class ConfigsService {
|
|
|
11
11
|
const tmp = this.#systemService.tmp;
|
|
12
12
|
const rawConfigs = tmp?.configs || tmp?.configs || {};
|
|
13
13
|
this.config = {
|
|
14
|
+
worker: process.env.WORKER === 'true' ? true : false || false,
|
|
15
|
+
nodeEnv: process.env.NODE_ENV === 'true' ? true : false || false,
|
|
14
16
|
debug: process.env.SYSTEM_LOGGER_LAYER,
|
|
17
|
+
https: process.env.HTTPS,
|
|
18
|
+
httpsfileEncoding: process.env.ENCODING || 'utf8',
|
|
15
19
|
rootFolderPath: rawConfigs.rootFolderPath || 'x',
|
|
16
20
|
projectName: tmp.project.name,
|
|
17
21
|
serviceName: rawConfigs.service,
|
|
18
|
-
|
|
22
|
+
projectNamePrefixEnv: process.env.PROJECT_NAME_PREFIX || '',
|
|
23
|
+
projectNameEnv: process.env.PROJECT_NAME || '',
|
|
24
|
+
projectNameSuffixEnv: process.env.PROJECT_NAME_SUFFIX || '',
|
|
19
25
|
systemStaticFolderPath: path.resolve(rawConfigs.rootFolderPath, this.publicFolderName),
|
|
26
|
+
systemLoggerLayer: process.env.SYSTEM_LOGGER_LAYER,
|
|
20
27
|
baseApiUri: process.env.HTTPS === 'true' ? process.env.SYSTEM_HTTPS_BASE_API_URI : process.env.SYSTEM_BASE_API_URI,
|
|
28
|
+
port: process.env.PORT || rawConfigs.port || 3000,
|
|
21
29
|
internalSecret: process.env.INTERNAL_SECRET,
|
|
22
30
|
secret: process.env.SECRET,
|
|
23
31
|
cwd: process.cwd(),
|
|
@@ -45,7 +45,6 @@ export interface CustomResponse {
|
|
|
45
45
|
declare abstract class Controller {
|
|
46
46
|
protected logger: LoggerService;
|
|
47
47
|
protected supportedProtocols: ProtocolEnum[];
|
|
48
|
-
constructor();
|
|
49
48
|
protected get protocol(): ProtocolEnum;
|
|
50
49
|
protected get currentStore(): {
|
|
51
50
|
protocol?: ProtocolEnum;
|
|
@@ -7,8 +7,6 @@ export const getControllerCtx = () => controllerContextStorage.getStore();
|
|
|
7
7
|
class Controller {
|
|
8
8
|
logger = x.get(LoggerService);
|
|
9
9
|
supportedProtocols = [ProtocolEnum.HTTP, ProtocolEnum.WEBSOCKET];
|
|
10
|
-
constructor() {
|
|
11
|
-
}
|
|
12
10
|
get protocol() {
|
|
13
11
|
return this.currentStore?.protocol || ProtocolEnum.HTTP;
|
|
14
12
|
}
|
|
@@ -32,8 +30,8 @@ class Controller {
|
|
|
32
30
|
params: ctx?.params || nativeReq?.params || source?.params || {},
|
|
33
31
|
query: ctx?.query || nativeReq?.query || source?.query || {},
|
|
34
32
|
accounts: ctx?.user || nativeReq?.accounts || source?.accounts,
|
|
35
|
-
lang: ctx?.lang || nativeReq?.lang || 'en',
|
|
36
|
-
t: ctx?.t || nativeReq?.t || identityT
|
|
33
|
+
lang: ctx?.lang || nativeReq?.lang || source?.lang || 'en',
|
|
34
|
+
t: ctx?.t || nativeReq?.t || source?.t || identityT
|
|
37
35
|
};
|
|
38
36
|
}
|
|
39
37
|
get res() {
|
|
@@ -41,7 +39,7 @@ class Controller {
|
|
|
41
39
|
const self = this;
|
|
42
40
|
const fallbackRes = {
|
|
43
41
|
status: function () { return this; },
|
|
44
|
-
send: (d) => d
|
|
42
|
+
send: (d) => d,
|
|
45
43
|
json: function (d) { return this.send(d); },
|
|
46
44
|
locals: {}
|
|
47
45
|
};
|
|
@@ -101,22 +99,34 @@ export class ControllerService extends Controller {
|
|
|
101
99
|
const convertedPayload = { ...payload, query: this.parsedQuerys(req.url) };
|
|
102
100
|
if (checks) {
|
|
103
101
|
const checkResult = await checks({ payload, convertedPayload });
|
|
104
|
-
if (checkResult) {
|
|
105
|
-
return res.status(checkResult
|
|
102
|
+
if (checkResult === false || (checkResult && !Array.isArray(checkResult) && typeof checkResult === 'object')) {
|
|
103
|
+
return res.status(checkResult?.code || 400).send(new ResponseSchema({
|
|
104
|
+
status: false,
|
|
105
|
+
message: checkResult?.message || '',
|
|
106
|
+
code: checkResult?.code || 400
|
|
107
|
+
}).getResponse);
|
|
106
108
|
}
|
|
107
109
|
}
|
|
108
110
|
const logicResult = await logic({ payload, convertedPayload });
|
|
111
|
+
if (logicResult?.status === false) {
|
|
112
|
+
return res.status(logicResult.code || 400).send(new ResponseSchema({
|
|
113
|
+
status: false,
|
|
114
|
+
message: logicResult.message,
|
|
115
|
+
code: logicResult.code || 400
|
|
116
|
+
}).getResponse);
|
|
117
|
+
}
|
|
109
118
|
if (logicResult?.response instanceof Function)
|
|
110
119
|
return logicResult.response(logicResult.payload);
|
|
111
120
|
if (logicResult instanceof Response)
|
|
112
121
|
return logicResult;
|
|
113
122
|
if (response) {
|
|
114
123
|
const resResult = await response({ payload, convertedPayload, logicResult });
|
|
124
|
+
const messageData = Array.isArray(resResult) ? resResult : resResult?.message;
|
|
115
125
|
const successObj = {
|
|
116
126
|
status: true,
|
|
117
|
-
message: Array.isArray(
|
|
118
|
-
? responseMessageHelper.successFully(
|
|
119
|
-
:
|
|
127
|
+
message: Array.isArray(messageData)
|
|
128
|
+
? responseMessageHelper.successFully(messageData[0], messageData[1], req.t)
|
|
129
|
+
: (messageData || ''),
|
|
120
130
|
payload: logicResult?.payload !== undefined ? logicResult.payload : logicResult
|
|
121
131
|
};
|
|
122
132
|
return res.status(200).send(new ResponseSchema(successObj).getResponse);
|
|
@@ -128,10 +138,11 @@ export class ControllerService extends Controller {
|
|
|
128
138
|
level: LoggerLayerEnum[LoggerLayerEnum.CRITICAL].toLowerCase(),
|
|
129
139
|
message: `Controller Error: ${error}`,
|
|
130
140
|
});
|
|
131
|
-
return this.res.status(500).send({
|
|
141
|
+
return this.res.status(500).send(new ResponseSchema({
|
|
132
142
|
status: false,
|
|
133
|
-
message: error.message
|
|
134
|
-
|
|
143
|
+
message: error.message,
|
|
144
|
+
code: 500
|
|
145
|
+
}).getResponse);
|
|
135
146
|
}
|
|
136
147
|
}
|
|
137
148
|
}
|
|
@@ -94,6 +94,7 @@ export var WsActionsEnum;
|
|
|
94
94
|
(function (WsActionsEnum) {
|
|
95
95
|
WsActionsEnum["REGISTER"] = "register";
|
|
96
96
|
WsActionsEnum["JOIN"] = "join";
|
|
97
|
+
WsActionsEnum["MESSAGE"] = "message";
|
|
97
98
|
})(WsActionsEnum || (WsActionsEnum = {}));
|
|
98
99
|
export var WsKeyEnum;
|
|
99
100
|
(function (WsKeyEnum) {
|