very-express 0.5.13 → 0.5.14
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 +214 -110
- package/dist/templates/_middlewares/Authentication.ts +8 -6
- package/dist/templates/_routes/oauth/OAuthRouteFactory.ts +7 -42
- package/dist/templates/_services/VexDbConnector.ts +8 -8
- package/dist/templates/_services/VexSystem.ts +5 -6
- package/dist/templates/_services/auth/JWTService.ts +168 -0
- package/dist/templates/_services/oauth/OAuthProfileMap.ts +69 -0
- package/dist/templates/_services/oauth/OAuthStrategyService.ts +92 -0
- package/dist/templates/_types/VexResponseError.ts +20 -0
- package/dist/templates/_types/responseObject.ts +7 -0
- package/dist/templates/_utils/hash.ts +47 -0
- package/dist/templates/_utils/index.ts +5 -3
- package/dist/templates/_utils/response.ts +102 -32
- package/dist/templates/jsonSchema/User.json +3 -0
- package/package.json +1 -1
- package/vex.config.json +3 -2
- package/dist/templates/_plugins/auth/jwt.ts +0 -85
- package/dist/templates/_plugins/auth/oauthVerify.ts +0 -86
- package/dist/templates/_plugins/auth/profileMapping.ts +0 -68
- package/dist/templates/_plugins/auth/token.ts +0 -29
- package/dist/templates/_types/response/index.ts +0 -10
- package/dist/templates/_types/response/responseCode.ts +0 -15
- package/dist/templates/_types/response/responseMsg.ts +0 -28
- package/dist/templates/_types/response/responseStatusCodeMap.ts +0 -70
- /package/dist/templates/{_plugins → _services}/auth/JWTKeyStore.ts +0 -0
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
import { Response } from "express";
|
|
2
|
-
import { responseMsg, responseCode, responseStatusCodeMap, type ResponseCode } from "./../_types/response/index.gen";
|
|
3
2
|
|
|
4
3
|
/**
|
|
5
4
|
* @param res express response object
|
|
@@ -11,21 +10,21 @@ import { responseMsg, responseCode, responseStatusCodeMap, type ResponseCode } f
|
|
|
11
10
|
*/
|
|
12
11
|
export function send<T = undefined>(
|
|
13
12
|
res: Response,
|
|
14
|
-
status: number = 200,
|
|
15
|
-
body?:{
|
|
13
|
+
status: number = 200,
|
|
14
|
+
body?: {
|
|
16
15
|
code?: ResponseCode,
|
|
17
|
-
message?: string|null,
|
|
16
|
+
message?: string | null,
|
|
18
17
|
result?: T,
|
|
19
18
|
}
|
|
20
19
|
): Response<any, Record<string, any>> {
|
|
21
20
|
const noBody = !body || (body.code === undefined && body.message === undefined && body.result === undefined);
|
|
22
21
|
|
|
23
|
-
if(noBody){
|
|
22
|
+
if (noBody) {
|
|
24
23
|
return res.status(status).send();
|
|
25
24
|
}
|
|
26
|
-
else{
|
|
27
|
-
const code
|
|
28
|
-
const msg
|
|
25
|
+
else {
|
|
26
|
+
const code: ResponseCode | undefined = body?.code ?? responseStatusCodeMap.get(status) as ResponseCode | undefined;
|
|
27
|
+
const msg: string | undefined = body?.message ?? (code ? responseMessage[code] : undefined);
|
|
29
28
|
|
|
30
29
|
return res.status(status)
|
|
31
30
|
.header({
|
|
@@ -40,34 +39,105 @@ export function send<T = undefined>(
|
|
|
40
39
|
}
|
|
41
40
|
}
|
|
42
41
|
|
|
43
|
-
|
|
44
|
-
ret_code : number,
|
|
45
|
-
ret_msg : string,
|
|
46
|
-
ret_time?: number,
|
|
47
|
-
result: T,
|
|
48
|
-
}
|
|
42
|
+
const responseMessage = {
|
|
49
43
|
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
public ret_code: ResponseCode;
|
|
53
|
-
public ret_msg: any;
|
|
44
|
+
DB_CONN_ERR: "Database connection error",
|
|
45
|
+
SERVER_ERROR: "Unknown Server Error",
|
|
54
46
|
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
47
|
+
success: "Success",
|
|
48
|
+
|
|
49
|
+
err_db_data: "Corrupted Database Record",
|
|
50
|
+
|
|
51
|
+
err_permission: "Permission Denied",
|
|
52
|
+
|
|
53
|
+
err_payload: "Invalid Request Payload",
|
|
54
|
+
err_query: "Invalid Request Query",
|
|
55
|
+
err_body: "Invalid Request Body",
|
|
56
|
+
|
|
57
|
+
err_validation: "Validation Error",
|
|
58
|
+
err_query_validation: "Query Validation Error",
|
|
59
|
+
err_body_validation: "Body Validation Error",
|
|
60
|
+
|
|
61
|
+
err_create: "Falied to Insert Data",
|
|
62
|
+
err_read: "Falied to Read Data",
|
|
63
|
+
err_update: "Falied to Edit Data",
|
|
64
|
+
err_delete: "Falied to Delete Data",
|
|
65
|
+
};
|
|
66
|
+
|
|
67
|
+
const responseCode = Object.keys(responseMessage).reduce((acc, key) => {
|
|
68
|
+
acc[key] = key as ResponseCode;
|
|
69
|
+
return acc;
|
|
70
|
+
}, {} as Record<string, ResponseCode>);
|
|
71
|
+
|
|
72
|
+
const responseStatusCodeMap = new Map<number, string>([
|
|
73
|
+
[100, "Continue"],
|
|
74
|
+
[101, "Switching Protocols"],
|
|
75
|
+
[102, "Processing"],
|
|
76
|
+
[103, "Early Hints"],
|
|
77
|
+
[200, responseCode.success],
|
|
78
|
+
[201, responseCode.success],
|
|
79
|
+
[202, responseCode.success],
|
|
80
|
+
[203, "Non-Authoritative Information"],
|
|
81
|
+
[204, "No Content"],
|
|
82
|
+
[205, "Reset Content"],
|
|
83
|
+
[206, "Partial Content"],
|
|
84
|
+
[207, "Multi-Status"],
|
|
85
|
+
[208, "Already Reported"],
|
|
86
|
+
[226, "IM Used"],
|
|
87
|
+
[300, "Multiple Choices"],
|
|
88
|
+
[301, "Moved Permanently"],
|
|
89
|
+
[302, "Found"],
|
|
90
|
+
[303, "See Other"],
|
|
91
|
+
[304, "Not Modified"],
|
|
92
|
+
[307, "Temporary Redirect"],
|
|
93
|
+
[308, "Permanent Redirect"],
|
|
94
|
+
[400, responseCode.err_payload],
|
|
95
|
+
[401, responseCode.err_permission],
|
|
96
|
+
[402, "Payment Required"],
|
|
97
|
+
[403, "Forbidden"],
|
|
98
|
+
[404, "Not Found"],
|
|
99
|
+
[405, "Method Not Allowed"],
|
|
100
|
+
[406, "Not Acceptable"],
|
|
101
|
+
[407, "Proxy Authentication Required"],
|
|
102
|
+
[408, "Request Timeout"],
|
|
103
|
+
[409, "Conflict"],
|
|
104
|
+
[410, "Gone"],
|
|
105
|
+
[411, "Length Required"],
|
|
106
|
+
[412, "Precondition Failed"],
|
|
107
|
+
[413, "Content Too Large"],
|
|
108
|
+
[414, "URI Too Long"],
|
|
109
|
+
[415, "Unsupported Media Type"],
|
|
110
|
+
[416, "Range Not Satisfiable"],
|
|
111
|
+
[417, "Expectation Failed"],
|
|
112
|
+
[418, "I'm a teapot"],
|
|
113
|
+
[421, "Misdirected Request"],
|
|
114
|
+
[422, "Unprocessable Content"],
|
|
115
|
+
[423, "Locked"],
|
|
116
|
+
[424, "Failed Dependency"],
|
|
117
|
+
[425, "Too Early"],
|
|
118
|
+
[426, "Upgrade Required"],
|
|
119
|
+
[428, "Precondition Required"],
|
|
120
|
+
[429, "Too Many Requests"],
|
|
121
|
+
[431, "Request Header Fields Too Large"],
|
|
122
|
+
[451, "Unavailable For Legal Reasons"],
|
|
123
|
+
[500, "Internal Server Error"],
|
|
124
|
+
[501, "Not Implemented"],
|
|
125
|
+
[502, "Bad Gateway"],
|
|
126
|
+
[503, "Service Unavailable"],
|
|
127
|
+
[504, "Gateway Timeout"],
|
|
128
|
+
[505, "HTTP Version Not Supported"],
|
|
129
|
+
[506, "Variant Also Negotiates"],
|
|
130
|
+
[507, "Insufficient Storage"],
|
|
131
|
+
[508, "Loop Detected"],
|
|
132
|
+
[510, "Not Extended"],
|
|
133
|
+
[511, "Network Authentication Required"],
|
|
134
|
+
]);
|
|
135
|
+
|
|
136
|
+
export type ResponseCode = keyof typeof responseMessage;
|
|
67
137
|
|
|
68
138
|
export default {
|
|
69
139
|
send,
|
|
70
|
-
msg:
|
|
71
|
-
code: responseCode,
|
|
140
|
+
msg: responseMessage,
|
|
141
|
+
code: responseCode,
|
|
72
142
|
statusCodeMap: responseStatusCodeMap,
|
|
73
143
|
};
|
package/package.json
CHANGED
package/vex.config.json
CHANGED
|
@@ -9,9 +9,10 @@
|
|
|
9
9
|
"useUserSchema": true,
|
|
10
10
|
"useObjectID": true,
|
|
11
11
|
"allowApiCreateUpdate_id": false,
|
|
12
|
-
"useStatefulRedisAuth":
|
|
12
|
+
"useStatefulRedisAuth": false
|
|
13
13
|
},
|
|
14
|
-
"
|
|
14
|
+
"auth": {
|
|
15
|
+
"localAuth": true,
|
|
15
16
|
"useHttpOnlyCookieToken": true,
|
|
16
17
|
"oauthProviders": {
|
|
17
18
|
"google": true,
|
|
@@ -1,85 +0,0 @@
|
|
|
1
|
-
// {{headerComment}}
|
|
2
|
-
import jwt from "jsonwebtoken";
|
|
3
|
-
import ms from "ms";
|
|
4
|
-
import JWTKeyStore from "./JWTKeyStore.gen";
|
|
5
|
-
import responseCode from "../../_types/response/responseCode.gen";
|
|
6
|
-
import { UserModel } from "../../_models/UserModel.gen";
|
|
7
|
-
import { sanitizeUser } from "../../_plugins/auth/token.gen";
|
|
8
|
-
import { VexResponseError } from "../../_utils/response.gen";
|
|
9
|
-
|
|
10
|
-
interface tokenObj {
|
|
11
|
-
token: string,
|
|
12
|
-
index?: number,
|
|
13
|
-
clientIndex?: string
|
|
14
|
-
}
|
|
15
|
-
|
|
16
|
-
const keys = new JWTKeyStore();
|
|
17
|
-
|
|
18
|
-
export function generateToken(
|
|
19
|
-
data: any,
|
|
20
|
-
index?: number,
|
|
21
|
-
expiresIn?: string
|
|
22
|
-
): tokenObj {
|
|
23
|
-
data = JSON.parse(JSON.stringify(data));
|
|
24
|
-
const keyInfo = typeof index == "number" ? keys.getSecretObj(index) : keys.getRandomKey();
|
|
25
|
-
const token = jwt.sign(
|
|
26
|
-
data,
|
|
27
|
-
keyInfo.key as jwt.Secret,
|
|
28
|
-
{
|
|
29
|
-
expiresIn: (expiresIn || keys.expireTime || "1h") as ms.StringValue,
|
|
30
|
-
algorithm: keys.algorithm
|
|
31
|
-
}
|
|
32
|
-
);
|
|
33
|
-
|
|
34
|
-
return {
|
|
35
|
-
token: token,
|
|
36
|
-
index: keyInfo.index,
|
|
37
|
-
clientIndex: keyInfo.clientIndex
|
|
38
|
-
};
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
export async function generateAccessToken(userId: string, index?: number): Promise<tokenObj> {
|
|
42
|
-
|
|
43
|
-
const userDoc = await UserModel.findById(userId).exec();
|
|
44
|
-
if (!userDoc) {
|
|
45
|
-
throw new VexResponseError(404, responseCode.err_payload, "Invalid User Id");
|
|
46
|
-
}
|
|
47
|
-
const userInfo = sanitizeUser(userDoc);
|
|
48
|
-
|
|
49
|
-
return generateToken(userInfo, index, process.env.ACCESS_TOKEN_EXPIRE_TIME);
|
|
50
|
-
}
|
|
51
|
-
|
|
52
|
-
export function generateRefreshToken(data: any, index?: number): tokenObj {
|
|
53
|
-
return generateToken(data, index, process.env.REFRESH_TOKEN_EXPIRE_TIME);
|
|
54
|
-
}
|
|
55
|
-
|
|
56
|
-
/**
|
|
57
|
-
* Verifies a JSON Web Token (JWT) using the provided token and key index.
|
|
58
|
-
*
|
|
59
|
-
* @param {string} token - The JSON Web Token to be verified.
|
|
60
|
-
* @param {number} index - The index of the key used to verify the token.
|
|
61
|
-
* @return {jwt.JwtPayload } The decoded token payload, an error message, or false if verification fails.
|
|
62
|
-
*/
|
|
63
|
-
export function verifyToken(token: string, index?: number|string): jwt.JwtPayload {
|
|
64
|
-
|
|
65
|
-
if(token.startsWith("Bearer ")) {
|
|
66
|
-
token = token.split("Bearer ")[1];
|
|
67
|
-
}
|
|
68
|
-
|
|
69
|
-
const key = keys.getSecret(index || 0);
|
|
70
|
-
|
|
71
|
-
try{
|
|
72
|
-
return jwt.verify(token, key) as jwt.JwtPayload;
|
|
73
|
-
}
|
|
74
|
-
catch (error){
|
|
75
|
-
if(error instanceof jwt.TokenExpiredError) {
|
|
76
|
-
throw new VexResponseError(401, responseCode.err_payload, "Token expired");
|
|
77
|
-
}
|
|
78
|
-
else if(error instanceof jwt.JsonWebTokenError) {
|
|
79
|
-
throw new VexResponseError(401, responseCode.err_payload, "jwt malformed");
|
|
80
|
-
}
|
|
81
|
-
else{
|
|
82
|
-
throw error;
|
|
83
|
-
}
|
|
84
|
-
}
|
|
85
|
-
}
|
|
@@ -1,86 +0,0 @@
|
|
|
1
|
-
// {{headerComment}}
|
|
2
|
-
import { UserModel, UserDocument } from "./../../_models/UserModel.gen";
|
|
3
|
-
import { User } from "./../../_types/User.gen";
|
|
4
|
-
import profileMapping, { IProfile } from "./profileMapping.gen";
|
|
5
|
-
import { sanitizeUser } from "./token.gen";
|
|
6
|
-
import vex from "../../_utils/index.gen";
|
|
7
|
-
|
|
8
|
-
export default async function oauthVerify(accessToken: string, refreshToken: string, profile: IProfile, done: (error: any, user?: any) => void) : Promise<void> {
|
|
9
|
-
try {
|
|
10
|
-
|
|
11
|
-
let user: UserDocument;
|
|
12
|
-
const authUser = profileMapping(profile);
|
|
13
|
-
|
|
14
|
-
// find user by authProfiles.authId or email
|
|
15
|
-
const existingUser = await UserModel.findOne<UserDocument>({
|
|
16
|
-
email: authUser.email,
|
|
17
|
-
$or: authUser.authProfiles?.map((p:any) => {
|
|
18
|
-
return { "authProfiles.authId": p.authId };
|
|
19
|
-
}),
|
|
20
|
-
});
|
|
21
|
-
|
|
22
|
-
// 1. create new user
|
|
23
|
-
if ( !existingUser ){
|
|
24
|
-
user = await createNewUser(authUser);
|
|
25
|
-
}
|
|
26
|
-
// 2. update existing user
|
|
27
|
-
else {
|
|
28
|
-
console.log("OAuthVerify UpdateUser");
|
|
29
|
-
user = await processExistingUser(authUser, existingUser);
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
// set req.user
|
|
33
|
-
done(null, {
|
|
34
|
-
provider: profile.provider,
|
|
35
|
-
profile: sanitizeUser(user),
|
|
36
|
-
});
|
|
37
|
-
}
|
|
38
|
-
catch(err) {
|
|
39
|
-
return done(err);
|
|
40
|
-
}
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
async function createNewUser(authProfile: User): Promise<UserDocument>{
|
|
44
|
-
vex.log.info("OAuthVerify > createNewUser");
|
|
45
|
-
const newUser = new UserModel(authProfile);
|
|
46
|
-
return await newUser.save();
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
async function processExistingUser( authUser: User, existingUser: UserDocument): Promise<UserDocument>{
|
|
50
|
-
vex.log.info("OAuthVerify > processExistingUser");
|
|
51
|
-
|
|
52
|
-
let userUpdated = false;
|
|
53
|
-
const authProfile = authUser.authProfiles?.[0] || undefined;
|
|
54
|
-
const userProfiles = existingUser.authProfiles as User["authProfiles"] || [];
|
|
55
|
-
|
|
56
|
-
if(!authProfile){
|
|
57
|
-
vex.log.errorNoExit("OAuthVerify > Invalid OAuth Callback \"authProfile\"");
|
|
58
|
-
throw new Error("Invalid OAuth Callback \"authProfile\"");
|
|
59
|
-
}
|
|
60
|
-
|
|
61
|
-
// B.1. check current provider exist in authProfiles
|
|
62
|
-
const providerExists = userProfiles.length > 0 && userProfiles.find((p:any) => {
|
|
63
|
-
return (p.provider === authProfile.provider) && (p.authId === authProfile.authId);
|
|
64
|
-
});
|
|
65
|
-
|
|
66
|
-
// B.2. add if not exist
|
|
67
|
-
if (!providerExists){
|
|
68
|
-
vex.log.info("OAuthVerify > add new provider",authProfile.provider);
|
|
69
|
-
userProfiles.push(authProfile);
|
|
70
|
-
userUpdated = true;
|
|
71
|
-
}
|
|
72
|
-
// B.3 update if username changed
|
|
73
|
-
else if (providerExists && providerExists.username !== authProfile.username){
|
|
74
|
-
vex.log.info("OAuthVerify > update username", authProfile.provider);
|
|
75
|
-
providerExists.username = authProfile.username;
|
|
76
|
-
userUpdated = true;
|
|
77
|
-
}
|
|
78
|
-
|
|
79
|
-
if (userUpdated){
|
|
80
|
-
vex.log.info("OAuthVerify > Update user");
|
|
81
|
-
return await existingUser.updateOne({ authProfiles: userProfiles });
|
|
82
|
-
}
|
|
83
|
-
else {
|
|
84
|
-
return existingUser;
|
|
85
|
-
}
|
|
86
|
-
}
|
|
@@ -1,68 +0,0 @@
|
|
|
1
|
-
// {{headerComment}}
|
|
2
|
-
import { Profile } from "passport";
|
|
3
|
-
import { User } from "./../../_types/User.gen";
|
|
4
|
-
|
|
5
|
-
export interface IProfile extends Profile {
|
|
6
|
-
[key: string]: any;
|
|
7
|
-
}
|
|
8
|
-
export default function profileMapping(oauthProfile: IProfile): User
|
|
9
|
-
{
|
|
10
|
-
let authProfile: User;
|
|
11
|
-
switch(oauthProfile.provider){
|
|
12
|
-
case "github":
|
|
13
|
-
authProfile = GithubProfileMapping(oauthProfile);
|
|
14
|
-
break;
|
|
15
|
-
case "google":
|
|
16
|
-
authProfile = GoogleProfileMapping(oauthProfile);
|
|
17
|
-
break;
|
|
18
|
-
default:
|
|
19
|
-
throw new Error("Invalid OAuth Provider");
|
|
20
|
-
break;
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
// if ( !authProfile.email){
|
|
24
|
-
// console.log('missingEmail');
|
|
25
|
-
// authProfile.profileErrors?.push('missingEmail');
|
|
26
|
-
// authProfile.active = false;
|
|
27
|
-
// }
|
|
28
|
-
return authProfile;
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
export function GithubProfileMapping(oauthProfile: IProfile): User
|
|
32
|
-
{
|
|
33
|
-
const user: User = {
|
|
34
|
-
active: true,
|
|
35
|
-
authProfiles: [{
|
|
36
|
-
provider: oauthProfile.provider,
|
|
37
|
-
authId: oauthProfile.id,
|
|
38
|
-
username: oauthProfile.username || oauthProfile.displayName
|
|
39
|
-
}],
|
|
40
|
-
roles: undefined,
|
|
41
|
-
name: oauthProfile.username || oauthProfile.displayName,
|
|
42
|
-
email: oauthProfile._json.email || oauthProfile._json.notification_email || undefined,
|
|
43
|
-
locale: undefined,
|
|
44
|
-
profileErrors: []
|
|
45
|
-
};
|
|
46
|
-
|
|
47
|
-
return user;
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
export function GoogleProfileMapping(oauthProfile: IProfile): User
|
|
51
|
-
{
|
|
52
|
-
const user: User = {
|
|
53
|
-
active: true,
|
|
54
|
-
authProfiles: [{
|
|
55
|
-
provider: oauthProfile.provider,
|
|
56
|
-
authId: oauthProfile.id,
|
|
57
|
-
username: oauthProfile.username || oauthProfile.displayName
|
|
58
|
-
}],
|
|
59
|
-
roles: undefined,
|
|
60
|
-
name: oauthProfile.username || oauthProfile.displayName,
|
|
61
|
-
// data below could be missing depend on the provider
|
|
62
|
-
email: oauthProfile._json.email || oauthProfile._json.notification_email || undefined,
|
|
63
|
-
locale: oauthProfile._json.locale || undefined,
|
|
64
|
-
profileErrors: []
|
|
65
|
-
};
|
|
66
|
-
|
|
67
|
-
return user;
|
|
68
|
-
}
|
|
@@ -1,29 +0,0 @@
|
|
|
1
|
-
// {{headerComment}}
|
|
2
|
-
import { generateToken } from "./../auth/jwt.gen";
|
|
3
|
-
import { UserDocument } from "./../../_models/UserModel.gen";
|
|
4
|
-
|
|
5
|
-
export default function returnToken(userProfile: UserDocument){
|
|
6
|
-
const sanitizedProfile = sanitizeUser(userProfile);
|
|
7
|
-
const accessToken = generateToken(sanitizedProfile, undefined, process.env.ACCESS_TOKEN_EXPIRE_TIME);
|
|
8
|
-
const refreshToken = generateToken({_id: userProfile._id }, 0, process.env.REFRESH_TOKEN_EXPIRE_TIME);
|
|
9
|
-
|
|
10
|
-
return {
|
|
11
|
-
profile: sanitizedProfile,
|
|
12
|
-
accessToken: accessToken.token,
|
|
13
|
-
accessTokenIndex: accessToken.index,
|
|
14
|
-
clientIndex: accessToken.clientIndex,
|
|
15
|
-
refreshToken: refreshToken.token
|
|
16
|
-
};
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
export function sanitizeUser(user: UserDocument){
|
|
20
|
-
return {
|
|
21
|
-
_id: user._id,
|
|
22
|
-
email: user.email,
|
|
23
|
-
name: user.name,
|
|
24
|
-
locale: user.locale,
|
|
25
|
-
roles: user.roles,
|
|
26
|
-
profileErrors: user.profileErrors,
|
|
27
|
-
active: user.active
|
|
28
|
-
};
|
|
29
|
-
}
|
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
export { responseMsg } from "./responseMsg.gen";
|
|
2
|
-
export { responseCode, ResponseCode } from "./responseCode.gen";
|
|
3
|
-
export { responseStatusCodeMap } from "./responseStatusCodeMap.gen";
|
|
4
|
-
|
|
5
|
-
export interface responseObject<T>{
|
|
6
|
-
ret_code : number,
|
|
7
|
-
ret_msg : string,
|
|
8
|
-
ret_time?: number,
|
|
9
|
-
result: T,
|
|
10
|
-
}
|
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
import { responseMsg } from "./responseMsg.gen";
|
|
2
|
-
|
|
3
|
-
/** custom response code **/
|
|
4
|
-
export type ResponseCode = keyof typeof responseMsg;
|
|
5
|
-
|
|
6
|
-
/**
|
|
7
|
-
* response code of response message
|
|
8
|
-
**/
|
|
9
|
-
export const responseCode = Object.keys(responseMsg).reduce((acc, key) => {
|
|
10
|
-
acc[key] = key as ResponseCode;
|
|
11
|
-
return acc;
|
|
12
|
-
}, {} as Record<string, ResponseCode>);
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
export default responseCode;
|
|
@@ -1,28 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* default response message by response code
|
|
3
|
-
* { code: message }
|
|
4
|
-
**/
|
|
5
|
-
export const responseMsg = {
|
|
6
|
-
|
|
7
|
-
DB_CONN_ERR: "Database connection error",
|
|
8
|
-
SERVER_ERROR: "Unknown Server Error",
|
|
9
|
-
|
|
10
|
-
success: "Success",
|
|
11
|
-
|
|
12
|
-
err_permission: "Permission Denied",
|
|
13
|
-
|
|
14
|
-
err_payload: "Invalid Request Payload",
|
|
15
|
-
err_query: "Invalid Request Query",
|
|
16
|
-
err_body: "Invalid Request Body",
|
|
17
|
-
|
|
18
|
-
err_validation: "Validation Error",
|
|
19
|
-
err_query_validation: "Query Validation Error",
|
|
20
|
-
err_body_validation: "Body Validation Error",
|
|
21
|
-
|
|
22
|
-
err_create: "Falied to Insert Data",
|
|
23
|
-
err_read: "Falied to Read Data",
|
|
24
|
-
err_update: "Falied to Edit Data",
|
|
25
|
-
err_delete: "Falied to Delete Data",
|
|
26
|
-
};
|
|
27
|
-
|
|
28
|
-
export default responseMsg;
|
|
@@ -1,70 +0,0 @@
|
|
|
1
|
-
import responseCode from "./responseCode.gen";
|
|
2
|
-
|
|
3
|
-
/**
|
|
4
|
-
* response status default message.
|
|
5
|
-
* if set value as response code, response handler will set status, code & message.
|
|
6
|
-
**/
|
|
7
|
-
export const responseStatusCodeMap = new Map<number, string>();
|
|
8
|
-
// responseStatusCodeMap.set(100, "Continue");
|
|
9
|
-
// responseStatusCodeMap.set(101, "Switching Protocols");
|
|
10
|
-
// responseStatusCodeMap.set(102, "Processing");
|
|
11
|
-
// responseStatusCodeMap.set(103, "Early Hints");
|
|
12
|
-
responseStatusCodeMap.set(200, responseCode.success);
|
|
13
|
-
responseStatusCodeMap.set(201, responseCode.success);
|
|
14
|
-
responseStatusCodeMap.set(202, responseCode.success);
|
|
15
|
-
// responseStatusCodeMap.set(203, "Non-Authoritative Information");
|
|
16
|
-
// responseStatusCodeMap.set(204, "No Content");
|
|
17
|
-
// responseStatusCodeMap.set(205, "Reset Content");
|
|
18
|
-
// responseStatusCodeMap.set(206, "Partial Content");
|
|
19
|
-
// responseStatusCodeMap.set(207, "Multi-Status");
|
|
20
|
-
// responseStatusCodeMap.set(208, "Already Reported");
|
|
21
|
-
// responseStatusCodeMap.set(226, "IM Used");
|
|
22
|
-
// responseStatusCodeMap.set(300, "Multiple Choices");
|
|
23
|
-
// responseStatusCodeMap.set(301, "Moved Permanently");
|
|
24
|
-
// responseStatusCodeMap.set(302, "Found");
|
|
25
|
-
// responseStatusCodeMap.set(303, "See Other");
|
|
26
|
-
// responseStatusCodeMap.set(304, "Not Modified");
|
|
27
|
-
// responseStatusCodeMap.set(307, "Temporary Redirect");
|
|
28
|
-
// responseStatusCodeMap.set(308, "Permanent Redirect");
|
|
29
|
-
responseStatusCodeMap.set(400, responseCode.err_payload);
|
|
30
|
-
// responseStatusCodeMap.set(401, responseCode.err_permission);
|
|
31
|
-
// responseStatusCodeMap.set(402, "Payment Required");
|
|
32
|
-
// responseStatusCodeMap.set(403, "Forbidden");
|
|
33
|
-
// responseStatusCodeMap.set(404, "Not Found");
|
|
34
|
-
// responseStatusCodeMap.set(405, "Method Not Allowed");
|
|
35
|
-
// responseStatusCodeMap.set(406, "Not Acceptable");
|
|
36
|
-
// responseStatusCodeMap.set(407, "Proxy Authentication Required");
|
|
37
|
-
// responseStatusCodeMap.set(408, "Request Timeout");
|
|
38
|
-
// responseStatusCodeMap.set(409, "Conflict");
|
|
39
|
-
// responseStatusCodeMap.set(410, "Gone");
|
|
40
|
-
// responseStatusCodeMap.set(411, "Length Required");
|
|
41
|
-
// responseStatusCodeMap.set(412, "Precondition Failed");
|
|
42
|
-
// responseStatusCodeMap.set(413, "Content Too Large");
|
|
43
|
-
// responseStatusCodeMap.set(414, "URI Too Long");
|
|
44
|
-
// responseStatusCodeMap.set(415, "Unsupported Media Type");
|
|
45
|
-
// responseStatusCodeMap.set(416, "Range Not Satisfiable");
|
|
46
|
-
// responseStatusCodeMap.set(417, "Expectation Failed");
|
|
47
|
-
// responseStatusCodeMap.set(418, "I'm a teapot");
|
|
48
|
-
// responseStatusCodeMap.set(421, "Misdirected Request");
|
|
49
|
-
// responseStatusCodeMap.set(422, "Unprocessable Content");
|
|
50
|
-
// responseStatusCodeMap.set(423, "Locked");
|
|
51
|
-
// responseStatusCodeMap.set(424, "Failed Dependency");
|
|
52
|
-
// responseStatusCodeMap.set(425, "Too Early");
|
|
53
|
-
// responseStatusCodeMap.set(426, "Upgrade Required");
|
|
54
|
-
// responseStatusCodeMap.set(428, "Precondition Required");
|
|
55
|
-
// responseStatusCodeMap.set(429, "Too Many Requests");
|
|
56
|
-
// responseStatusCodeMap.set(431, "Request Header Fields Too Large");
|
|
57
|
-
// responseStatusCodeMap.set(451, "Unavailable For Legal Reasons");
|
|
58
|
-
// responseStatusCodeMap.set(500, "Internal Server Error");
|
|
59
|
-
// responseStatusCodeMap.set(501, "Not Implemented");
|
|
60
|
-
// responseStatusCodeMap.set(502, "Bad Gateway");
|
|
61
|
-
// responseStatusCodeMap.set(503, "Service Unavailable");
|
|
62
|
-
// responseStatusCodeMap.set(504, "Gateway Timeout");
|
|
63
|
-
// responseStatusCodeMap.set(505, "HTTP Version Not Supported");
|
|
64
|
-
// responseStatusCodeMap.set(506, "Variant Also Negotiates");
|
|
65
|
-
// responseStatusCodeMap.set(507, "Insufficient Storage");
|
|
66
|
-
// responseStatusCodeMap.set(508, "Loop Detected");
|
|
67
|
-
// responseStatusCodeMap.set(510, "Not Extended");
|
|
68
|
-
// responseStatusCodeMap.set(511, "Network Authentication Required");
|
|
69
|
-
|
|
70
|
-
export default responseStatusCodeMap;
|
|
File without changes
|