gemcap-be-common 1.4.13 → 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/package.json +2 -2
- package/public/plaid/connect.js +5 -5
- package/services/users.service.d.ts +0 -1
- package/services/users.service.js +1 -53
- package/services/users.service.ts +2 -55
- 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/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
|
}>>;
|
|
@@ -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);
|
|
@@ -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({ 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
|
}
|
|
@@ -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) {
|
|
@@ -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({ 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
|
}
|