gemcap-be-common 1.4.13 → 1.4.15

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.
@@ -22,7 +22,7 @@
22
22
  /// <reference types="mongoose/types/validation" />
23
23
  /// <reference types="mongoose/types/virtuals" />
24
24
  /// <reference types="mongoose/types/inferschematype" />
25
- import mongoose, { Model } from 'mongoose';
25
+ import mongoose, { Document, Model } from 'mongoose';
26
26
  export declare enum ELogType {
27
27
  TRANSACTIONS_UPLOAD = "TRANSACTIONS_UPLOAD",
28
28
  COLLATERAL_UPLOAD = "COLLATERAL_UPLOAD",
@@ -44,7 +44,6 @@ export declare enum ELogActionType {
44
44
  DELETE = "DELETE"
45
45
  }
46
46
  export interface IUserLog {
47
- _id?: mongoose.Types.ObjectId;
48
47
  logType: ELogType;
49
48
  userId: string;
50
49
  timestamp: Date;
@@ -53,12 +52,14 @@ export interface IUserLog {
53
52
  recordCollection: string;
54
53
  details: any;
55
54
  }
55
+ export interface IUserLogDoc extends IUserLog, Document {
56
+ }
56
57
  export interface IUserLogWithLookup extends IUserLog {
57
58
  record?: any;
58
59
  }
59
60
  type UserLogModel = Model<IUserLog, {}, {}>;
60
- export declare const UserLogSchema: mongoose.Schema<IUserLog, UserLogModel, {}, {}, {}, {}, mongoose.DefaultSchemaOptions, IUserLog, mongoose.Document<unknown, {}, mongoose.FlatRecord<IUserLog>> & mongoose.FlatRecord<IUserLog> & Required<{
61
+ export declare const UserLogSchema: mongoose.Schema<IUserLog, UserLogModel, {}, {}, {}, {}, mongoose.DefaultSchemaOptions, IUserLog, mongoose.Document<unknown, {}, mongoose.FlatRecord<IUserLog>> & mongoose.FlatRecord<IUserLog> & {
61
62
  _id: mongoose.Types.ObjectId;
62
- }>>;
63
+ }>;
63
64
  export declare const UserLog: UserLogModel;
64
65
  export {};
@@ -1,4 +1,4 @@
1
- import mongoose, { Model } from 'mongoose';
1
+ import mongoose, { Document, Model } from 'mongoose';
2
2
 
3
3
  import { MODEL_NAMES } from './_models';
4
4
 
@@ -25,7 +25,6 @@ export enum ELogActionType {
25
25
  }
26
26
 
27
27
  export interface IUserLog {
28
- _id?: mongoose.Types.ObjectId;
29
28
  logType: ELogType;
30
29
  userId: string;
31
30
  timestamp: Date;
@@ -35,6 +34,9 @@ export interface IUserLog {
35
34
  details: any;
36
35
  }
37
36
 
37
+ export interface IUserLogDoc extends IUserLog, Document {
38
+ }
39
+
38
40
  export interface IUserLogWithLookup extends IUserLog {
39
41
  record?: any;
40
42
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "gemcap-be-common",
3
- "version": "1.4.13",
3
+ "version": "1.4.15",
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",
@@ -1,5 +1,5 @@
1
1
  let linkTokenData;
2
- let keycloakToken;
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, keycloakToken, borrowerId, redirectLink),
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, keycloakToken, borrowerId, redirectLink) => {
43
+ const exchangeToken = async (publicToken, authToken, borrowerId, redirectLink) => {
44
44
  const url = new URL(window.location);
45
45
  const searchParams = url.searchParams;
46
- keycloakToken = searchParams.get('authorization');
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, keycloakToken, borrowerId }),
55
+ body: JSON.stringify({ public_token: publicToken, authToken, borrowerId }),
56
56
  },
57
57
  );
58
58
  window.location.href = redirectLink;
@@ -46,9 +46,9 @@ export declare class BrokersService {
46
46
  getAllProductBrokers(): Promise<(import("mongoose").FlattenMaps<import("../models/ProductBroker.model").IProductBrokerDoc> & {
47
47
  _id: import("mongoose").Types.ObjectId;
48
48
  })[]>;
49
- getBorrowerBrokers(borrowerId: string): Promise<BrokerView[] | (import("mongoose").FlattenMaps<import("../models/ProductBroker.model").IProductBrokerDoc> & {
49
+ getBorrowerBrokers(borrowerId: string): Promise<(import("mongoose").FlattenMaps<import("../models/ProductBroker.model").IProductBrokerDoc> & {
50
50
  _id: import("mongoose").Types.ObjectId;
51
- })[]>;
51
+ })[] | BrokerView[]>;
52
52
  getProductBrokers(productId: string): Promise<import("../models/ProductBroker.model").IProductBrokerDocWithBroker[]>;
53
53
  getTotalShares(borrowerId: string, brokers: IProductBrokerView[], replaceNames?: boolean): Promise<ProductTotal>;
54
54
  getTotals(borrowerId: string): Promise<BrokerTotalView[]>;
@@ -45,7 +45,7 @@ export declare class ComplianceBorrowersService {
45
45
  };
46
46
  };
47
47
  getFullComplianceBorrowerById(complianceBorrowerId: string): Promise<any>;
48
- getAllBorrowersShortened(userAccess: any): Promise<(Pick<IComplianceBorrowerDocument, "borrower" | "fundingStatus" | "items"> | {
48
+ getAllBorrowersShortened(userAccess: any): Promise<(Pick<IComplianceBorrowerDocument, "borrower" | "items" | "fundingStatus"> | {
49
49
  items: {
50
50
  instances: any[];
51
51
  item: import("../models/ComplianceItem.model").IComplianceItemDocument;
@@ -155,7 +155,7 @@ export declare class LoanTransactionsService {
155
155
  getTransactionReport(transactionIds: string[], borrowerId: string, effectiveDate: Date): Promise<{
156
156
  transactionIdsToMark: any[];
157
157
  transactions: {
158
- [x: string]: (string | number | string[] | Date)[];
158
+ [x: string]: (string | number | Date | string[])[];
159
159
  }[];
160
160
  }>;
161
161
  getBorrowerIdsForFile(transactionFileId: string): Promise<{
@@ -1,5 +1,5 @@
1
1
  import { ICreateLogParams } from '../db/user-logs.db';
2
- import { IUserLog, IUserLogWithLookup } from '../models/UserLog.model';
2
+ import { IUserLogDoc, IUserLogWithLookup } from '../models/UserLog.model';
3
3
  import { BanksService } from './banks.service';
4
4
  import { BorrowersDB } from './borrowers.db';
5
5
  import { LoanChargesService } from './loan-charges.service';
@@ -17,7 +17,7 @@ export declare class UserLogsService {
17
17
  createUserLog(params: ICreateLogParams): Promise<void>;
18
18
  filterByBorrower(logs: IUserLogWithLookup[], borrowerId: string): Promise<IUserLogWithLookup[]>;
19
19
  replaceBorrowers(logs: IUserLogWithLookup[]): Promise<void[]>;
20
- performDynamicLookup(record: IUserLog): Promise<IUserLogWithLookup>;
20
+ performDynamicLookup(record: IUserLogDoc): Promise<IUserLogWithLookup>;
21
21
  getLogs(filter: IUserLogFilter): Promise<IUserLogWithLookup[]>;
22
22
  getDocumentLogs(documentId: string): Promise<IUserLogWithLookup[]>;
23
23
  }
@@ -1,7 +1,7 @@
1
1
  import mongoose from 'mongoose';
2
2
 
3
3
  import { createLog, ICreateLogParams } from '../db/user-logs.db';
4
- import { ELogType, IUserLog, IUserLogWithLookup, UserLog } from '../models/UserLog.model';
4
+ import { ELogType, IUserLogDoc, IUserLogWithLookup, UserLog } from '../models/UserLog.model';
5
5
  import { DeletedRecord } from '../models/DeletedRecords.model';
6
6
 
7
7
  import { BanksService } from './banks.service';
@@ -82,7 +82,7 @@ export class UserLogsService {
82
82
  });
83
83
  }
84
84
 
85
- async performDynamicLookup(record: IUserLog): Promise<IUserLogWithLookup> {
85
+ async performDynamicLookup(record: IUserLogDoc): Promise<IUserLogWithLookup> {
86
86
  try {
87
87
  const { _id, recordCollection } = record;
88
88
  if (!recordCollection) {
@@ -132,7 +132,7 @@ export class UserLogsService {
132
132
  }
133
133
 
134
134
  async getLogs(filter: IUserLogFilter) {
135
- const logs = await UserLog.aggregate<IUserLog>([
135
+ const logs = await UserLog.aggregate<IUserLogDoc>([
136
136
  {
137
137
  $match: {
138
138
  $and: [
@@ -157,7 +157,7 @@ export class UserLogsService {
157
157
  }
158
158
 
159
159
  async getDocumentLogs(documentId: string) {
160
- const logs = await UserLog.aggregate<IUserLog>([
160
+ const logs = await UserLog.aggregate<IUserLogDoc>([
161
161
  {
162
162
  $match: {
163
163
  $and: [
@@ -43,9 +43,8 @@ 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
- getUserLogByDate(userId: string, date: Date): Promise<import("mongoose").FlattenMaps<import("../models/UserLog.model").IUserLog> & Required<{
46
+ getUserLogByDate(userId: string, date: Date): Promise<import("mongoose").FlattenMaps<import("../models/UserLog.model").IUserLog> & {
48
47
  _id: import("mongoose").Types.ObjectId;
49
- }>>;
48
+ }>;
50
49
  }
51
50
  export {};
@@ -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 ?? null;
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 ?? null;
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
  }