gemcap-be-common 1.4.12 → 1.4.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/models/User.model.d.ts +4 -4
- package/models/User.model.js +1 -1
- package/models/User.model.ts +2 -2
- package/models/UserMobileAccess.model.d.ts +1 -1
- package/models/UserMobileAccess.model.js +1 -1
- package/models/UserMobileAccess.model.ts +2 -2
- package/package.json +2 -2
- package/public/plaid/connect.js +5 -5
- package/services/users.service.d.ts +0 -1
- package/services/users.service.js +4 -56
- package/services/users.service.ts +5 -58
- package/tsconfig.tsbuildinfo +1 -1
- package/helpers/users.helper.d.ts +0 -12
- package/helpers/users.helper.js +0 -17
- package/helpers/users.helper.ts +0 -20
package/models/User.model.d.ts
CHANGED
|
@@ -27,7 +27,7 @@ export interface IUserLegacy {
|
|
|
27
27
|
isDeleted?: boolean;
|
|
28
28
|
firstName?: string;
|
|
29
29
|
lastName?: string;
|
|
30
|
-
|
|
30
|
+
userId?: string;
|
|
31
31
|
allBorrowers: boolean;
|
|
32
32
|
lastLogin?: Date;
|
|
33
33
|
borrowersAccess: {
|
|
@@ -42,8 +42,8 @@ export declare const UserSchema: mongoose.Schema<any, mongoose.Model<any, any, a
|
|
|
42
42
|
createdAt: NativeDate;
|
|
43
43
|
updatedAt: NativeDate;
|
|
44
44
|
} & {
|
|
45
|
+
userId: string;
|
|
45
46
|
isDeleted: boolean;
|
|
46
|
-
keycloakUserId: string;
|
|
47
47
|
borrowersAccess: mongoose.Types.DocumentArray<{
|
|
48
48
|
borrower: string;
|
|
49
49
|
}>;
|
|
@@ -56,8 +56,8 @@ export declare const UserSchema: mongoose.Schema<any, mongoose.Model<any, any, a
|
|
|
56
56
|
createdAt: NativeDate;
|
|
57
57
|
updatedAt: NativeDate;
|
|
58
58
|
} & {
|
|
59
|
+
userId: string;
|
|
59
60
|
isDeleted: boolean;
|
|
60
|
-
keycloakUserId: string;
|
|
61
61
|
borrowersAccess: mongoose.Types.DocumentArray<{
|
|
62
62
|
borrower: string;
|
|
63
63
|
}>;
|
|
@@ -70,8 +70,8 @@ export declare const UserSchema: mongoose.Schema<any, mongoose.Model<any, any, a
|
|
|
70
70
|
createdAt: NativeDate;
|
|
71
71
|
updatedAt: NativeDate;
|
|
72
72
|
} & {
|
|
73
|
+
userId: string;
|
|
73
74
|
isDeleted: boolean;
|
|
74
|
-
keycloakUserId: string;
|
|
75
75
|
borrowersAccess: mongoose.Types.DocumentArray<{
|
|
76
76
|
borrower: string;
|
|
77
77
|
}>;
|
package/models/User.model.js
CHANGED
package/models/User.model.ts
CHANGED
|
@@ -8,7 +8,7 @@ export interface IUserLegacy {
|
|
|
8
8
|
isDeleted?: boolean;
|
|
9
9
|
firstName?: string;
|
|
10
10
|
lastName?: string;
|
|
11
|
-
|
|
11
|
+
userId?: string;
|
|
12
12
|
allBorrowers: boolean;
|
|
13
13
|
lastLogin?: Date;
|
|
14
14
|
borrowersAccess: {
|
|
@@ -25,7 +25,7 @@ export const UserSchema = new mongoose.Schema(
|
|
|
25
25
|
type: Boolean,
|
|
26
26
|
default: false,
|
|
27
27
|
},
|
|
28
|
-
|
|
28
|
+
userId: {
|
|
29
29
|
type: String,
|
|
30
30
|
trim: true,
|
|
31
31
|
required: true,
|
|
@@ -7,7 +7,7 @@ exports.UserMobileAccess = exports.UserMobileAccessSchema = void 0;
|
|
|
7
7
|
const mongoose_1 = __importDefault(require("mongoose"));
|
|
8
8
|
const _models_1 = require("./_models");
|
|
9
9
|
exports.UserMobileAccessSchema = new mongoose_1.default.Schema({
|
|
10
|
-
|
|
10
|
+
userId: {
|
|
11
11
|
type: String,
|
|
12
12
|
trim: true,
|
|
13
13
|
required: true,
|
|
@@ -4,7 +4,7 @@ import { MODEL_NAMES } from './_models';
|
|
|
4
4
|
|
|
5
5
|
export interface IUserMobileAccess {
|
|
6
6
|
_id?: mongoose.Types.ObjectId;
|
|
7
|
-
|
|
7
|
+
userId?: string;
|
|
8
8
|
hasAccess: boolean;
|
|
9
9
|
canSignDocument: boolean;
|
|
10
10
|
}
|
|
@@ -13,7 +13,7 @@ type UserMobileAccessModel = Model<IUserMobileAccess, {}, {}>;
|
|
|
13
13
|
|
|
14
14
|
export const UserMobileAccessSchema = new mongoose.Schema<IUserMobileAccess, UserMobileAccessModel>(
|
|
15
15
|
{
|
|
16
|
-
|
|
16
|
+
userId: {
|
|
17
17
|
type: String,
|
|
18
18
|
trim: true,
|
|
19
19
|
required: true,
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "gemcap-be-common",
|
|
3
|
-
"version": "1.4.
|
|
3
|
+
"version": "1.4.14",
|
|
4
4
|
"description": "",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"scripts": {
|
|
@@ -14,6 +14,7 @@
|
|
|
14
14
|
"@types/pdfmake": "^0.2.9",
|
|
15
15
|
"amqplib": "^0.10.8",
|
|
16
16
|
"aws-sdk": "^2.1691.0",
|
|
17
|
+
"axios": "^1.12.2",
|
|
17
18
|
"class-transformer": "^0.5.1",
|
|
18
19
|
"dayjs": "^1.11.13",
|
|
19
20
|
"decimal.js": "^10.4.3",
|
|
@@ -21,7 +22,6 @@
|
|
|
21
22
|
"express": "^4.21.0",
|
|
22
23
|
"joi": "^17.13.3",
|
|
23
24
|
"jwt-decode": "^4.0.0",
|
|
24
|
-
"keycloak-connect": "^24.0.5",
|
|
25
25
|
"lodash": "^4.17.21",
|
|
26
26
|
"mongoose": "^8.3.1",
|
|
27
27
|
"nodemailer": "^6.9.15",
|
package/public/plaid/connect.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
let linkTokenData;
|
|
2
|
-
let
|
|
2
|
+
let authToken;
|
|
3
3
|
let borrowerId;
|
|
4
4
|
let redirectLink;
|
|
5
5
|
|
|
@@ -31,7 +31,7 @@ const startLink = () => {
|
|
|
31
31
|
|
|
32
32
|
const handler = Plaid.create({
|
|
33
33
|
token: linkTokenData.link_token,
|
|
34
|
-
onSuccess: async (publicToken) => await exchangeToken(publicToken,
|
|
34
|
+
onSuccess: async (publicToken) => await exchangeToken(publicToken, authToken, borrowerId, redirectLink),
|
|
35
35
|
onExit: (err, metadata) => {
|
|
36
36
|
},
|
|
37
37
|
onEvent: (eventName) => {
|
|
@@ -40,10 +40,10 @@ const startLink = () => {
|
|
|
40
40
|
handler.open();
|
|
41
41
|
};
|
|
42
42
|
|
|
43
|
-
const exchangeToken = async (publicToken,
|
|
43
|
+
const exchangeToken = async (publicToken, authToken, borrowerId, redirectLink) => {
|
|
44
44
|
const url = new URL(window.location);
|
|
45
45
|
const searchParams = url.searchParams;
|
|
46
|
-
|
|
46
|
+
authToken = searchParams.get('authorization');
|
|
47
47
|
borrowerId = searchParams.get('borrowerId');
|
|
48
48
|
redirectLink = searchParams.get('redirectLink');
|
|
49
49
|
|
|
@@ -52,7 +52,7 @@ const exchangeToken = async (publicToken, keycloakToken, borrowerId, redirectLin
|
|
|
52
52
|
{
|
|
53
53
|
method: 'POST',
|
|
54
54
|
headers: { 'Content-type': 'application/json' },
|
|
55
|
-
body: JSON.stringify({ public_token: publicToken,
|
|
55
|
+
body: JSON.stringify({ public_token: publicToken, authToken, borrowerId }),
|
|
56
56
|
},
|
|
57
57
|
);
|
|
58
58
|
window.location.href = redirectLink;
|
|
@@ -43,7 +43,6 @@ export declare class UsersService {
|
|
|
43
43
|
[key: string]: string | number | boolean;
|
|
44
44
|
}): Promise<void>;
|
|
45
45
|
getUserAccess(userId: string): Promise<IUserAccess>;
|
|
46
|
-
createUserLoginLog(): Promise<void>;
|
|
47
46
|
getUserLogByDate(userId: string, date: Date): Promise<import("mongoose").FlattenMaps<import("../models/UserLog.model").IUserLog> & Required<{
|
|
48
47
|
_id: import("mongoose").Types.ObjectId;
|
|
49
48
|
}>>;
|
|
@@ -39,8 +39,8 @@ class UsersService {
|
|
|
39
39
|
if (!authorization) {
|
|
40
40
|
return null;
|
|
41
41
|
}
|
|
42
|
-
const { sub
|
|
43
|
-
return this.getUserById(
|
|
42
|
+
const { sub } = (0, jwt_decode_1.jwtDecode)(authorization);
|
|
43
|
+
return this.getUserById(sub);
|
|
44
44
|
}
|
|
45
45
|
async getUserIdByToken(req) {
|
|
46
46
|
const user = await this.getUserByToken(req);
|
|
@@ -55,7 +55,7 @@ class UsersService {
|
|
|
55
55
|
}
|
|
56
56
|
async getAllRoles() {
|
|
57
57
|
const { data } = await axios_1.default.get(`${this.config.baseUrl}/users/roles`);
|
|
58
|
-
return data ??
|
|
58
|
+
return data ?? [];
|
|
59
59
|
}
|
|
60
60
|
async getUserRoles(userId) {
|
|
61
61
|
const user = await this.getUserById(userId);
|
|
@@ -66,7 +66,7 @@ class UsersService {
|
|
|
66
66
|
.map((role) => role.name);
|
|
67
67
|
}
|
|
68
68
|
async updateMobileUser(userId, keyValue) {
|
|
69
|
-
await UserMobileAccess_model_1.UserMobileAccess.findOneAndUpdate({
|
|
69
|
+
await UserMobileAccess_model_1.UserMobileAccess.findOneAndUpdate({ userId }, keyValue, { upsert: true });
|
|
70
70
|
}
|
|
71
71
|
async getUserAccess(userId) {
|
|
72
72
|
const foundUser = await this.getUserById(userId);
|
|
@@ -75,58 +75,6 @@ class UsersService {
|
|
|
75
75
|
.map((b) => b._id.toString());
|
|
76
76
|
return { allBorrowers: foundUser.allBorrowers, borrowersAccess, complianceBorrowersAccess };
|
|
77
77
|
}
|
|
78
|
-
async createUserLoginLog() {
|
|
79
|
-
// const { access_token } = await this.getKeyCloakAdminBearer();
|
|
80
|
-
// const dateFrom = dayjs().subtract(1, 'day').format('YYYY-MM-DD');
|
|
81
|
-
// const reqUrl = `${this.config.keycloakHost}/admin/realms/${this.config.realm}/events?type=LOGIN&dateFrom=${dateFrom}&max=10000`;
|
|
82
|
-
// const options = {
|
|
83
|
-
// method: 'GET',
|
|
84
|
-
// url: reqUrl,
|
|
85
|
-
// headers: {
|
|
86
|
-
// 'Content-Type': 'application/json',
|
|
87
|
-
// Authorization: `Bearer ${access_token}`,
|
|
88
|
-
// },
|
|
89
|
-
// };
|
|
90
|
-
// try {
|
|
91
|
-
// const result = await axios.request(options);
|
|
92
|
-
// const userDates: { [userId: string]: Set<string> } = {};
|
|
93
|
-
// result.data.forEach((log: { userId: string, time: number }) => {
|
|
94
|
-
// const timestamp = new Date(log.time);
|
|
95
|
-
// const formattedDate = timestamp.getFullYear() +
|
|
96
|
-
// '-' + ('0' + (timestamp.getMonth() + 1)).slice(-2) +
|
|
97
|
-
// '-' + ('0' + timestamp.getDate()).slice(-2) +
|
|
98
|
-
// 'T' + ('0' + timestamp.getHours()).slice(-2) +
|
|
99
|
-
// ':' + ('0' + timestamp.getMinutes()).slice(-2);
|
|
100
|
-
//
|
|
101
|
-
// const userId = log.userId;
|
|
102
|
-
// if (!userDates[userId]) {
|
|
103
|
-
// userDates[userId] = new Set<string>();
|
|
104
|
-
// }
|
|
105
|
-
// userDates[userId].add(formattedDate);
|
|
106
|
-
// });
|
|
107
|
-
// await Promise.all(Object.entries(userDates).map(async ([userId, dateSet]) => {
|
|
108
|
-
// const user = await UserModel.findOne({ keycloakUserId: userId });
|
|
109
|
-
// if (!user) {
|
|
110
|
-
// return;
|
|
111
|
-
// }
|
|
112
|
-
// await Promise.all(Array.from(dateSet).map(async (date) => {
|
|
113
|
-
// const existingLog = await this.getUserLogByDate(String(user._id), new Date(date));
|
|
114
|
-
// if (!existingLog) {
|
|
115
|
-
// const newLog: ICreateLogParams = {
|
|
116
|
-
// action: ELogActionType.CREATE,
|
|
117
|
-
// timestamp: new Date(date),
|
|
118
|
-
// logType: ELogType.LOGIN,
|
|
119
|
-
// userId: String(user._id),
|
|
120
|
-
// details: {},
|
|
121
|
-
// };
|
|
122
|
-
// await createLog(newLog);
|
|
123
|
-
// }
|
|
124
|
-
// }));
|
|
125
|
-
// }));
|
|
126
|
-
// } catch (e) {
|
|
127
|
-
// console.error(e);
|
|
128
|
-
// }
|
|
129
|
-
}
|
|
130
78
|
async getUserLogByDate(userId, date) {
|
|
131
79
|
return UserLog_model_1.UserLog.findOne({ userId, timestamp: date }).lean();
|
|
132
80
|
}
|
|
@@ -46,8 +46,8 @@ export class UsersService {
|
|
|
46
46
|
if (!authorization) {
|
|
47
47
|
return null;
|
|
48
48
|
}
|
|
49
|
-
const { sub
|
|
50
|
-
return this.getUserById(
|
|
49
|
+
const { sub }: { sub: string } = jwtDecode(authorization);
|
|
50
|
+
return this.getUserById(sub);
|
|
51
51
|
}
|
|
52
52
|
|
|
53
53
|
async getUserIdByToken(req: express.Request) {
|
|
@@ -63,9 +63,9 @@ export class UsersService {
|
|
|
63
63
|
return data ?? null;
|
|
64
64
|
}
|
|
65
65
|
|
|
66
|
-
async getAllRoles() {
|
|
66
|
+
async getAllRoles(): Promise<IUserRole[]> {
|
|
67
67
|
const { data } = await axios.get<IUserRole[]>(`${this.config.baseUrl}/users/roles`);
|
|
68
|
-
return data ??
|
|
68
|
+
return data ?? [];
|
|
69
69
|
}
|
|
70
70
|
|
|
71
71
|
async getUserRoles(userId: string) {
|
|
@@ -78,7 +78,7 @@ export class UsersService {
|
|
|
78
78
|
}
|
|
79
79
|
|
|
80
80
|
async updateMobileUser(userId: string, keyValue: { [key: string]: string | number | boolean }) {
|
|
81
|
-
await UserMobileAccess.findOneAndUpdate({
|
|
81
|
+
await UserMobileAccess.findOneAndUpdate({ userId }, keyValue, { upsert: true });
|
|
82
82
|
}
|
|
83
83
|
|
|
84
84
|
async getUserAccess(userId: string): Promise<IUserAccess> {
|
|
@@ -90,59 +90,6 @@ export class UsersService {
|
|
|
90
90
|
return { allBorrowers: foundUser.allBorrowers, borrowersAccess, complianceBorrowersAccess };
|
|
91
91
|
}
|
|
92
92
|
|
|
93
|
-
async createUserLoginLog() {
|
|
94
|
-
// const { access_token } = await this.getKeyCloakAdminBearer();
|
|
95
|
-
// const dateFrom = dayjs().subtract(1, 'day').format('YYYY-MM-DD');
|
|
96
|
-
// const reqUrl = `${this.config.keycloakHost}/admin/realms/${this.config.realm}/events?type=LOGIN&dateFrom=${dateFrom}&max=10000`;
|
|
97
|
-
// const options = {
|
|
98
|
-
// method: 'GET',
|
|
99
|
-
// url: reqUrl,
|
|
100
|
-
// headers: {
|
|
101
|
-
// 'Content-Type': 'application/json',
|
|
102
|
-
// Authorization: `Bearer ${access_token}`,
|
|
103
|
-
// },
|
|
104
|
-
// };
|
|
105
|
-
// try {
|
|
106
|
-
// const result = await axios.request(options);
|
|
107
|
-
// const userDates: { [userId: string]: Set<string> } = {};
|
|
108
|
-
// result.data.forEach((log: { userId: string, time: number }) => {
|
|
109
|
-
// const timestamp = new Date(log.time);
|
|
110
|
-
// const formattedDate = timestamp.getFullYear() +
|
|
111
|
-
// '-' + ('0' + (timestamp.getMonth() + 1)).slice(-2) +
|
|
112
|
-
// '-' + ('0' + timestamp.getDate()).slice(-2) +
|
|
113
|
-
// 'T' + ('0' + timestamp.getHours()).slice(-2) +
|
|
114
|
-
// ':' + ('0' + timestamp.getMinutes()).slice(-2);
|
|
115
|
-
//
|
|
116
|
-
// const userId = log.userId;
|
|
117
|
-
// if (!userDates[userId]) {
|
|
118
|
-
// userDates[userId] = new Set<string>();
|
|
119
|
-
// }
|
|
120
|
-
// userDates[userId].add(formattedDate);
|
|
121
|
-
// });
|
|
122
|
-
// await Promise.all(Object.entries(userDates).map(async ([userId, dateSet]) => {
|
|
123
|
-
// const user = await UserModel.findOne({ keycloakUserId: userId });
|
|
124
|
-
// if (!user) {
|
|
125
|
-
// return;
|
|
126
|
-
// }
|
|
127
|
-
// await Promise.all(Array.from(dateSet).map(async (date) => {
|
|
128
|
-
// const existingLog = await this.getUserLogByDate(String(user._id), new Date(date));
|
|
129
|
-
// if (!existingLog) {
|
|
130
|
-
// const newLog: ICreateLogParams = {
|
|
131
|
-
// action: ELogActionType.CREATE,
|
|
132
|
-
// timestamp: new Date(date),
|
|
133
|
-
// logType: ELogType.LOGIN,
|
|
134
|
-
// userId: String(user._id),
|
|
135
|
-
// details: {},
|
|
136
|
-
// };
|
|
137
|
-
// await createLog(newLog);
|
|
138
|
-
// }
|
|
139
|
-
// }));
|
|
140
|
-
// }));
|
|
141
|
-
// } catch (e) {
|
|
142
|
-
// console.error(e);
|
|
143
|
-
// }
|
|
144
|
-
}
|
|
145
|
-
|
|
146
93
|
async getUserLogByDate(userId: string, date: Date) {
|
|
147
94
|
return UserLog.findOne({ userId, timestamp: date }).lean();
|
|
148
95
|
}
|