gemcap-be-common 1.2.134 → 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.134",
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;
@@ -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;
@@ -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,50 +63,31 @@ class UsersService {
64
63
  const users = result.data;
65
64
  return users.find((user) => user.username === username);
66
65
  }
67
- getKeyCloakAdminBearer() {
68
- return new Promise(function (resolve, reject) {
69
- const options = {
70
- method: 'POST',
71
- url: `${this.config.keycloakHost}/realms/master/protocol/openid-connect/token`,
72
- headers: {
73
- 'Content-Type': 'application/x-www-form-urlencoded',
74
- },
75
- form: {
76
- username: this.config.adminUser,
77
- password: this.config.adminPass,
78
- client_id: 'admin-cli',
79
- grant_type: 'password',
80
- },
81
- };
82
- request(options, (error, res, body) => {
83
- if (!error && res.statusCode === 200) {
84
- resolve(JSON.parse(body));
85
- }
86
- else {
87
- reject(error);
88
- }
89
- });
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',
90
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;
91
79
  }
92
- getUserList(authorization) {
93
- return new Promise((resolve, reject) => {
94
- const options = {
95
- method: 'GET',
96
- url: `${this.config.keycloakHost}/admin/realms/${this.config.realm}/users`,
97
- headers: {
98
- 'Content-Type': 'application/json',
99
- Authorization: `Bearer ${authorization}`,
100
- },
101
- };
102
- request(options, (error, _res, body) => {
103
- if (!error) {
104
- resolve(JSON.parse(body));
105
- }
106
- else {
107
- reject(error);
108
- }
109
- });
110
- });
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;
111
91
  }
112
92
  async getUsersWithRoles(authorization) {
113
93
  const users = await this.getUserList(authorization);
@@ -121,73 +101,45 @@ class UsersService {
121
101
  }
122
102
  return usersAndAccess;
123
103
  }
124
- getUserRoles(authorization, userId) {
125
- return new Promise((resolve, reject) => {
126
- const options = {
127
- method: 'GET',
128
- url: `${this.config.keycloakHost}/admin/realms/${this.config.realm}/users/${userId}/role-mappings`,
129
- headers: {
130
- 'Content-Type': 'application/json',
131
- Authorization: `Bearer ${authorization}`,
132
- },
133
- };
134
- request(options, (error, _res, body) => {
135
- if (!error) {
136
- resolve(JSON.parse(body));
137
- }
138
- else {
139
- reject(error);
140
- }
141
- });
142
- });
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;
143
115
  }
144
- createUser(authorization, user) {
145
- return new Promise((resolve, reject) => {
146
- const options = {
147
- method: 'POST',
148
- url: `${this.config.keycloakHost}/admin/realms/${this.config.realm}/users`,
149
- headers: {
150
- 'Content-Type': 'application/json',
151
- Authorization: `Bearer ${authorization}`,
152
- },
153
- body: {
154
- ...user,
155
- },
156
- json: true,
157
- };
158
- request(options, (error, res, body) => {
159
- if (!error) {
160
- resolve(body);
161
- }
162
- else {
163
- console.error({ error });
164
- reject(error);
165
- }
166
- });
167
- });
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;
168
130
  }
169
- updateUser(authorization, userId, keyValue) {
170
- return new Promise((resolve, reject) => {
171
- const options = {
172
- method: 'PUT',
173
- url: `${this.config.keycloakHost}/admin/realms/${this.config.realm}/users/${userId}`,
174
- headers: {
175
- 'Content-Type': 'application/json',
176
- Authorization: `Bearer ${authorization}`,
177
- },
178
- body: keyValue,
179
- json: true,
180
- };
181
- request(options, (error, res, body) => {
182
- if (!error) {
183
- resolve(body);
184
- }
185
- else {
186
- console.error({ error });
187
- reject(error);
188
- }
189
- });
190
- });
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;
191
143
  }
192
144
  async updateMobileUser(userId, keyValue) {
193
145
  await UserMobileAccess_model_1.UserMobileAccess.findOneAndUpdate({ keycloakUserId: userId }, keyValue, { upsert: true });
@@ -196,74 +148,44 @@ class UsersService {
196
148
  await User_model_1.UserModel
197
149
  .findOneAndUpdate({ keycloakUserId }, userAccess);
198
150
  }
199
- removeUserRoles(authorization, userId, roles) {
200
- return new Promise((resolve, reject) => {
201
- const options = {
202
- method: 'DELETE',
203
- url: `${this.config.keycloakHost}/admin/realms/${this.config.realm}/users/${userId}/role-mappings/realm`,
204
- headers: {
205
- 'Content-Type': 'application/json',
206
- Authorization: `Bearer ${authorization}`,
207
- },
208
- body: [...roles],
209
- json: true,
210
- };
211
- request(options, (error, res, body) => {
212
- if (!error) {
213
- resolve(body);
214
- }
215
- else {
216
- console.error({ error });
217
- reject(error);
218
- }
219
- });
220
- });
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;
221
163
  }
222
- addUserRoles(authorization, userId, roles) {
223
- return new Promise((resolve, reject) => {
224
- const options = {
225
- method: 'POST',
226
- url: `${this.config.keycloakHost}/admin/realms/${this.config.realm}/users/${userId}/role-mappings/realm`,
227
- headers: {
228
- 'Content-Type': 'application/json',
229
- Authorization: `Bearer ${authorization}`,
230
- },
231
- body: [...roles],
232
- json: true,
233
- };
234
- request(options, (error, res, body) => {
235
- if (!error) {
236
- resolve(body);
237
- }
238
- else {
239
- console.error({ error });
240
- reject(error);
241
- }
242
- });
243
- });
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;
244
176
  }
245
- resetPassword(authorization, userId, temporaryPassword) {
246
- return new Promise((resolve, reject) => {
247
- const options = {
248
- method: 'PUT',
249
- url: `${this.config.keycloakHost}/admin/realms/${this.config.realm}/users/${userId}/reset-password`,
250
- headers: {
251
- 'Content-Type': 'application/json',
252
- Authorization: `Bearer ${authorization}`,
253
- },
254
- body: { value: temporaryPassword, temporary: true },
255
- json: true,
256
- };
257
- request(options, (error, res, body) => {
258
- if (!error) {
259
- resolve(body);
260
- }
261
- else {
262
- console.error({ error });
263
- reject(error);
264
- }
265
- });
266
- });
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;
267
189
  }
268
190
  async createNewPasswordWithEmail(authorization, userId, newPassword) {
269
191
  const options = {
@@ -303,26 +225,17 @@ class UsersService {
303
225
  console.log(error);
304
226
  }
305
227
  }
306
- getRoleList(authorization) {
307
- return new Promise((resolve, reject) => {
308
- const options = {
309
- method: 'GET',
310
- url: `${this.config.keycloakHost}/admin/realms/${this.config.realm}/roles`,
311
- headers: {
312
- 'Content-Type': 'application/json',
313
- Authorization: `Bearer ${authorization}`,
314
- },
315
- };
316
- request(options, (error, _res, body) => {
317
- if (!error) {
318
- resolve(JSON.parse(body));
319
- }
320
- else {
321
- console.error({ error });
322
- reject(error);
323
- }
324
- });
325
- });
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;
326
239
  }
327
240
  groupRoles(roles) {
328
241
  return roles.reduce((acc, role) => {