@tomei/sso 0.1.2 → 0.2.1

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.
Files changed (212) hide show
  1. package/README.md +7 -2
  2. package/__tests__/unit/components/login-history/login-history.repository.spec.ts +95 -0
  3. package/__tests__/unit/components/login-user/login-user.spec.ts +223 -0
  4. package/__tests__/unit/components/login-user/user.repository.spec.ts +81 -0
  5. package/__tests__/unit/components/password-hash/password-hash.service.spec.ts +33 -0
  6. package/__tests__/unit/components/system/system.repository.spec.ts +88 -0
  7. package/__tests__/unit/components/system-access/system-access.repository.spec.ts +78 -0
  8. package/__tests__/unit/redis-client/redis.service.spec.ts +24 -0
  9. package/__tests__/unit/session/session.service.spec.ts +27 -0
  10. package/create-sso-user.sql +1 -0
  11. package/dist/__tests__/unit/components/login-history/login-history.repository.spec.d.ts +1 -0
  12. package/dist/__tests__/unit/components/login-history/login-history.repository.spec.js +99 -0
  13. package/dist/__tests__/unit/components/login-history/login-history.repository.spec.js.map +1 -0
  14. package/dist/__tests__/unit/components/login-user/login-user.spec.d.ts +1 -0
  15. package/dist/__tests__/unit/components/login-user/login-user.spec.js +208 -0
  16. package/dist/__tests__/unit/components/login-user/login-user.spec.js.map +1 -0
  17. package/dist/__tests__/unit/components/login-user/user.repository.spec.d.ts +1 -0
  18. package/dist/__tests__/unit/components/login-user/user.repository.spec.js +78 -0
  19. package/dist/__tests__/unit/components/login-user/user.repository.spec.js.map +1 -0
  20. package/dist/__tests__/unit/components/password-hash/password-hash.service.spec.d.ts +1 -0
  21. package/dist/__tests__/unit/components/password-hash/password-hash.service.spec.js +38 -0
  22. package/dist/__tests__/unit/components/password-hash/password-hash.service.spec.js.map +1 -0
  23. package/dist/__tests__/unit/components/system/system.repository.spec.d.ts +1 -0
  24. package/dist/__tests__/unit/components/system/system.repository.spec.js +85 -0
  25. package/dist/__tests__/unit/components/system/system.repository.spec.js.map +1 -0
  26. package/dist/__tests__/unit/components/system-access/system-access.repository.spec.d.ts +1 -0
  27. package/dist/__tests__/unit/components/system-access/system-access.repository.spec.js +75 -0
  28. package/dist/__tests__/unit/components/system-access/system-access.repository.spec.js.map +1 -0
  29. package/dist/__tests__/unit/redis-client/redis.service.spec.d.ts +1 -0
  30. package/dist/__tests__/unit/redis-client/redis.service.spec.js +32 -0
  31. package/dist/__tests__/unit/redis-client/redis.service.spec.js.map +1 -0
  32. package/dist/__tests__/unit/session/session.service.spec.d.ts +1 -0
  33. package/dist/__tests__/unit/session/session.service.spec.js +36 -0
  34. package/dist/__tests__/unit/session/session.service.spec.js.map +1 -0
  35. package/dist/index.d.ts +1 -0
  36. package/dist/index.js +17 -0
  37. package/dist/index.js.map +1 -1
  38. package/dist/src/components/index.d.ts +7 -0
  39. package/dist/src/components/index.js +24 -0
  40. package/dist/src/components/index.js.map +1 -0
  41. package/dist/src/components/login-history/index.d.ts +1 -0
  42. package/dist/src/components/login-history/index.js +18 -0
  43. package/dist/src/components/login-history/index.js.map +1 -0
  44. package/dist/src/components/login-history/login-history.repository.d.ts +9 -0
  45. package/dist/src/components/login-history/login-history.repository.js +50 -0
  46. package/dist/src/components/login-history/login-history.repository.js.map +1 -0
  47. package/dist/src/components/login-user/index.d.ts +3 -0
  48. package/dist/src/components/login-user/index.js +20 -0
  49. package/dist/src/components/login-user/index.js.map +1 -0
  50. package/dist/src/components/login-user/interfaces/index.d.ts +1 -0
  51. package/dist/src/components/login-user/interfaces/index.js +18 -0
  52. package/dist/src/components/login-user/interfaces/index.js.map +1 -0
  53. package/dist/src/components/login-user/interfaces/user-info.interface.d.ts +9 -0
  54. package/dist/src/components/login-user/interfaces/user-info.interface.js +3 -0
  55. package/dist/src/components/login-user/interfaces/user-info.interface.js.map +1 -0
  56. package/dist/src/components/login-user/login-user.d.ts +41 -0
  57. package/dist/src/components/login-user/login-user.js +332 -0
  58. package/dist/src/components/login-user/login-user.js.map +1 -0
  59. package/dist/src/components/login-user/user.repository.d.ts +9 -0
  60. package/dist/src/components/login-user/user.repository.js +50 -0
  61. package/dist/src/components/login-user/user.repository.js.map +1 -0
  62. package/dist/src/components/password-hash/index.d.ts +2 -0
  63. package/dist/src/components/password-hash/index.js +19 -0
  64. package/dist/src/components/password-hash/index.js.map +1 -0
  65. package/dist/src/components/password-hash/interfaces/index.d.ts +1 -0
  66. package/dist/src/components/password-hash/interfaces/index.js +18 -0
  67. package/dist/src/components/password-hash/interfaces/index.js.map +1 -0
  68. package/dist/src/components/password-hash/interfaces/password-hash-service.interface.d.ts +4 -0
  69. package/dist/src/components/password-hash/interfaces/password-hash-service.interface.js +3 -0
  70. package/dist/src/components/password-hash/interfaces/password-hash-service.interface.js.map +1 -0
  71. package/dist/src/components/password-hash/password-hash.service.d.ts +6 -0
  72. package/dist/src/components/password-hash/password-hash.service.js +28 -0
  73. package/dist/src/components/password-hash/password-hash.service.js.map +1 -0
  74. package/dist/src/components/system/index.d.ts +1 -0
  75. package/dist/src/components/system/index.js +18 -0
  76. package/dist/src/components/system/index.js.map +1 -0
  77. package/dist/src/components/system/system.repository.d.ts +9 -0
  78. package/dist/src/components/system/system.repository.js +50 -0
  79. package/dist/src/components/system/system.repository.js.map +1 -0
  80. package/dist/src/components/system-access/index.d.ts +1 -0
  81. package/dist/src/components/system-access/index.js +18 -0
  82. package/dist/src/components/system-access/index.js.map +1 -0
  83. package/dist/src/components/system-access/system-access.repository.d.ts +9 -0
  84. package/dist/src/components/system-access/system-access.repository.js +50 -0
  85. package/dist/src/components/system-access/system-access.repository.js.map +1 -0
  86. package/dist/src/components/user-group/index.d.ts +1 -0
  87. package/dist/src/components/user-group/index.js +18 -0
  88. package/dist/src/components/user-group/index.js.map +1 -0
  89. package/dist/src/components/user-group/user-group.repository.d.ts +9 -0
  90. package/dist/src/components/user-group/user-group.repository.js +50 -0
  91. package/dist/src/components/user-group/user-group.repository.js.map +1 -0
  92. package/dist/src/components/user-user-group/index.d.ts +1 -0
  93. package/dist/src/components/user-user-group/index.js +18 -0
  94. package/dist/src/components/user-user-group/index.js.map +1 -0
  95. package/dist/src/components/user-user-group/user-user-group.repository.d.ts +9 -0
  96. package/dist/src/components/user-user-group/user-user-group.repository.js +50 -0
  97. package/dist/src/components/user-user-group/user-user-group.repository.js.map +1 -0
  98. package/dist/src/index.d.ts +6 -0
  99. package/dist/src/index.js +24 -0
  100. package/dist/src/index.js.map +1 -0
  101. package/dist/src/interfaces/index.d.ts +2 -0
  102. package/dist/src/interfaces/index.js +19 -0
  103. package/dist/src/interfaces/index.js.map +1 -0
  104. package/dist/src/interfaces/system-login.interface.d.ts +6 -0
  105. package/dist/src/interfaces/system-login.interface.js +3 -0
  106. package/dist/src/interfaces/system-login.interface.js.map +1 -0
  107. package/dist/src/interfaces/user-session.interface.d.ts +4 -0
  108. package/dist/src/interfaces/user-session.interface.js +3 -0
  109. package/dist/src/interfaces/user-session.interface.js.map +1 -0
  110. package/dist/src/mail/index.d.ts +2 -0
  111. package/dist/src/mail/index.js +19 -0
  112. package/dist/src/mail/index.js.map +1 -0
  113. package/dist/src/mail/interfaces/index.d.ts +2 -0
  114. package/dist/src/mail/interfaces/index.js +19 -0
  115. package/dist/src/mail/interfaces/index.js.map +1 -0
  116. package/dist/src/mail/interfaces/send-mail.interface.d.ts +8 -0
  117. package/dist/src/mail/interfaces/send-mail.interface.js +3 -0
  118. package/dist/src/mail/interfaces/send-mail.interface.js.map +1 -0
  119. package/dist/src/mail/interfaces/send-new-login-alert.interface.d.ts +6 -0
  120. package/dist/src/mail/interfaces/send-new-login-alert.interface.js +3 -0
  121. package/dist/src/mail/interfaces/send-new-login-alert.interface.js.map +1 -0
  122. package/dist/src/mail/mail.d.ts +7 -0
  123. package/dist/src/mail/mail.js +49 -0
  124. package/dist/src/mail/mail.js.map +1 -0
  125. package/dist/src/mail/mail.service.d.ts +7 -0
  126. package/dist/src/mail/mail.service.js +42 -0
  127. package/dist/src/mail/mail.service.js.map +1 -0
  128. package/dist/src/prisma-client/__mocks__/prisma.d.ts +3 -0
  129. package/dist/src/prisma-client/__mocks__/prisma.js +14 -0
  130. package/dist/src/prisma-client/__mocks__/prisma.js.map +1 -0
  131. package/dist/src/prisma-client/client.d.ts +3 -0
  132. package/dist/src/prisma-client/client.js +6 -0
  133. package/dist/src/prisma-client/client.js.map +1 -0
  134. package/dist/src/prisma-client/index.d.ts +1 -0
  135. package/dist/src/prisma-client/index.js +18 -0
  136. package/dist/src/prisma-client/index.js.map +1 -0
  137. package/dist/src/redis-client/__mocks__/jest-initial-setup.d.ts +1 -0
  138. package/dist/src/redis-client/__mocks__/jest-initial-setup.js +5 -0
  139. package/dist/src/redis-client/__mocks__/jest-initial-setup.js.map +1 -0
  140. package/dist/src/redis-client/__mocks__/redis-mock.d.ts +2 -0
  141. package/dist/src/redis-client/__mocks__/redis-mock.js +23 -0
  142. package/dist/src/redis-client/__mocks__/redis-mock.js.map +1 -0
  143. package/dist/src/redis-client/index.d.ts +1 -0
  144. package/dist/src/redis-client/index.js +18 -0
  145. package/dist/src/redis-client/index.js.map +1 -0
  146. package/dist/src/redis-client/redis.service.d.ts +7 -0
  147. package/dist/src/redis-client/redis.service.js +56 -0
  148. package/dist/src/redis-client/redis.service.js.map +1 -0
  149. package/dist/src/session/index.d.ts +2 -0
  150. package/dist/src/session/index.js +19 -0
  151. package/dist/src/session/index.js.map +1 -0
  152. package/dist/src/session/interfaces/index.d.ts +1 -0
  153. package/dist/src/session/interfaces/index.js +18 -0
  154. package/dist/src/session/interfaces/index.js.map +1 -0
  155. package/dist/src/session/interfaces/session-service.interface.d.ts +5 -0
  156. package/dist/src/session/interfaces/session-service.interface.js +3 -0
  157. package/dist/src/session/interfaces/session-service.interface.js.map +1 -0
  158. package/dist/src/session/session.service.d.ts +9 -0
  159. package/dist/src/session/session.service.js +52 -0
  160. package/dist/src/session/session.service.js.map +1 -0
  161. package/dist/tsconfig.tsbuildinfo +1 -1
  162. package/index.ts +1 -0
  163. package/jest.config.js +15 -0
  164. package/package.json +21 -3
  165. package/prisma/migrations/0_init/migration.sql +41 -42
  166. package/prisma/migrations/20230528161352_create_user_user_group_and_add_new_column/migration.sql +2 -2
  167. package/prisma/migrations/20230606091407_create_login_histories_table/migration.sql +17 -0
  168. package/prisma/schema.prisma +46 -33
  169. package/sampledotenv +8 -0
  170. package/src/components/index.ts +7 -0
  171. package/src/components/login-history/index.ts +1 -0
  172. package/src/components/login-history/login-history.repository.ts +33 -0
  173. package/src/components/login-user/index.ts +4 -0
  174. package/src/components/login-user/interfaces/index.ts +1 -0
  175. package/src/components/login-user/interfaces/user-info.interface.ts +9 -0
  176. package/src/components/login-user/login-user.ts +427 -0
  177. package/src/components/login-user/user.repository.ts +33 -0
  178. package/src/components/password-hash/index.ts +2 -0
  179. package/src/components/password-hash/interfaces/index.ts +1 -0
  180. package/src/components/password-hash/interfaces/password-hash-service.interface.ts +4 -0
  181. package/src/components/password-hash/password-hash.service.ts +14 -0
  182. package/src/components/system/index.ts +1 -0
  183. package/src/components/system/system.repository.ts +33 -0
  184. package/src/components/system-access/index.ts +1 -0
  185. package/src/components/system-access/system-access.repository.ts +33 -0
  186. package/src/components/user-group/index.ts +1 -0
  187. package/src/components/user-group/user-group.repository.ts +33 -0
  188. package/src/components/user-user-group/index.ts +1 -0
  189. package/src/components/user-user-group/user-user-group.repository.ts +33 -0
  190. package/src/index.ts +7 -0
  191. package/src/interfaces/index.ts +2 -0
  192. package/src/interfaces/system-login.interface.ts +6 -0
  193. package/src/interfaces/user-session.interface.ts +5 -0
  194. package/src/mail/index.ts +2 -0
  195. package/src/mail/interfaces/index.ts +2 -0
  196. package/src/mail/interfaces/send-mail.interface.ts +8 -0
  197. package/src/mail/interfaces/send-new-login-alert.interface.ts +6 -0
  198. package/src/mail/mail.service.ts +33 -0
  199. package/src/mail/mail.ts +40 -0
  200. package/src/prisma-client/__mocks__/prisma.ts +15 -0
  201. package/src/prisma-client/client.ts +3 -0
  202. package/src/prisma-client/index.ts +1 -0
  203. package/src/redis-client/__mocks__/jest-initial-setup.ts +2 -0
  204. package/src/redis-client/__mocks__/redis-mock.ts +28 -0
  205. package/src/redis-client/index.ts +1 -0
  206. package/src/redis-client/redis.service.ts +48 -0
  207. package/src/session/index.ts +2 -0
  208. package/src/session/interfaces/index.ts +1 -0
  209. package/src/session/interfaces/session-service.interface.ts +6 -0
  210. package/src/session/session.service.ts +45 -0
  211. package/tsconfig.build.json +2 -1
  212. package/tsconfig.json +5 -4
@@ -0,0 +1,332 @@
1
+ "use strict";
2
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
+ return new (P || (P = Promise))(function (resolve, reject) {
5
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
9
+ });
10
+ };
11
+ Object.defineProperty(exports, "__esModule", { value: true });
12
+ exports.LoginUser = void 0;
13
+ const general_1 = require("@tomei/general");
14
+ const user_repository_1 = require("./user.repository");
15
+ const system_repository_1 = require("../system/system.repository");
16
+ const system_access_repository_1 = require("../system-access/system-access.repository");
17
+ const login_history_repository_1 = require("../login-history/login-history.repository");
18
+ const mail_service_1 = require("../../mail/mail.service");
19
+ const user_user_group_repository_1 = require("../user-user-group/user-user-group.repository");
20
+ const password_hash_service_1 = require("../password-hash/password-hash.service");
21
+ const session_service_1 = require("../../session/session.service");
22
+ const user_group_repository_1 = require("../user-group/user-group.repository");
23
+ class LoginUser extends general_1.ObjectBase {
24
+ getDetails() {
25
+ return {
26
+ FullName: this.FullName,
27
+ IDNo: this.IDNo,
28
+ IDType: this.IDType,
29
+ Email: this.Email,
30
+ ContactNo: this.ContactNo,
31
+ };
32
+ }
33
+ constructor(sessionService, dbTransaction, userInfo) {
34
+ super();
35
+ this.ObjectName = 'User';
36
+ this.TableName = 'sso_users';
37
+ this._PasswordHashService = new password_hash_service_1.PasswordHashService();
38
+ this._MailService = new mail_service_1.MailService();
39
+ this._SessionService = sessionService;
40
+ if (dbTransaction) {
41
+ LoginUser._Repository = new user_repository_1.UserRepository(dbTransaction);
42
+ LoginUser._SystemRepository = new system_repository_1.SystemRepository(dbTransaction);
43
+ LoginUser._SystemAccessRepository = new system_access_repository_1.SystemAccessRepository(dbTransaction);
44
+ LoginUser._LoginHistoryRepository = new login_history_repository_1.LoginHistoryRepository(dbTransaction);
45
+ LoginUser._UserUserGroupRepository = new user_user_group_repository_1.UserUserGroupRepository(dbTransaction);
46
+ LoginUser._UserGroupRepository = new user_group_repository_1.UserGroupRepository(dbTransaction);
47
+ }
48
+ if (userInfo) {
49
+ this.ObjectId = userInfo.ObjectId;
50
+ this.FullName = userInfo.FullName;
51
+ this.IDNo = userInfo.IDNo;
52
+ this.Email = userInfo.Email;
53
+ this.ContactNo = userInfo.ContactNo;
54
+ this.Password = userInfo.Password;
55
+ this.staffs = userInfo.staffs;
56
+ }
57
+ }
58
+ static init(userId, dbTransaction = null) {
59
+ return __awaiter(this, void 0, void 0, function* () {
60
+ const sessionService = yield session_service_1.SessionService.init();
61
+ if (userId) {
62
+ if (dbTransaction) {
63
+ LoginUser._Repository = new user_repository_1.UserRepository(dbTransaction);
64
+ }
65
+ const user = yield LoginUser._Repository.findOne({
66
+ where: {
67
+ id: Number(userId),
68
+ },
69
+ include: {
70
+ staffs: true,
71
+ userSystemPrivileges: {
72
+ include: {
73
+ systemPrivilege: true,
74
+ },
75
+ },
76
+ },
77
+ });
78
+ if (user) {
79
+ const userInfo = {
80
+ ObjectId: user.id,
81
+ FullName: user.staffs[0].name,
82
+ IDNo: user.staffs[0].idNo,
83
+ ContactNo: user.staffs[0].contactNo,
84
+ Email: user.staffs[0].email,
85
+ Password: user.password,
86
+ staffs: user.staffs[0],
87
+ };
88
+ return new LoginUser(sessionService, dbTransaction, userInfo);
89
+ }
90
+ else {
91
+ throw new Error('User not found');
92
+ }
93
+ }
94
+ return new LoginUser(sessionService, dbTransaction);
95
+ });
96
+ }
97
+ login(systemCode, email, password, ipAddress) {
98
+ return __awaiter(this, void 0, void 0, function* () {
99
+ if (this.Email !== email) {
100
+ throw new Error('Invalid credentials.');
101
+ }
102
+ const isPasswordValid = yield this._PasswordHashService.verify(password, this.Password);
103
+ if (!isPasswordValid) {
104
+ throw new Error('Invalid credentials.');
105
+ }
106
+ const system = yield LoginUser._SystemRepository.findOne({
107
+ where: {
108
+ code: systemCode,
109
+ },
110
+ });
111
+ if (!system) {
112
+ throw new Error('Invalid system code.');
113
+ }
114
+ yield this.checkSystemAccess(this.ObjectId, system.id);
115
+ yield this.alertNewLogin(this.ObjectId, system.id, ipAddress);
116
+ const userSession = yield this._SessionService.retrieveUserSession(this.ObjectId);
117
+ let systemLogin = userSession.systemLogins.find((system) => system.code === systemCode);
118
+ const { randomUUID } = require('crypto');
119
+ const sessionId = randomUUID();
120
+ if (systemLogin) {
121
+ systemLogin = systemLogin.sessionId = sessionId;
122
+ userSession.systemLogins.map((system) => system.code === systemCode ? systemLogin : system);
123
+ }
124
+ else {
125
+ const newLogin = {
126
+ id: system.id.toString(),
127
+ code: system.code,
128
+ sessionId: sessionId,
129
+ privileges: yield this.getPrivileges(system.code),
130
+ };
131
+ userSession.systemLogins.push(newLogin);
132
+ }
133
+ this._SessionService.setUserSession(this.ObjectId, userSession);
134
+ yield LoginUser._LoginHistoryRepository.create({
135
+ data: {
136
+ userId: this.ObjectId,
137
+ systemId: system.id,
138
+ originIp: ipAddress,
139
+ createdAt: new Date(),
140
+ },
141
+ });
142
+ return sessionId;
143
+ });
144
+ }
145
+ checkSystemAccess(userId, systemId) {
146
+ return __awaiter(this, void 0, void 0, function* () {
147
+ const systemAccess = yield LoginUser._SystemAccessRepository.findOne({
148
+ where: {
149
+ userId: userId,
150
+ systemId: systemId,
151
+ },
152
+ });
153
+ if (!systemAccess) {
154
+ throw new Error("User don't have access to the system.");
155
+ }
156
+ });
157
+ }
158
+ alertNewLogin(userId, systemId, ipAddress) {
159
+ return __awaiter(this, void 0, void 0, function* () {
160
+ const userLogins = yield LoginUser._LoginHistoryRepository.findAll({
161
+ where: {
162
+ userId: userId,
163
+ systemId: systemId,
164
+ },
165
+ });
166
+ const gotPreviousLogins = (userLogins === null || userLogins === void 0 ? void 0 : userLogins.length) !== 0;
167
+ let ipFound = null;
168
+ if (gotPreviousLogins) {
169
+ ipFound = userLogins.find((item) => item.ipAddress === ipAddress);
170
+ }
171
+ if (gotPreviousLogins && !ipFound) {
172
+ yield this._MailService.sendNewLoginAlertEmail({
173
+ IpAddress: ipAddress,
174
+ Email: this.Email,
175
+ Name: this.FullName,
176
+ LoginDate: new Date(),
177
+ });
178
+ }
179
+ });
180
+ }
181
+ getPrivileges(systemCode) {
182
+ return __awaiter(this, void 0, void 0, function* () {
183
+ try {
184
+ const system = yield LoginUser._SystemRepository.findOne({
185
+ where: {
186
+ code: systemCode,
187
+ },
188
+ });
189
+ if (!system) {
190
+ throw new Error('Invalid system code.');
191
+ }
192
+ const userUserGroups = yield this.getUserUserGroupFromDB(system.id);
193
+ const userGroupData = userUserGroups.map((u) => u.userGroup);
194
+ let privileges = [];
195
+ for (const userGroup of userGroupData) {
196
+ const groupSystemPrivileges = userGroup.groupSystemPrivileges.map((g) => g.systemPrivilege.code);
197
+ const groupRolePrivileges = userGroup.groupRolePrivileges.map((g) => g.systemPrivilege.code);
198
+ if (userGroup.groupLevel !== 0) {
199
+ const parentTreePrivileges = yield this.getPrivilegesFromUserGroup(userGroup.parentCode);
200
+ privileges = [...privileges, ...parentTreePrivileges];
201
+ }
202
+ privileges = [
203
+ ...privileges,
204
+ ...groupSystemPrivileges,
205
+ ...groupRolePrivileges,
206
+ ];
207
+ }
208
+ const userPrivileges = yield this.getUserPersonalPrivileges(system.id);
209
+ privileges = [...privileges, ...userPrivileges];
210
+ privileges = [...new Set(privileges)];
211
+ return privileges;
212
+ }
213
+ catch (error) {
214
+ throw error;
215
+ }
216
+ });
217
+ }
218
+ getPrivilegesFromUserGroup(groupCode) {
219
+ return __awaiter(this, void 0, void 0, function* () {
220
+ try {
221
+ const userGroup = yield this.getUserGroupFromDB(groupCode);
222
+ let privileges = [];
223
+ privileges = [
224
+ ...privileges,
225
+ ...userGroup.groupSystemPrivileges.map((g) => g.systemPrivilege.code),
226
+ ...userGroup.groupRolePrivileges.map((g) => g.systemPrivilege.code),
227
+ ];
228
+ const isContinue = userGroup.groupLevel !== 0 &&
229
+ userGroup.allowInheritFromParentYN === 'Y';
230
+ if (isContinue) {
231
+ const recursivePrivileges = yield this.getPrivilegesFromUserGroup(userGroup.parentGroupCode);
232
+ privileges = privileges.concat(recursivePrivileges);
233
+ }
234
+ return privileges;
235
+ }
236
+ catch (error) {
237
+ throw error;
238
+ }
239
+ });
240
+ }
241
+ getUserGroupFromDB(groupCode) {
242
+ return __awaiter(this, void 0, void 0, function* () {
243
+ try {
244
+ const userGroup = yield LoginUser._UserGroupRepository.findOne({
245
+ where: {
246
+ groupCode: groupCode,
247
+ },
248
+ include: {
249
+ groupSystemPrivileges: {
250
+ include: {
251
+ systemPrivilege: true,
252
+ },
253
+ },
254
+ groupRolePrivileges: {
255
+ include: {
256
+ systemPrivilege: true,
257
+ },
258
+ },
259
+ },
260
+ });
261
+ return userGroup;
262
+ }
263
+ catch (error) {
264
+ throw error;
265
+ }
266
+ });
267
+ }
268
+ getUserUserGroupFromDB(systemCode) {
269
+ return __awaiter(this, void 0, void 0, function* () {
270
+ try {
271
+ return yield LoginUser._UserUserGroupRepository.findAll({
272
+ where: {
273
+ userId: this.ObjectId,
274
+ systemId: systemCode,
275
+ },
276
+ include: {
277
+ userGroup: {
278
+ include: {
279
+ groupSystemPrivileges: {
280
+ include: {
281
+ systemPrivilege: true,
282
+ },
283
+ },
284
+ groupRolePrivileges: {
285
+ include: {
286
+ systemPrivilege: true,
287
+ },
288
+ },
289
+ },
290
+ },
291
+ },
292
+ });
293
+ }
294
+ catch (error) {
295
+ throw error;
296
+ }
297
+ });
298
+ }
299
+ getUserPersonalPrivileges(systemId) {
300
+ return __awaiter(this, void 0, void 0, function* () {
301
+ try {
302
+ const userRole = yield LoginUser._Repository.findOne({
303
+ where: {
304
+ id: this.ObjectId,
305
+ },
306
+ include: {
307
+ userSystemPrivileges: {
308
+ include: {
309
+ systemPrivilege: true,
310
+ },
311
+ },
312
+ },
313
+ });
314
+ let userSystemPrivileges = userRole.userSystemPrivileges.map((u) => u.systemPrivilege);
315
+ userSystemPrivileges = userRole.userSystemPrivileges.filter((u) => u.systemPrivilege.systemId === systemId);
316
+ const userPrivileges = userSystemPrivileges.map((u) => u.code);
317
+ return userPrivileges;
318
+ }
319
+ catch (error) {
320
+ throw error;
321
+ }
322
+ });
323
+ }
324
+ }
325
+ exports.LoginUser = LoginUser;
326
+ LoginUser._Repository = new user_repository_1.UserRepository();
327
+ LoginUser._SystemRepository = new system_repository_1.SystemRepository();
328
+ LoginUser._SystemAccessRepository = new system_access_repository_1.SystemAccessRepository();
329
+ LoginUser._LoginHistoryRepository = new login_history_repository_1.LoginHistoryRepository();
330
+ LoginUser._UserUserGroupRepository = new user_user_group_repository_1.UserUserGroupRepository();
331
+ LoginUser._UserGroupRepository = new user_group_repository_1.UserGroupRepository();
332
+ //# sourceMappingURL=login-user.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"login-user.js","sourceRoot":"","sources":["../../../../src/components/login-user/login-user.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,4CAA+D;AAI/D,uDAAmD;AACnD,mEAA+D;AAC/D,wFAAmF;AACnF,wFAAmF;AACnF,0DAAsD;AACtD,8FAAwF;AACxF,kFAA6E;AAC7E,mEAA+D;AAC/D,+EAA0E;AAE1E,MAAa,SAAU,SAAQ,oBAAU;IAwBvC,UAAU;QAOR,OAAO;YACL,QAAQ,EAAE,IAAI,CAAC,QAAQ;YACvB,IAAI,EAAE,IAAI,CAAC,IAAI;YACf,MAAM,EAAE,IAAI,CAAC,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iDAAsB,EAAE,CAAC;AACvD,kCAAwB,GAAG,IAAI,oDAAuB,EAAE,CAAC;AACzD,8BAAoB,GAAG,IAAI,2CAAmB,EAAE,CAAC"}
@@ -0,0 +1,9 @@
1
+ export declare class UserRepository {
2
+ private _prisma;
3
+ constructor(client?: any);
4
+ create(data: any): Promise<any>;
5
+ findAll(options: any): Promise<any[]>;
6
+ findOne(options: any): Promise<any>;
7
+ update(where: any, data: any): Promise<any>;
8
+ delete(where: any): Promise<any>;
9
+ }
@@ -0,0 +1,50 @@
1
+ "use strict";
2
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
+ return new (P || (P = Promise))(function (resolve, reject) {
5
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
9
+ });
10
+ };
11
+ Object.defineProperty(exports, "__esModule", { value: true });
12
+ exports.UserRepository = void 0;
13
+ const client_1 = require("../../prisma-client/client");
14
+ class UserRepository {
15
+ constructor(client) {
16
+ if (client) {
17
+ this._prisma = client;
18
+ }
19
+ else {
20
+ this._prisma = client_1.default;
21
+ }
22
+ }
23
+ create(data) {
24
+ return __awaiter(this, void 0, void 0, function* () {
25
+ return yield this._prisma.user.create(data);
26
+ });
27
+ }
28
+ findAll(options) {
29
+ return __awaiter(this, void 0, void 0, function* () {
30
+ return yield this._prisma.user.findMany(options);
31
+ });
32
+ }
33
+ findOne(options) {
34
+ return __awaiter(this, void 0, void 0, function* () {
35
+ return yield this._prisma.user.findFirst(options);
36
+ });
37
+ }
38
+ update(where, data) {
39
+ return __awaiter(this, void 0, void 0, function* () {
40
+ return yield this._prisma.user.update(where, data);
41
+ });
42
+ }
43
+ delete(where) {
44
+ return __awaiter(this, void 0, void 0, function* () {
45
+ return yield this._prisma.user.delete(where);
46
+ });
47
+ }
48
+ }
49
+ exports.UserRepository = UserRepository;
50
+ //# sourceMappingURL=user.repository.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"user.repository.js","sourceRoot":"","sources":["../../../../src/components/login-user/user.repository.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,uDAAgD;AAEhD,MAAa,cAAc;IAGzB,YAAY,MAAY;QACtB,IAAI,MAAM,EAAE;YACV,IAAI,CAAC,OAAO,GAAG,MAAM,CAAC;SACvB;aAAM;YACL,IAAI,CAAC,OAAO,GAAG,gBAAM,CAAC;SACvB;IACH,CAAC;IAEY,MAAM,CAAC,IAAS;;YAC3B,OAAO,MAAM,IAAI,CAAC,OAAO,CAAC,IAAI,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC;QAC9C,CAAC;KAAA;IAEY,OAAO,CAAC,OAAY;;YAC/B,OAAO,MAAM,IAAI,CAAC,OAAO,CAAC,IAAI,CAAC,QAAQ,CAAC,OAAO,CAAC,CAAC;QACnD,CAAC;KAAA;IAEY,OAAO,CAAC,OAAY;;YAC/B,OAAO,MAAM,IAAI,CAAC,OAAO,CAAC,IAAI,CAAC,SAAS,CAAC,OAAO,CAAC,CAAC;QACpD,CAAC;KAAA;IAEY,MAAM,CAAC,KAAU,EAAE,IAAS;;YACvC,OAAO,MAAM,IAAI,CAAC,OAAO,CAAC,IAAI,CAAC,MAAM,CAAC,KAAK,EAAE,IAAI,CAAC,CAAC;QACrD,CAAC;KAAA;IAEY,MAAM,CAAC,KAAU;;YAC5B,OAAO,MAAM,IAAI,CAAC,OAAO,CAAC,IAAI,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC;QAC/C,CAAC;KAAA;CACF;AA9BD,wCA8BC"}
@@ -0,0 +1,2 @@
1
+ export * from './interfaces';
2
+ export * from './password-hash.service';
@@ -0,0 +1,19 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
+ };
16
+ Object.defineProperty(exports, "__esModule", { value: true });
17
+ __exportStar(require("./interfaces"), exports);
18
+ __exportStar(require("./password-hash.service"), exports);
19
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../src/components/password-hash/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,+CAA6B;AAC7B,0DAAwC"}
@@ -0,0 +1 @@
1
+ export * from './password-hash-service.interface';
@@ -0,0 +1,18 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
+ };
16
+ Object.defineProperty(exports, "__esModule", { value: true });
17
+ __exportStar(require("./password-hash-service.interface"), exports);
18
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../../src/components/password-hash/interfaces/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,oEAAkD"}
@@ -0,0 +1,4 @@
1
+ export interface IPasswordHashService {
2
+ hashPassword(password: string): Promise<string>;
3
+ verify(password: string, hash: string): Promise<boolean>;
4
+ }
@@ -0,0 +1,3 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ //# sourceMappingURL=password-hash-service.interface.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"password-hash-service.interface.js","sourceRoot":"","sources":["../../../../../src/components/password-hash/interfaces/password-hash-service.interface.ts"],"names":[],"mappings":""}
@@ -0,0 +1,6 @@
1
+ import { IPasswordHashService } from './interfaces/password-hash-service.interface';
2
+ export declare class PasswordHashService implements IPasswordHashService {
3
+ constructor();
4
+ hashPassword(password: string): Promise<string>;
5
+ verify(password: string, hash: string): Promise<boolean>;
6
+ }
@@ -0,0 +1,28 @@
1
+ "use strict";
2
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
+ return new (P || (P = Promise))(function (resolve, reject) {
5
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
9
+ });
10
+ };
11
+ Object.defineProperty(exports, "__esModule", { value: true });
12
+ exports.PasswordHashService = void 0;
13
+ const argon2 = require("argon2");
14
+ class PasswordHashService {
15
+ constructor() { }
16
+ hashPassword(password) {
17
+ return __awaiter(this, void 0, void 0, function* () {
18
+ return yield argon2.hash(password);
19
+ });
20
+ }
21
+ verify(password, hash) {
22
+ return __awaiter(this, void 0, void 0, function* () {
23
+ return yield argon2.verify(hash, password);
24
+ });
25
+ }
26
+ }
27
+ exports.PasswordHashService = PasswordHashService;
28
+ //# sourceMappingURL=password-hash.service.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"password-hash.service.js","sourceRoot":"","sources":["../../../../src/components/password-hash/password-hash.service.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,iCAAiC;AAGjC,MAAa,mBAAmB;IAC9B,gBAAe,CAAC;IAEV,YAAY,CAAC,QAAgB;;YACjC,OAAO,MAAM,MAAM,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAC;QACrC,CAAC;KAAA;IAEK,MAAM,CAAC,QAAgB,EAAE,IAAY;;YACzC,OAAO,MAAM,MAAM,CAAC,MAAM,CAAC,IAAI,EAAE,QAAQ,CAAC,CAAC;QAC7C,CAAC;KAAA;CACF;AAVD,kDAUC"}
@@ -0,0 +1 @@
1
+ export * from './system.repository';
@@ -0,0 +1,18 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
+ };
16
+ Object.defineProperty(exports, "__esModule", { value: true });
17
+ __exportStar(require("./system.repository"), exports);
18
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../src/components/system/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,sDAAoC"}
@@ -0,0 +1,9 @@
1
+ export declare class SystemRepository {
2
+ private _prisma;
3
+ constructor(client?: any);
4
+ create(data: any): Promise<any>;
5
+ findAll(options: any): Promise<any[]>;
6
+ findOne(options: any): Promise<any>;
7
+ update(where: any, data: any): Promise<any>;
8
+ delete(where: any): Promise<any>;
9
+ }
@@ -0,0 +1,50 @@
1
+ "use strict";
2
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
+ return new (P || (P = Promise))(function (resolve, reject) {
5
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
9
+ });
10
+ };
11
+ Object.defineProperty(exports, "__esModule", { value: true });
12
+ exports.SystemRepository = void 0;
13
+ const client_1 = require("../../prisma-client/client");
14
+ class SystemRepository {
15
+ constructor(client) {
16
+ if (client) {
17
+ this._prisma = client;
18
+ }
19
+ else {
20
+ this._prisma = client_1.default;
21
+ }
22
+ }
23
+ create(data) {
24
+ return __awaiter(this, void 0, void 0, function* () {
25
+ return yield this._prisma.system.create(data);
26
+ });
27
+ }
28
+ findAll(options) {
29
+ return __awaiter(this, void 0, void 0, function* () {
30
+ return yield this._prisma.system.findMany(options);
31
+ });
32
+ }
33
+ findOne(options) {
34
+ return __awaiter(this, void 0, void 0, function* () {
35
+ return yield this._prisma.system.findFirst(options);
36
+ });
37
+ }
38
+ update(where, data) {
39
+ return __awaiter(this, void 0, void 0, function* () {
40
+ return yield this._prisma.system.update(where, data);
41
+ });
42
+ }
43
+ delete(where) {
44
+ return __awaiter(this, void 0, void 0, function* () {
45
+ return yield this._prisma.system.delete(where);
46
+ });
47
+ }
48
+ }
49
+ exports.SystemRepository = SystemRepository;
50
+ //# sourceMappingURL=system.repository.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"system.repository.js","sourceRoot":"","sources":["../../../../src/components/system/system.repository.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,uDAAgD;AAEhD,MAAa,gBAAgB;IAG3B,YAAY,MAAY;QACtB,IAAI,MAAM,EAAE;YACV,IAAI,CAAC,OAAO,GAAG,MAAM,CAAC;SACvB;aAAM;YACL,IAAI,CAAC,OAAO,GAAG,gBAAM,CAAC;SACvB;IACH,CAAC;IAEY,MAAM,CAAC,IAAS;;YAC3B,OAAO,MAAM,IAAI,CAAC,OAAO,CAAC,MAAM,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC;QAChD,CAAC;KAAA;IAEY,OAAO,CAAC,OAAY;;YAC/B,OAAO,MAAM,IAAI,CAAC,OAAO,CAAC,MAAM,CAAC,QAAQ,CAAC,OAAO,CAAC,CAAC;QACrD,CAAC;KAAA;IAEY,OAAO,CAAC,OAAY;;YAC/B,OAAO,MAAM,IAAI,CAAC,OAAO,CAAC,MAAM,CAAC,SAAS,CAAC,OAAO,CAAC,CAAC;QACtD,CAAC;KAAA;IAEY,MAAM,CAAC,KAAU,EAAE,IAAS;;YACvC,OAAO,MAAM,IAAI,CAAC,OAAO,CAAC,MAAM,CAAC,MAAM,CAAC,KAAK,EAAE,IAAI,CAAC,CAAC;QACvD,CAAC;KAAA;IAEY,MAAM,CAAC,KAAU;;YAC5B,OAAO,MAAM,IAAI,CAAC,OAAO,CAAC,MAAM,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC;QACjD,CAAC;KAAA;CACF;AA9BD,4CA8BC"}
@@ -0,0 +1 @@
1
+ export * from './system-access.repository';
@@ -0,0 +1,18 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
+ };
16
+ Object.defineProperty(exports, "__esModule", { value: true });
17
+ __exportStar(require("./system-access.repository"), exports);
18
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../src/components/system-access/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,6DAA2C"}