gemcap-be-common 1.2.135 → 1.2.136

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.
@@ -23,7 +23,7 @@
23
23
  /// <reference types="mongoose/types/virtuals" />
24
24
  /// <reference types="mongoose/types/inferschematype" />
25
25
  import mongoose, { Document } from 'mongoose';
26
- import { IBorrowerItemDocument, IEmailRecipient } from '../models/ComplianceItem.model';
26
+ import { IBorrowerItemDocument, IEmailRecipient } from './ComplianceItem.model';
27
27
  export interface IComplianceNote {
28
28
  note: string;
29
29
  date: Date;
@@ -5,7 +5,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
6
  exports.BorrowerCompliance = void 0;
7
7
  const mongoose_1 = __importDefault(require("mongoose"));
8
- const _models_1 = require("../models/_models");
8
+ const _models_1 = require("./_models");
9
9
  const mongooseLeanId = require('../plugins/id.plugin');
10
10
  const BorrowerComplianceInstanceSchema = new mongoose_1.default.Schema({
11
11
  nextDate: {
@@ -3,8 +3,8 @@ import mongoose, { Document } from 'mongoose';
3
3
  import {
4
4
  IBorrowerItemDocument,
5
5
  IEmailRecipient,
6
- } from '../models/ComplianceItem.model';
7
- import { MODEL_NAMES } from '../models/_models';
6
+ } from './ComplianceItem.model';
7
+ import { MODEL_NAMES } from './_models';
8
8
 
9
9
  const mongooseLeanId = require('../plugins/id.plugin');
10
10
 
@@ -5,7 +5,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
6
  exports.UserMobileAccess = void 0;
7
7
  const mongoose_1 = __importDefault(require("mongoose"));
8
- const _models_1 = require("../models/_models");
8
+ const _models_1 = require("./_models");
9
9
  const UserMobileAccessSchema = new mongoose_1.default.Schema({
10
10
  keycloakUserId: {
11
11
  type: String,
@@ -1,5 +1,6 @@
1
1
  import mongoose, { Model } from 'mongoose';
2
- import { MODEL_NAMES } from '../models/_models';
2
+
3
+ import { MODEL_NAMES } from './_models';
3
4
 
4
5
  export interface IUserMobileAccess {
5
6
  _id?: mongoose.Types.ObjectId;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "gemcap-be-common",
3
- "version": "1.2.135",
3
+ "version": "1.2.136",
4
4
  "description": "",
5
5
  "main": "index.js",
6
6
  "scripts": {
@@ -42,7 +42,7 @@ export declare class UsersService {
42
42
  getUserRepresentationById(authorization: string, userId: string): Promise<IKeycloakUser>;
43
43
  getUserRepresentationByUsername(authorization: string, username: string): Promise<IKeycloakUser>;
44
44
  getKeyCloakAdminBearer(): Promise<any>;
45
- getUserList(authorization: any): Promise<IKeycloakUser[]>;
45
+ getUserList(authorization: string): Promise<IKeycloakUser[]>;
46
46
  getUsersWithRoles(authorization: string): Promise<{
47
47
  keycloakUserId: string;
48
48
  _id: any;
@@ -55,12 +55,12 @@ export declare class UsersService {
55
55
  hasAccess: boolean;
56
56
  canSignDocument: boolean;
57
57
  };
58
+ email: string;
58
59
  firstName: string;
59
60
  lastName: string;
60
61
  roles?: IGroupedKeycloakRoles;
61
62
  username: string;
62
63
  enabled: boolean;
63
- email: string;
64
64
  emailVerified: boolean;
65
65
  access: {
66
66
  manageGroupMembership: boolean;
@@ -86,7 +86,7 @@ export declare class UsersService {
86
86
  getUserRoles(authorization: string, userId: string): Promise<{
87
87
  realmMappings: IKeycloakRole[];
88
88
  }>;
89
- createUser(authorization: any, user: any): Promise<any>;
89
+ createUser(authorization: string, user: any): Promise<any>;
90
90
  updateUser(authorization: string, userId: string, keyValue: any): Promise<any>;
91
91
  updateMobileUser(userId: string, keyValue: {
92
92
  [key: string]: string | number | boolean;
@@ -97,7 +97,7 @@ export declare class UsersService {
97
97
  resetPassword(authorization: string, userId: string, temporaryPassword: string): Promise<any>;
98
98
  createNewPasswordWithEmail(authorization: string, userId: string, newPassword: string): Promise<import("axios").AxiosResponse<any, any>>;
99
99
  deleteUser(authorization: string, userId: string): Promise<void>;
100
- getRoleList(authorization: any): Promise<IKeycloakRole[]>;
100
+ getRoleList(authorization: string): Promise<IKeycloakRole[]>;
101
101
  groupRoles(roles: IKeycloakRole[]): IGroupedKeycloakRoles;
102
102
  mapRolesToUsers(authorization: string, users: IKeycloakUser[]): Promise<{
103
103
  roles: IGroupedKeycloakRoles;
@@ -141,12 +141,12 @@ export declare class UsersService {
141
141
  hasAccess: boolean;
142
142
  canSignDocument: boolean;
143
143
  };
144
+ email: string;
144
145
  firstName: string;
145
146
  lastName: string;
146
147
  roles?: IGroupedKeycloakRoles;
147
148
  username: string;
148
149
  enabled: boolean;
149
- email: string;
150
150
  emailVerified: boolean;
151
151
  access: {
152
152
  manageGroupMembership: boolean;
@@ -9,12 +9,12 @@ const lodash_1 = __importDefault(require("lodash"));
9
9
  const axios_1 = __importDefault(require("axios"));
10
10
  const dayjs_1 = __importDefault(require("dayjs"));
11
11
  const mongoose_1 = __importDefault(require("mongoose"));
12
+ const qs_1 = __importDefault(require("qs"));
12
13
  const User_model_1 = require("../models/User.model");
13
- const user_logs_db_1 = require("../db/user-logs.db");
14
- const UserLog_model_1 = require("../models/UserLog.model");
15
14
  const BorrowerCompliance_model_1 = require("../models/BorrowerCompliance.model");
16
15
  const UserMobileAccess_model_1 = require("../models/UserMobileAccess.model");
17
- const request = require('request');
16
+ const UserLog_model_1 = require("../models/UserLog.model");
17
+ const user_logs_db_1 = require("../db/user-logs.db");
18
18
  class UsersService {
19
19
  config;
20
20
  constructor(config) {
@@ -48,8 +48,7 @@ class UsersService {
48
48
  },
49
49
  };
50
50
  const result = await axios_1.default.request(options);
51
- const user = result.data;
52
- return user;
51
+ return result.data;
53
52
  }
54
53
  async getUserRepresentationByUsername(authorization, username) {
55
54
  const options = {
@@ -64,52 +63,31 @@ class UsersService {
64
63
  const users = result.data;
65
64
  return users.find((user) => user.username === username);
66
65
  }
67
- getKeyCloakAdminBearer() {
68
- console.log('this in getKeyCloakAdminBearer:', this);
69
- console.log('this.config:', this?.config);
70
- return new Promise(function (resolve, reject) {
71
- const options = {
72
- method: 'POST',
73
- url: `${this.config.keycloakHost}/realms/master/protocol/openid-connect/token`,
74
- headers: {
75
- 'Content-Type': 'application/x-www-form-urlencoded',
76
- },
77
- form: {
78
- username: this.config.adminUser,
79
- password: this.config.adminPass,
80
- client_id: 'admin-cli',
81
- grant_type: 'password',
82
- },
83
- };
84
- request(options, (error, res, body) => {
85
- if (!error && res.statusCode === 200) {
86
- resolve(JSON.parse(body));
87
- }
88
- else {
89
- reject(error);
90
- }
91
- });
66
+ async getKeyCloakAdminBearer() {
67
+ const url = `${this.config.keycloakHost}/realms/master/protocol/openid-connect/token`;
68
+ const data = qs_1.default.stringify({
69
+ username: this.config.adminUser,
70
+ password: this.config.adminPass,
71
+ client_id: 'admin-cli',
72
+ grant_type: 'password',
92
73
  });
74
+ const headers = {
75
+ 'Content-Type': 'application/x-www-form-urlencoded',
76
+ };
77
+ const response = await axios_1.default.post(url, data, { headers });
78
+ return response.data;
93
79
  }
94
- getUserList(authorization) {
95
- return new Promise((resolve, reject) => {
96
- const options = {
97
- method: 'GET',
98
- url: `${this.config.keycloakHost}/admin/realms/${this.config.realm}/users`,
99
- headers: {
100
- 'Content-Type': 'application/json',
101
- Authorization: `Bearer ${authorization}`,
102
- },
103
- };
104
- request(options, (error, _res, body) => {
105
- if (!error) {
106
- resolve(JSON.parse(body));
107
- }
108
- else {
109
- reject(error);
110
- }
111
- });
112
- });
80
+ async getUserList(authorization) {
81
+ const options = {
82
+ method: 'GET',
83
+ url: `${this.config.keycloakHost}/admin/realms/${this.config.realm}/users`,
84
+ headers: {
85
+ 'Content-Type': 'application/json',
86
+ Authorization: `Bearer ${authorization}`,
87
+ },
88
+ };
89
+ const result = await axios_1.default.request(options);
90
+ return result.data;
113
91
  }
114
92
  async getUsersWithRoles(authorization) {
115
93
  const users = await this.getUserList(authorization);
@@ -123,73 +101,45 @@ class UsersService {
123
101
  }
124
102
  return usersAndAccess;
125
103
  }
126
- getUserRoles(authorization, userId) {
127
- return new Promise((resolve, reject) => {
128
- const options = {
129
- method: 'GET',
130
- url: `${this.config.keycloakHost}/admin/realms/${this.config.realm}/users/${userId}/role-mappings`,
131
- headers: {
132
- 'Content-Type': 'application/json',
133
- Authorization: `Bearer ${authorization}`,
134
- },
135
- };
136
- request(options, (error, _res, body) => {
137
- if (!error) {
138
- resolve(JSON.parse(body));
139
- }
140
- else {
141
- reject(error);
142
- }
143
- });
144
- });
104
+ async getUserRoles(authorization, userId) {
105
+ const options = {
106
+ method: 'GET',
107
+ url: `${this.config.keycloakHost}/admin/realms/${this.config.realm}/users/${userId}/role-mappings`,
108
+ headers: {
109
+ 'Content-Type': 'application/json',
110
+ Authorization: `Bearer ${authorization}`,
111
+ },
112
+ };
113
+ const result = await axios_1.default.request(options);
114
+ return result.data;
145
115
  }
146
- createUser(authorization, user) {
147
- return new Promise((resolve, reject) => {
148
- const options = {
149
- method: 'POST',
150
- url: `${this.config.keycloakHost}/admin/realms/${this.config.realm}/users`,
151
- headers: {
152
- 'Content-Type': 'application/json',
153
- Authorization: `Bearer ${authorization}`,
154
- },
155
- body: {
156
- ...user,
157
- },
158
- json: true,
159
- };
160
- request(options, (error, res, body) => {
161
- if (!error) {
162
- resolve(body);
163
- }
164
- else {
165
- console.error({ error });
166
- reject(error);
167
- }
168
- });
169
- });
116
+ async createUser(authorization, user) {
117
+ const options = {
118
+ method: 'POST',
119
+ url: `${this.config.keycloakHost}/admin/realms/${this.config.realm}/users`,
120
+ headers: {
121
+ 'Content-Type': 'application/json',
122
+ Authorization: `Bearer ${authorization}`,
123
+ },
124
+ data: {
125
+ ...user,
126
+ },
127
+ };
128
+ const result = await axios_1.default.request(options);
129
+ return result.data;
170
130
  }
171
- updateUser(authorization, userId, keyValue) {
172
- return new Promise((resolve, reject) => {
173
- const options = {
174
- method: 'PUT',
175
- url: `${this.config.keycloakHost}/admin/realms/${this.config.realm}/users/${userId}`,
176
- headers: {
177
- 'Content-Type': 'application/json',
178
- Authorization: `Bearer ${authorization}`,
179
- },
180
- body: keyValue,
181
- json: true,
182
- };
183
- request(options, (error, res, body) => {
184
- if (!error) {
185
- resolve(body);
186
- }
187
- else {
188
- console.error({ error });
189
- reject(error);
190
- }
191
- });
192
- });
131
+ async updateUser(authorization, userId, keyValue) {
132
+ const options = {
133
+ method: 'PUT',
134
+ url: `${this.config.keycloakHost}/admin/realms/${this.config.realm}/users/${userId}`,
135
+ headers: {
136
+ 'Content-Type': 'application/json',
137
+ Authorization: `Bearer ${authorization}`,
138
+ },
139
+ data: keyValue,
140
+ };
141
+ const result = await axios_1.default.request(options);
142
+ return result.data;
193
143
  }
194
144
  async updateMobileUser(userId, keyValue) {
195
145
  await UserMobileAccess_model_1.UserMobileAccess.findOneAndUpdate({ keycloakUserId: userId }, keyValue, { upsert: true });
@@ -198,74 +148,44 @@ class UsersService {
198
148
  await User_model_1.UserModel
199
149
  .findOneAndUpdate({ keycloakUserId }, userAccess);
200
150
  }
201
- removeUserRoles(authorization, userId, roles) {
202
- return new Promise((resolve, reject) => {
203
- const options = {
204
- method: 'DELETE',
205
- url: `${this.config.keycloakHost}/admin/realms/${this.config.realm}/users/${userId}/role-mappings/realm`,
206
- headers: {
207
- 'Content-Type': 'application/json',
208
- Authorization: `Bearer ${authorization}`,
209
- },
210
- body: [...roles],
211
- json: true,
212
- };
213
- request(options, (error, res, body) => {
214
- if (!error) {
215
- resolve(body);
216
- }
217
- else {
218
- console.error({ error });
219
- reject(error);
220
- }
221
- });
222
- });
151
+ async removeUserRoles(authorization, userId, roles) {
152
+ const options = {
153
+ method: 'DELETE',
154
+ url: `${this.config.keycloakHost}/admin/realms/${this.config.realm}/users/${userId}/role-mappings/realm`,
155
+ headers: {
156
+ 'Content-Type': 'application/json',
157
+ Authorization: `Bearer ${authorization}`,
158
+ },
159
+ data: [...roles],
160
+ };
161
+ const result = await axios_1.default.request(options);
162
+ return result.data;
223
163
  }
224
- addUserRoles(authorization, userId, roles) {
225
- return new Promise((resolve, reject) => {
226
- const options = {
227
- method: 'POST',
228
- url: `${this.config.keycloakHost}/admin/realms/${this.config.realm}/users/${userId}/role-mappings/realm`,
229
- headers: {
230
- 'Content-Type': 'application/json',
231
- Authorization: `Bearer ${authorization}`,
232
- },
233
- body: [...roles],
234
- json: true,
235
- };
236
- request(options, (error, res, body) => {
237
- if (!error) {
238
- resolve(body);
239
- }
240
- else {
241
- console.error({ error });
242
- reject(error);
243
- }
244
- });
245
- });
164
+ async addUserRoles(authorization, userId, roles) {
165
+ const options = {
166
+ method: 'POST',
167
+ url: `${this.config.keycloakHost}/admin/realms/${this.config.realm}/users/${userId}/role-mappings/realm`,
168
+ headers: {
169
+ 'Content-Type': 'application/json',
170
+ Authorization: `Bearer ${authorization}`,
171
+ },
172
+ data: [...roles],
173
+ };
174
+ const result = await axios_1.default.request(options);
175
+ return result.data;
246
176
  }
247
- resetPassword(authorization, userId, temporaryPassword) {
248
- return new Promise((resolve, reject) => {
249
- const options = {
250
- method: 'PUT',
251
- url: `${this.config.keycloakHost}/admin/realms/${this.config.realm}/users/${userId}/reset-password`,
252
- headers: {
253
- 'Content-Type': 'application/json',
254
- Authorization: `Bearer ${authorization}`,
255
- },
256
- body: { value: temporaryPassword, temporary: true },
257
- json: true,
258
- };
259
- request(options, (error, res, body) => {
260
- if (!error) {
261
- resolve(body);
262
- }
263
- else {
264
- console.error({ error });
265
- reject(error);
266
- }
267
- });
268
- });
177
+ async resetPassword(authorization, userId, temporaryPassword) {
178
+ const options = {
179
+ method: 'PUT',
180
+ url: `${this.config.keycloakHost}/admin/realms/${this.config.realm}/users/${userId}/reset-password`,
181
+ headers: {
182
+ 'Content-Type': 'application/json',
183
+ Authorization: `Bearer ${authorization}`,
184
+ },
185
+ data: { value: temporaryPassword, temporary: true },
186
+ };
187
+ const result = await axios_1.default.request(options);
188
+ return result.data;
269
189
  }
270
190
  async createNewPasswordWithEmail(authorization, userId, newPassword) {
271
191
  const options = {
@@ -305,26 +225,17 @@ class UsersService {
305
225
  console.log(error);
306
226
  }
307
227
  }
308
- getRoleList(authorization) {
309
- return new Promise((resolve, reject) => {
310
- const options = {
311
- method: 'GET',
312
- url: `${this.config.keycloakHost}/admin/realms/${this.config.realm}/roles`,
313
- headers: {
314
- 'Content-Type': 'application/json',
315
- Authorization: `Bearer ${authorization}`,
316
- },
317
- };
318
- request(options, (error, _res, body) => {
319
- if (!error) {
320
- resolve(JSON.parse(body));
321
- }
322
- else {
323
- console.error({ error });
324
- reject(error);
325
- }
326
- });
327
- });
228
+ async getRoleList(authorization) {
229
+ const options = {
230
+ method: 'GET',
231
+ url: `${this.config.keycloakHost}/admin/realms/${this.config.realm}/roles`,
232
+ headers: {
233
+ 'Content-Type': 'application/json',
234
+ Authorization: `Bearer ${authorization}`,
235
+ },
236
+ };
237
+ const result = await axios_1.default.request(options);
238
+ return result.data;
328
239
  }
329
240
  groupRoles(roles) {
330
241
  return roles.reduce((acc, role) => {