response-standardizer 1.3.4 → 1.3.6
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.js +5 -0
- package/dist/types.d.ts +1 -0
- package/package.json +1 -1
- package/src/index.ts +5 -0
- package/src/types.ts +1 -0
package/dist/index.js
CHANGED
|
@@ -14,6 +14,7 @@ const initKeycloak = async (config) => {
|
|
|
14
14
|
const realmUrl = `http://${KEYCLOAK_SERVICE}/realms/${KEYCLOAK_REALM}`;
|
|
15
15
|
(0, exports.info)(`Keycloak PublicKey Url: ${realmUrl}`);
|
|
16
16
|
const resp = await axios_1.default.get(realmUrl);
|
|
17
|
+
(0, exports.info)(`Keycloak: ${resp.data}`);
|
|
17
18
|
const key = resp.data.public_key;
|
|
18
19
|
KEYCLOAK_PUBLIC_KEY = `-----BEGIN PUBLIC KEY-----\n${key.match(/.{1,64}/g)?.join("\n")}\n-----END PUBLIC KEY-----`;
|
|
19
20
|
};
|
|
@@ -70,6 +71,9 @@ const created = (req, res, data) => {
|
|
|
70
71
|
const deleted = (req, res) => {
|
|
71
72
|
res.status(204).send();
|
|
72
73
|
};
|
|
74
|
+
const noContent = (req, res) => {
|
|
75
|
+
res.status(204).send();
|
|
76
|
+
};
|
|
73
77
|
const validationError = (req, res, errors, message = "Validation error") => {
|
|
74
78
|
res.status(400).json({ errors, message });
|
|
75
79
|
};
|
|
@@ -93,6 +97,7 @@ exports.RestResponse = {
|
|
|
93
97
|
paginate,
|
|
94
98
|
created,
|
|
95
99
|
deleted,
|
|
100
|
+
noContent,
|
|
96
101
|
validationError,
|
|
97
102
|
exceptionError,
|
|
98
103
|
unauthorized,
|
package/dist/types.d.ts
CHANGED
|
@@ -28,6 +28,7 @@ export interface RestResponseFunctions {
|
|
|
28
28
|
paginate: <T>(req: Request, res: Response, data: Pagination<T>) => void;
|
|
29
29
|
created: <T>(req: Request, res: Response, data: T) => void;
|
|
30
30
|
deleted: (req: Request, res: Response) => void;
|
|
31
|
+
noContent: (req: Request, res: Response) => void;
|
|
31
32
|
validationError: (req: Request, res: Response, errors?: ErrorFields, message?: string) => void;
|
|
32
33
|
exceptionError: (req: Request, res: Response, errors: any, message?: string) => void;
|
|
33
34
|
unauthorized: (req: Request, res: Response, message?: string) => void;
|
package/package.json
CHANGED
package/src/index.ts
CHANGED
|
@@ -24,6 +24,7 @@ export const initKeycloak = async (config: { service?: string; realm?: string })
|
|
|
24
24
|
const realmUrl = `http://${KEYCLOAK_SERVICE}/realms/${KEYCLOAK_REALM}`;
|
|
25
25
|
info(`Keycloak PublicKey Url: ${realmUrl}`);
|
|
26
26
|
const resp = await axios.get(realmUrl);
|
|
27
|
+
info(`Keycloak: ${resp.data}`);
|
|
27
28
|
const key = resp.data.public_key;
|
|
28
29
|
KEYCLOAK_PUBLIC_KEY = `-----BEGIN PUBLIC KEY-----\n${key.match(/.{1,64}/g)?.join("\n")}\n-----END PUBLIC KEY-----`;
|
|
29
30
|
};
|
|
@@ -91,6 +92,9 @@ const created = <T>(req: Request, res: Response, data: T) => {
|
|
|
91
92
|
const deleted = (req: Request, res: Response) => {
|
|
92
93
|
res.status(204).send();
|
|
93
94
|
};
|
|
95
|
+
const noContent = (req: Request, res: Response) => {
|
|
96
|
+
res.status(204).send();
|
|
97
|
+
};
|
|
94
98
|
|
|
95
99
|
const validationError = (
|
|
96
100
|
req: Request,
|
|
@@ -130,6 +134,7 @@ export const RestResponse: RestResponseFunctions = {
|
|
|
130
134
|
paginate,
|
|
131
135
|
created,
|
|
132
136
|
deleted,
|
|
137
|
+
noContent,
|
|
133
138
|
validationError,
|
|
134
139
|
exceptionError,
|
|
135
140
|
unauthorized,
|
package/src/types.ts
CHANGED
|
@@ -37,6 +37,7 @@ export interface RestResponseFunctions {
|
|
|
37
37
|
) => void;
|
|
38
38
|
created: <T>(req: Request, res: Response, data: T) => void;
|
|
39
39
|
deleted: (req: Request, res: Response) => void;
|
|
40
|
+
noContent: (req: Request, res: Response) => void;
|
|
40
41
|
validationError: (
|
|
41
42
|
req: Request,
|
|
42
43
|
res: Response,
|