@hapiboo/server 2.1.0 → 3.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/dist/server.js +6 -1
- package/package.json +15 -16
- package/eslint.config.mjs +0 -16
- package/package.dev.json +0 -31
- package/package.public.json +0 -30
- package/src/index.ts +0 -5
- package/src/routing.ts +0 -77
- package/src/server.ts +0 -172
- package/src/validator.ts +0 -63
- package/tsconfig.base.json +0 -18
- package/tsconfig.dev.json +0 -7
- package/tsconfig.public.json +0 -7
package/dist/server.js
CHANGED
|
@@ -182,7 +182,12 @@ var server;
|
|
|
182
182
|
verboseResponseError(reason);
|
|
183
183
|
});
|
|
184
184
|
response.status(202);
|
|
185
|
-
|
|
185
|
+
if (operation) {
|
|
186
|
+
response.send({ status: 'OK', operation });
|
|
187
|
+
}
|
|
188
|
+
else {
|
|
189
|
+
response.send({ status: 'OK' });
|
|
190
|
+
}
|
|
186
191
|
}
|
|
187
192
|
server.prepareAcceptedResponsewithVerboseOutput = prepareAcceptedResponsewithVerboseOutput;
|
|
188
193
|
function prepareFailedResponse(response, fail) {
|
package/package.json
CHANGED
|
@@ -1,30 +1,29 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@hapiboo/server",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "3.0.0",
|
|
4
4
|
"description": "MK13 Studio Hapiboo - API server services",
|
|
5
5
|
"author": "MK13 Studio",
|
|
6
6
|
"license": "ISC",
|
|
7
7
|
"main": "dist/index.js",
|
|
8
8
|
"types": "dist/index.d.ts",
|
|
9
|
+
"files": [
|
|
10
|
+
"dist"
|
|
11
|
+
],
|
|
9
12
|
"dependencies": {
|
|
10
|
-
"@hapiboo/core": "^
|
|
11
|
-
"express": "^5.1
|
|
13
|
+
"@hapiboo/core": "^3.0.1",
|
|
14
|
+
"express": "^5.2.1"
|
|
12
15
|
},
|
|
13
16
|
"devDependencies": {
|
|
14
|
-
"@types/express": "^5.0.
|
|
15
|
-
"@typescript-eslint/eslint-plugin": "^8.
|
|
16
|
-
"@typescript-eslint/parser": "^8.
|
|
17
|
-
"eslint": "^9.
|
|
18
|
-
"typescript": "5.
|
|
19
|
-
"typescript-eslint": "^8.
|
|
17
|
+
"@types/express": "^5.0.6",
|
|
18
|
+
"@typescript-eslint/eslint-plugin": "^8.51.0",
|
|
19
|
+
"@typescript-eslint/parser": "^8.51.0",
|
|
20
|
+
"eslint": "^9.39.2",
|
|
21
|
+
"typescript": "^5.9.3",
|
|
22
|
+
"typescript-eslint": "^8.51.0"
|
|
20
23
|
},
|
|
21
24
|
"scripts": {
|
|
22
|
-
"
|
|
23
|
-
"
|
|
24
|
-
"
|
|
25
|
-
"s_build": "tsc --project tsconfig.public.json",
|
|
26
|
-
"s_lint": "eslint 'src/*.ts'",
|
|
27
|
-
"s_check": "bash ../../scripts/publish.sh ./",
|
|
28
|
-
"s_publish": "pnpm s_clean && pnpm i -w=false && pnpm s_lint && pnpm s_build && pnpm s_check && pnpm s_dev"
|
|
25
|
+
"publish-check": "bash ../../scripts/publish.sh ./",
|
|
26
|
+
"ci:publish-prepare": "rm -f pnpm-lock.yaml && rm -rf node_modules dist && pnpm install --ignore-workspace --no-frozen-lockfile && eslint 'src/*.ts' && echo \"Linter OK\" && tsc && echo \"Build OK\"",
|
|
27
|
+
"ci:publish": "pnpm ci:publish-prepare && pnpm publish-check"
|
|
29
28
|
}
|
|
30
29
|
}
|
package/eslint.config.mjs
DELETED
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
import tseslint from "typescript-eslint";
|
|
2
|
-
import { defineConfig } from "eslint/config";
|
|
3
|
-
|
|
4
|
-
export default defineConfig([
|
|
5
|
-
...tseslint.configs.recommended,
|
|
6
|
-
{
|
|
7
|
-
files: ["**/*.{ts,mts,cts}"],
|
|
8
|
-
rules: {
|
|
9
|
-
"@typescript-eslint/no-namespace": "off",
|
|
10
|
-
indent: ['error', 4],
|
|
11
|
-
'linebreak-style': ['error', 'unix'],
|
|
12
|
-
quotes: ['error', 'single'],
|
|
13
|
-
semi: ['error', 'always'],
|
|
14
|
-
},
|
|
15
|
-
},
|
|
16
|
-
]);
|
package/package.dev.json
DELETED
|
@@ -1,31 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"name": "@hapiboo/server",
|
|
3
|
-
"version": "2.1.1-dev",
|
|
4
|
-
"description": "MK13 Studio Hapiboo - API server services",
|
|
5
|
-
"author": "MK13 Studio",
|
|
6
|
-
"license": "ISC",
|
|
7
|
-
"main": "dist/index.js",
|
|
8
|
-
"types": "dist/index.d.ts",
|
|
9
|
-
"scripts": {
|
|
10
|
-
"s_public": "cp package.public.json package.json",
|
|
11
|
-
"s_dev": "cp package.dev.json package.json",
|
|
12
|
-
"s_clean": "rm -f pnpm-lock.yaml && rm -rf node_modules dist",
|
|
13
|
-
"s_dependency": "cd .. && cd __core && pnpm s_build",
|
|
14
|
-
"s_build": "tsc --project tsconfig.dev.json",
|
|
15
|
-
"s_lint": "eslint 'src/*.ts'",
|
|
16
|
-
"s_lint_fix": "eslint 'src/*.ts' --fix",
|
|
17
|
-
"s_prepare": "pnpm s_clean && pnpm i && pnpm s_lint && pnpm s_build"
|
|
18
|
-
},
|
|
19
|
-
"dependencies": {
|
|
20
|
-
"@hapiboo/core": "workspace:*",
|
|
21
|
-
"express": "^5.1.0"
|
|
22
|
-
},
|
|
23
|
-
"devDependencies": {
|
|
24
|
-
"@types/express": "^5.0.3",
|
|
25
|
-
"@typescript-eslint/eslint-plugin": "^8.38.0",
|
|
26
|
-
"@typescript-eslint/parser": "^8.38.0",
|
|
27
|
-
"eslint": "^9.32.0",
|
|
28
|
-
"typescript": "5.8.3",
|
|
29
|
-
"typescript-eslint": "^8.38.0"
|
|
30
|
-
}
|
|
31
|
-
}
|
package/package.public.json
DELETED
|
@@ -1,30 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"name": "@hapiboo/server",
|
|
3
|
-
"version": "2.1.0",
|
|
4
|
-
"description": "MK13 Studio Hapiboo - API server services",
|
|
5
|
-
"author": "MK13 Studio",
|
|
6
|
-
"license": "ISC",
|
|
7
|
-
"main": "dist/index.js",
|
|
8
|
-
"types": "dist/index.d.ts",
|
|
9
|
-
"scripts": {
|
|
10
|
-
"s_public": "cp package.public.json package.json",
|
|
11
|
-
"s_dev": "cp package.dev.json package.json",
|
|
12
|
-
"s_clean": "rm -f pnpm-lock.yaml && rm -rf node_modules dist",
|
|
13
|
-
"s_build": "tsc --project tsconfig.public.json",
|
|
14
|
-
"s_lint": "eslint 'src/*.ts'",
|
|
15
|
-
"s_check": "bash ../../scripts/publish.sh ./",
|
|
16
|
-
"s_publish": "pnpm s_clean && pnpm i -w=false && pnpm s_lint && pnpm s_build && pnpm s_check && pnpm s_dev"
|
|
17
|
-
},
|
|
18
|
-
"dependencies": {
|
|
19
|
-
"@hapiboo/core": "^2.0.0",
|
|
20
|
-
"express": "^5.1.0"
|
|
21
|
-
},
|
|
22
|
-
"devDependencies": {
|
|
23
|
-
"@types/express": "^5.0.3",
|
|
24
|
-
"@typescript-eslint/eslint-plugin": "^8.38.0",
|
|
25
|
-
"@typescript-eslint/parser": "^8.38.0",
|
|
26
|
-
"eslint": "^9.32.0",
|
|
27
|
-
"typescript": "5.8.3",
|
|
28
|
-
"typescript-eslint": "^8.38.0"
|
|
29
|
-
}
|
|
30
|
-
}
|
package/src/index.ts
DELETED
package/src/routing.ts
DELETED
|
@@ -1,77 +0,0 @@
|
|
|
1
|
-
import { Application, Router, IRouter } from 'express';
|
|
2
|
-
|
|
3
|
-
interface IRouteDetails{
|
|
4
|
-
method: string;
|
|
5
|
-
url: string;
|
|
6
|
-
}
|
|
7
|
-
|
|
8
|
-
function parseItem(path: string, item: IRoutingItem): IRouteDetails[]{
|
|
9
|
-
if (item.children.length === 0) {
|
|
10
|
-
return parseRouter(`${path}${item.mount ?? ''}`, item.router);
|
|
11
|
-
} else {
|
|
12
|
-
const ret: IRouteDetails[] = [];
|
|
13
|
-
item.children.forEach((child) => {
|
|
14
|
-
ret.push(...parseItem(`${path}${item.mount ?? ''}`, child));
|
|
15
|
-
});
|
|
16
|
-
|
|
17
|
-
return ret;
|
|
18
|
-
}
|
|
19
|
-
}
|
|
20
|
-
function parseRouter(path: string, item: IRouter): IRouteDetails[]{
|
|
21
|
-
const ret: IRouteDetails[] = [];
|
|
22
|
-
item.stack.forEach((layer) => {
|
|
23
|
-
if (layer.route && layer.name === 'handle') {
|
|
24
|
-
layer.route.stack.forEach((details) => {
|
|
25
|
-
if (details.name === '<anonymous>'){
|
|
26
|
-
ret.push({ method: details.method, url: `${path}${layer.route?.path }` });
|
|
27
|
-
}
|
|
28
|
-
});
|
|
29
|
-
}
|
|
30
|
-
});
|
|
31
|
-
|
|
32
|
-
return ret;
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
export interface IRoutingItem{
|
|
36
|
-
mount: string | undefined;
|
|
37
|
-
children: IRoutingItem[];
|
|
38
|
-
router: Router;
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
export namespace routingProvider{
|
|
42
|
-
export function printMap(routes: IRoutingItem[]){
|
|
43
|
-
console.info('Method Routes:');
|
|
44
|
-
console.info('------------------');
|
|
45
|
-
|
|
46
|
-
routes.forEach((route) => {
|
|
47
|
-
parseItem('', route).forEach((detail) => {
|
|
48
|
-
console.info(`${detail.method.toUpperCase().padEnd(10)} ${detail.url}`);
|
|
49
|
-
});
|
|
50
|
-
});
|
|
51
|
-
}
|
|
52
|
-
export function createRoutingItem(mount: string | undefined, router: Router): IRoutingItem{
|
|
53
|
-
return { mount: mount, children: [], router: router };
|
|
54
|
-
}
|
|
55
|
-
export function createRouter(mount: string | undefined, routes: IRoutingItem[]): IRoutingItem{
|
|
56
|
-
const router = Router({ mergeParams: true });
|
|
57
|
-
|
|
58
|
-
routes.forEach((item) => {
|
|
59
|
-
if (item.mount && item.mount !== ''){
|
|
60
|
-
router.use(item.mount, item.router);
|
|
61
|
-
} else {
|
|
62
|
-
router.use(item.router);
|
|
63
|
-
}
|
|
64
|
-
});
|
|
65
|
-
|
|
66
|
-
return { mount: mount, children: routes, router: router };
|
|
67
|
-
}
|
|
68
|
-
export function processApp(expressApp: Application, routers: IRoutingItem[]){
|
|
69
|
-
routers.forEach((item) => {
|
|
70
|
-
if (item.mount && item.mount !== ''){
|
|
71
|
-
expressApp.use(item.mount, item.router);
|
|
72
|
-
} else {
|
|
73
|
-
expressApp.use(item.router);
|
|
74
|
-
}
|
|
75
|
-
});
|
|
76
|
-
}
|
|
77
|
-
}
|
package/src/server.ts
DELETED
|
@@ -1,172 +0,0 @@
|
|
|
1
|
-
import { Response, Request } from 'express';
|
|
2
|
-
import { promise, ResponseError, IResponsePromise, IResponsePromiseVoid } from '@hapiboo/core';
|
|
3
|
-
|
|
4
|
-
function prepareResponse(response: Response, responseSender?: () => void, err?: ResponseError, non200Status?: number) {
|
|
5
|
-
if (err) {
|
|
6
|
-
response.status(err.status);
|
|
7
|
-
if (err.code) {
|
|
8
|
-
if (err.error) {
|
|
9
|
-
response.json({ code: err.code, error: err.message, original: err.error.name, stack: err.error.stack });
|
|
10
|
-
} else {
|
|
11
|
-
response.json({ code: err.code, error: err.message});
|
|
12
|
-
}
|
|
13
|
-
} else {
|
|
14
|
-
if (err.error) {
|
|
15
|
-
response.json({ error: err.message, original: err.error.name, stack: err.error.stack });
|
|
16
|
-
} else {
|
|
17
|
-
response.json({ error: err.message});
|
|
18
|
-
}
|
|
19
|
-
}
|
|
20
|
-
} else {
|
|
21
|
-
if (responseSender) {
|
|
22
|
-
response.status(non200Status ?? 200);
|
|
23
|
-
responseSender();
|
|
24
|
-
} else {
|
|
25
|
-
response.status(non200Status ?? 204);
|
|
26
|
-
response.send();
|
|
27
|
-
}
|
|
28
|
-
}
|
|
29
|
-
}
|
|
30
|
-
function verboseResponseError(reason: ResponseError){
|
|
31
|
-
if (reason.code) {
|
|
32
|
-
console.error(`${reason.status}: [${reason.code}] ${reason.message}`);
|
|
33
|
-
} else {
|
|
34
|
-
console.error(`${reason.status}: ${reason.message}`);
|
|
35
|
-
}
|
|
36
|
-
if (reason.error) {
|
|
37
|
-
console.error(`${reason.error.name}: ${reason.error.message}`);
|
|
38
|
-
console.error(`stack: ${reason.error.stack}`);
|
|
39
|
-
}
|
|
40
|
-
if (reason.dataError) {
|
|
41
|
-
console.error(`[${reason.dataError.collection}] - ${reason.dataError.operation}:${reason.dataError.id}`);
|
|
42
|
-
}
|
|
43
|
-
if (reason.collection){
|
|
44
|
-
reason.collection.forEach((error) => {
|
|
45
|
-
verboseResponseError(error);
|
|
46
|
-
});
|
|
47
|
-
}
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
export namespace server {
|
|
51
|
-
export function prepareJsonResponse<T>(response: Response, data: T, err?: ResponseError, non200Status?: number) {
|
|
52
|
-
prepareResponse(response, () => {
|
|
53
|
-
response.json(data);
|
|
54
|
-
}, err, non200Status);
|
|
55
|
-
}
|
|
56
|
-
export function prepareStringResponse(response: Response, data: string, err?: ResponseError) {
|
|
57
|
-
prepareResponse(response, () => {
|
|
58
|
-
response.send(data);
|
|
59
|
-
}, err);
|
|
60
|
-
}
|
|
61
|
-
export function prepareBinaryResponse(response: Response, data: Buffer, err?: ResponseError) {
|
|
62
|
-
prepareResponse(response, () => {
|
|
63
|
-
response.send(data);
|
|
64
|
-
}, err);
|
|
65
|
-
}
|
|
66
|
-
export function prepareMimeResponse(response: Response, data: Buffer, mime: string, err?: ResponseError, non200Status?: number) {
|
|
67
|
-
prepareResponse(response, () => {
|
|
68
|
-
if (mime != undefined && data != undefined) {
|
|
69
|
-
response.contentType(mime);
|
|
70
|
-
response.send(data);
|
|
71
|
-
} else {
|
|
72
|
-
response.json({});
|
|
73
|
-
}
|
|
74
|
-
}, err, non200Status);
|
|
75
|
-
}
|
|
76
|
-
|
|
77
|
-
export function prepareJsonPromiseResponse<T>(response: Response, promise: IResponsePromise<T>, non200Status?: number) {
|
|
78
|
-
promise
|
|
79
|
-
.then((data) => {
|
|
80
|
-
prepareResponse(response, () => {
|
|
81
|
-
response.json(data);
|
|
82
|
-
}, undefined, non200Status);
|
|
83
|
-
})
|
|
84
|
-
.catch((error) => {
|
|
85
|
-
prepareResponse(response, undefined, error, non200Status);
|
|
86
|
-
});
|
|
87
|
-
}
|
|
88
|
-
export function prepareStringPromiseResponse(response: Response, promise: IResponsePromise<string>, non200Status?: number) {
|
|
89
|
-
promise
|
|
90
|
-
.then((value) => {
|
|
91
|
-
prepareStringResponse(response, value);
|
|
92
|
-
})
|
|
93
|
-
.catch((error) => {
|
|
94
|
-
prepareResponse(response, undefined, error, non200Status);
|
|
95
|
-
});
|
|
96
|
-
}
|
|
97
|
-
export function prepareEmptyPromiseResponse(response: Response, promise: IResponsePromiseVoid, non200Status?: number) {
|
|
98
|
-
promise
|
|
99
|
-
.then(() => {
|
|
100
|
-
prepareResponse(response, undefined, undefined, non200Status);
|
|
101
|
-
})
|
|
102
|
-
.catch((error) => {
|
|
103
|
-
prepareResponse(response, undefined, error, non200Status);
|
|
104
|
-
});
|
|
105
|
-
}
|
|
106
|
-
export function prepareMimePromiseResponse(response: Response, mime: string, promise: IResponsePromise<Buffer>, non200Status?: number) {
|
|
107
|
-
promise
|
|
108
|
-
.then((data) => {
|
|
109
|
-
prepareMimeResponse(response, data, mime, undefined, non200Status);
|
|
110
|
-
})
|
|
111
|
-
.catch((error) => {
|
|
112
|
-
prepareResponse(response, undefined, error, non200Status);
|
|
113
|
-
});
|
|
114
|
-
}
|
|
115
|
-
export function prepareMimeBinaryPromiseResponse(response: Response, promise: IResponsePromise<{mime: string, binary: Buffer}>, non200Status?: number) {
|
|
116
|
-
promise
|
|
117
|
-
.then((data) => {
|
|
118
|
-
prepareMimeResponse(response, data.binary, data.mime, undefined, non200Status);
|
|
119
|
-
})
|
|
120
|
-
.catch((error) => {
|
|
121
|
-
prepareResponse(response, undefined, error, non200Status);
|
|
122
|
-
});
|
|
123
|
-
}
|
|
124
|
-
export function prepareCustomPromiseResponse<T>(response: Response, promise: IResponsePromiseVoid, successContent: T, non200Status?: number) {
|
|
125
|
-
promise
|
|
126
|
-
.then(() => {
|
|
127
|
-
prepareResponse(response, () => { response.send(successContent); }, undefined, non200Status);
|
|
128
|
-
})
|
|
129
|
-
.catch((error) => {
|
|
130
|
-
prepareResponse(response, undefined, error, non200Status);
|
|
131
|
-
});
|
|
132
|
-
}
|
|
133
|
-
|
|
134
|
-
export function createValidatedPromise<T>(request: Request, validator: (request: Request) => boolean, delayedPromise: IResponsePromise<T>): IResponsePromise<T> {
|
|
135
|
-
if (validator(request)) {
|
|
136
|
-
return delayedPromise.start();
|
|
137
|
-
} else {
|
|
138
|
-
return promise.createFailedPromise(ResponseError.getMessageResponse(400, 'malformed request'));
|
|
139
|
-
}
|
|
140
|
-
}
|
|
141
|
-
export function createValidatedVoidPromise(request: Request, validator: (request: Request) => boolean, delayedPromise: IResponsePromiseVoid): IResponsePromiseVoid {
|
|
142
|
-
if (validator(request)) {
|
|
143
|
-
return delayedPromise.start();
|
|
144
|
-
} else {
|
|
145
|
-
return promise.createFailedVoidPromise(ResponseError.getMessageResponse(400, 'malformed request'));
|
|
146
|
-
}
|
|
147
|
-
}
|
|
148
|
-
|
|
149
|
-
export function prepareAcceptedResponsewithVerboseOutput(response: Response, promise: IResponsePromiseVoid, operation: string | undefined){
|
|
150
|
-
promise
|
|
151
|
-
.then(() => {
|
|
152
|
-
if (operation) {
|
|
153
|
-
console.info(`${operation} completed succesfully`);
|
|
154
|
-
}
|
|
155
|
-
})
|
|
156
|
-
.catch((reason) => {
|
|
157
|
-
if (operation) {
|
|
158
|
-
console.info(`${operation} completed with problem:`);
|
|
159
|
-
} else {
|
|
160
|
-
console.info('Operation completed with problem:');
|
|
161
|
-
}
|
|
162
|
-
verboseResponseError(reason);
|
|
163
|
-
});
|
|
164
|
-
|
|
165
|
-
response.status(202);
|
|
166
|
-
response.send();
|
|
167
|
-
}
|
|
168
|
-
|
|
169
|
-
export function prepareFailedResponse(response: Response, fail: ResponseError){
|
|
170
|
-
prepareResponse(response, undefined, fail, undefined);
|
|
171
|
-
}
|
|
172
|
-
}
|
package/src/validator.ts
DELETED
|
@@ -1,63 +0,0 @@
|
|
|
1
|
-
import { Request } from 'express';
|
|
2
|
-
import { promise, ResponseError, IResponsePromise, IResponsePromiseVoid } from '@hapiboo/core';
|
|
3
|
-
|
|
4
|
-
export namespace validator {
|
|
5
|
-
|
|
6
|
-
export function createValidatedPromise<T>(validator: () => boolean, delayedPromise: IResponsePromise<T>): IResponsePromise<T> {
|
|
7
|
-
if (validator()) {
|
|
8
|
-
return delayedPromise.start();
|
|
9
|
-
} else {
|
|
10
|
-
return promise.createFailedPromise(ResponseError.getMessageResponse(400, 'malformed request'));
|
|
11
|
-
}
|
|
12
|
-
}
|
|
13
|
-
export function createValidatedVoidPromise(validator: () => boolean, delayedPromise: IResponsePromiseVoid): IResponsePromiseVoid {
|
|
14
|
-
if (validator()) {
|
|
15
|
-
return delayedPromise.start();
|
|
16
|
-
} else {
|
|
17
|
-
return promise.createFailedVoidPromise(ResponseError.getMessageResponse(400, 'malformed request'));
|
|
18
|
-
}
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
export function validateString(toValidate: string | undefined): boolean {
|
|
22
|
-
return toValidate !== undefined && toValidate !== '';
|
|
23
|
-
}
|
|
24
|
-
export function validatePattern(toValidate: string, pattern: string[]): boolean {
|
|
25
|
-
return validateString(toValidate) &&
|
|
26
|
-
pattern.some((val) => {
|
|
27
|
-
return val == toValidate;
|
|
28
|
-
});
|
|
29
|
-
}
|
|
30
|
-
export function validateStringArray(toValidate: string[]): boolean {
|
|
31
|
-
return toValidate != undefined;
|
|
32
|
-
}
|
|
33
|
-
export function validateNotEmptyStringArray(toValidate: string[]): boolean {
|
|
34
|
-
return toValidate != undefined && toValidate.length > 0 && toValidate.every((item) => { return validateString(item); });
|
|
35
|
-
}
|
|
36
|
-
export function validateInteger(toValidate: number): boolean {
|
|
37
|
-
return toValidate != undefined && (Math.floor(toValidate) == toValidate);
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
export function validateBody(request: Request): boolean{
|
|
41
|
-
return request.body !== undefined;
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
export function validateHeader(request: Request, headerKey: string): { isValid: boolean, value: string }{
|
|
45
|
-
const headerValue = request.headers[headerKey.toLowerCase()];
|
|
46
|
-
|
|
47
|
-
if (headerValue && typeof(headerValue) === 'string' && headerValue.trim() !== '') {
|
|
48
|
-
return { isValid: true, value: headerValue };
|
|
49
|
-
} else {
|
|
50
|
-
return { isValid: false, value: '' };
|
|
51
|
-
}
|
|
52
|
-
}
|
|
53
|
-
|
|
54
|
-
export function validateQuery(request: Request, queryKey: string): { isValid: boolean, value: string }{
|
|
55
|
-
const queryValue = request.query[queryKey];
|
|
56
|
-
|
|
57
|
-
if (queryValue && typeof(queryValue) === 'string' && queryValue.trim() !== '') {
|
|
58
|
-
return { isValid: true, value: queryValue };
|
|
59
|
-
} else {
|
|
60
|
-
return { isValid: false, value: '' };
|
|
61
|
-
}
|
|
62
|
-
}
|
|
63
|
-
}
|
package/tsconfig.base.json
DELETED
|
@@ -1,18 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"compilerOptions": {
|
|
3
|
-
"target": "ES2020",
|
|
4
|
-
"module": "commonjs",
|
|
5
|
-
"lib": ["ES2020"],
|
|
6
|
-
"outDir": "./dist",
|
|
7
|
-
"rootDir": "./src",
|
|
8
|
-
"strict": true,
|
|
9
|
-
"esModuleInterop": true,
|
|
10
|
-
"skipLibCheck": true,
|
|
11
|
-
"forceConsistentCasingInFileNames": true,
|
|
12
|
-
"moduleResolution": "node",
|
|
13
|
-
"resolveJsonModule": true,
|
|
14
|
-
"declaration": true,
|
|
15
|
-
},
|
|
16
|
-
"include": ["src/**/*"],
|
|
17
|
-
"exclude": ["node_modules", "dist"]
|
|
18
|
-
}
|
package/tsconfig.dev.json
DELETED