@tomei/sso 0.8.10 → 0.8.12

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 (33) hide show
  1. package/.prettierrc +2 -3
  2. package/Jenkinsfile +1 -1
  3. package/__tests__/unit/components/login-user/login-user.spec.ts +734 -731
  4. package/__tests__/unit/components/password-hash/password-hash.service.spec.ts +26 -26
  5. package/dist/__tests__/unit/components/login-user/login-user.spec.d.ts +1 -0
  6. package/dist/__tests__/unit/components/login-user/login-user.spec.js +652 -0
  7. package/dist/__tests__/unit/components/login-user/login-user.spec.js.map +1 -1
  8. package/dist/__tests__/unit/components/password-hash/password-hash.service.spec.d.ts +1 -0
  9. package/dist/__tests__/unit/components/password-hash/password-hash.service.spec.js +37 -0
  10. package/dist/__tests__/unit/components/password-hash/password-hash.service.spec.js.map +1 -1
  11. package/dist/src/components/login-user/login-user.d.ts +4 -4
  12. package/dist/src/components/login-user/login-user.js +15 -13
  13. package/dist/src/components/login-user/login-user.js.map +1 -1
  14. package/dist/tsconfig.tsbuildinfo +1 -1
  15. package/jest.config.js +0 -1
  16. package/package.json +3 -3
  17. package/src/components/login-user/login-user.ts +10 -10
  18. package/__tests__/unit/components/login-history/login-history.repository.spec.ts +0 -95
  19. package/__tests__/unit/components/login-user/user.repository.spec.ts +0 -81
  20. package/__tests__/unit/components/system/system.repository.spec.ts +0 -88
  21. package/__tests__/unit/components/system-access/system-access.repository.spec.ts +0 -78
  22. package/dist/__tests__/unit/components/login-history/login-history.repository.spec.d.ts +0 -0
  23. package/dist/__tests__/unit/components/login-history/login-history.repository.spec.js +0 -1
  24. package/dist/__tests__/unit/components/login-history/login-history.repository.spec.js.map +0 -1
  25. package/dist/__tests__/unit/components/login-user/user.repository.spec.d.ts +0 -0
  26. package/dist/__tests__/unit/components/login-user/user.repository.spec.js +0 -1
  27. package/dist/__tests__/unit/components/login-user/user.repository.spec.js.map +0 -1
  28. package/dist/__tests__/unit/components/system/system.repository.spec.d.ts +0 -0
  29. package/dist/__tests__/unit/components/system/system.repository.spec.js +0 -1
  30. package/dist/__tests__/unit/components/system/system.repository.spec.js.map +0 -1
  31. package/dist/__tests__/unit/components/system-access/system-access.repository.spec.d.ts +0 -0
  32. package/dist/__tests__/unit/components/system-access/system-access.repository.spec.js +0 -1
  33. package/dist/__tests__/unit/components/system-access/system-access.repository.spec.js.map +0 -1
package/jest.config.js CHANGED
@@ -9,7 +9,6 @@ module.exports = {
9
9
  "<rootDir>/dist"
10
10
  ],
11
11
  setupFilesAfterEnv: [
12
- '<rootDir>/src/prisma-client/__mocks__/prisma.ts',
13
12
  '<rootDir>/src/redis-client/__mocks__/jest-initial-setup.ts',
14
13
  ]
15
14
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tomei/sso",
3
- "version": "0.8.10",
3
+ "version": "0.8.12",
4
4
  "description": "Tomei SSO Package",
5
5
  "main": "dist/index.js",
6
6
  "scripts": {
@@ -57,13 +57,13 @@
57
57
  "access": "public"
58
58
  },
59
59
  "peerDependencies": {
60
- "@tomei/general": "^0.4.0",
60
+ "@tomei/general": "^0.4.3",
61
+ "@tomei/mailer": "^0.5.2",
61
62
  "@types/jest": "^29.5.2",
62
63
  "argon2": "^0.30.3",
63
64
  "cls-hooked": "^4.2.2",
64
65
  "nodemailer": "^6.9.3",
65
66
  "redis": "^4.6.7",
66
- "@tomei/mailer": "^0.5.2",
67
67
  "reflect-metadata": "^0.1.13",
68
68
  "sequelize": "^6.32.1",
69
69
  "sequelize-typescript": "^2.1.5"
@@ -1,7 +1,6 @@
1
- import { ObjectBase, IPerson, IAddress } from '@tomei/general';
1
+ import { IAddress, LoginUserBase } from '@tomei/general';
2
2
  import { ISessionService } from '../../session/interfaces/session-service.interface';
3
3
  import { IUserInfo } from './interfaces/user-info.interface';
4
- // import { IPasswordHashService } from '../password-hash/interfaces/password-hash-service.interface';
5
4
  import { UserRepository } from './user.repository';
6
5
  import { SystemRepository } from '../system/system.repository';
7
6
  import { SystemAccessRepository } from '../system-access/system-access.repository';
@@ -10,7 +9,6 @@ import { UserUserGroupRepository } from '../user-user-group/user-user-group.repo
10
9
  import { PasswordHashService } from '../password-hash/password-hash.service';
11
10
  import { SessionService } from '../../session/session.service';
12
11
  import { UserGroupRepository } from '../user-group/user-group.repository';
13
- import * as nodemailer from 'nodemailer';
14
12
  import { SMTPMailer } from '@tomei/mailer';
15
13
  import { ISystemLogin } from '../../../src/interfaces/system-login.interface';
16
14
  import Staff from '../../models/staff.entity';
@@ -20,7 +18,7 @@ import GroupSystemPrivilege from '../../models/group-system-privilege.entity';
20
18
  import GroupRolePrivilege from '../../models/group-role-privilege.entity';
21
19
  import UserGroup from '../../models/user-group.entity';
22
20
 
23
- export class LoginUser extends ObjectBase implements IPerson {
21
+ export class LoginUser extends LoginUserBase {
24
22
  FullName: string;
25
23
  IDNo: string;
26
24
  IDType: string;
@@ -44,13 +42,13 @@ export class LoginUser extends ObjectBase implements IPerson {
44
42
  private static _UserGroupRepository = new UserGroupRepository();
45
43
  private _dbTransaction: any;
46
44
 
47
- getDetails(): {
45
+ async getDetails(): Promise<{
48
46
  FullName: string;
49
47
  IDNo: string;
50
48
  IDType: string;
51
49
  Email: string;
52
50
  ContactNo: string;
53
- } {
51
+ }> {
54
52
  return {
55
53
  FullName: this.FullName,
56
54
  IDNo: this.IDNo,
@@ -109,7 +107,7 @@ export class LoginUser extends ObjectBase implements IPerson {
109
107
  FullName: user.Staff.FullName,
110
108
  IDNo: user.Staff.IdNo,
111
109
  ContactNo: user.Staff.Mobile,
112
- Email: user.Staff.Email,
110
+ Email: user.Email,
113
111
  Password: user.Password,
114
112
  staffs: user.Staff,
115
113
  };
@@ -130,9 +128,7 @@ export class LoginUser extends ObjectBase implements IPerson {
130
128
  ): Promise<string> {
131
129
  try {
132
130
  //validate email
133
- if (this.ObjectId && this.Email !== email) {
134
- throw new Error('Invalid credentials.');
135
- } else {
131
+ if (!this.ObjectId) {
136
132
  const user = await LoginUser._Repository.findOne({
137
133
  where: {
138
134
  Email: email,
@@ -163,6 +159,10 @@ export class LoginUser extends ObjectBase implements IPerson {
163
159
  this.staffs = userInfo.staffs;
164
160
  }
165
161
 
162
+ if (this.ObjectId && this.Email !== email) {
163
+ throw new Error('Invalid credentials.');
164
+ }
165
+
166
166
  //validate password
167
167
  const isPasswordValid = await this._PasswordHashService.verify(
168
168
  password,
@@ -1,95 +0,0 @@
1
- // import { LoginHistory } from '@prisma/client';
2
- // import { LoginHistoryRepository } from '../../../../src/components/login-history/login-history.repository';
3
- // import { prismaMock } from '../../../../src/prisma-client/__mocks__/prisma';
4
-
5
- // describe('login-history.repository', () => {
6
- // afterEach(() => {
7
- // jest.restoreAllMocks()
8
- // })
9
- // describe('findAll', () => {
10
- // it('should return list of login history', async () => {
11
- // const data = [{
12
- // userId: 1,
13
- // systemId: 1,
14
- // originIp: '1.1.1.1',
15
- // createdAt: new Date(),
16
- // }]
17
- // prismaMock.loginHistory.findMany.mockResolvedValueOnce(data as LoginHistory[])
18
- // const loginHistoryRepository = new LoginHistoryRepository()
19
- // expect(await loginHistoryRepository.findAll({})).toEqual(data)
20
- // })
21
- // })
22
-
23
- // describe('findOne', () => {
24
- // it('should return login history', async () => {
25
- // const data = {
26
- // userId: 1,
27
- // systemId: 1,
28
- // originIp: '1.1.1.1',
29
- // createdAt: new Date(),
30
- // }
31
- // prismaMock.loginHistory.findFirst.mockResolvedValueOnce(data as LoginHistory)
32
- // const loginHistoryRepository = new LoginHistoryRepository()
33
- // expect(await loginHistoryRepository.findOne({
34
- // where: {
35
- // userId_systemId: {
36
- // userId: data.userId,
37
- // systemId: data.systemId,
38
- // },
39
- // },
40
- // })).toEqual(data)
41
- // })
42
- // })
43
-
44
- // describe('create', () => {
45
- // it('should create login history', async () => {
46
- // const data = {
47
- // userId: 1,
48
- // systemId: 1,
49
- // originIp: '1.1.1.1',
50
- // createdAt: new Date(),
51
- // }
52
- // prismaMock.loginHistory.create.mockResolvedValueOnce(data as LoginHistory)
53
- // const loginHistoryRepository = new LoginHistoryRepository()
54
- // expect(await loginHistoryRepository.create({data})).toEqual(data)
55
- // })
56
- // })
57
-
58
- // describe('update', () => {
59
- // it('should update login history', async () => {
60
- // const data = {
61
- // userId: 1,
62
- // systemId: 1,
63
- // originIp: '1.1.1.1',
64
- // createdAt: new Date(),
65
- // }
66
- // prismaMock.loginHistory.update.mockResolvedValueOnce(data as LoginHistory)
67
- // const loginHistoryRepository = new LoginHistoryRepository()
68
- // expect(await loginHistoryRepository.update({
69
- // where: {
70
- // userId: data.userId
71
- // }, data: data
72
- // }, data)).toEqual(data)
73
- // })
74
- // })
75
-
76
- // describe('delete', () => {
77
- // it('should delete login history', async () => {
78
- // const data = {
79
- // userId: 1,
80
- // systemId: 1,
81
- // originIp: '1.1.1.1',
82
- // createdAt: new Date(),
83
- // }
84
- // prismaMock.loginHistory.delete.mockResolvedValueOnce(data as LoginHistory)
85
- // const loginHistoryRepository = new LoginHistoryRepository()
86
- // expect(await loginHistoryRepository.delete({
87
- // where: {
88
- // userId: data.userId
89
- // }
90
- // })).toEqual(data)
91
- // })
92
- // })
93
-
94
- // })
95
-
@@ -1,81 +0,0 @@
1
- // import { UserRepository } from '../../../../src/components/login-user/user.repository';
2
- // import { prismaMock } from '../../../../src/prisma-client/__mocks__/prisma';
3
-
4
- // describe('system-access.repository', () => {
5
- // const data = {
6
- // id: 1,
7
- // email: 'test@test.email.com',
8
- // password: '@H34f5yRE',
9
- // status: 'Active',
10
- // defaultPasswordChanged: false,
11
- // firstLoginAt: new Date(),
12
- // createdAt: new Date(),
13
- // updatedAt: new Date(),
14
- // groupCode: 'RDAS',
15
- // };
16
-
17
- // afterEach(() => {
18
- // jest.restoreAllMocks();
19
- // });
20
- // describe('findAll', () => {
21
- // it('should return list of user', async () => {
22
- // prismaMock.user.findMany.mockResolvedValueOnce([data]);
23
- // const userRepository = new UserRepository();
24
- // expect(await userRepository.findAll({})).toEqual([data]);
25
- // });
26
- // });
27
-
28
- // describe('findOne', () => {
29
- // it('should return user', async () => {
30
- // prismaMock.user.findFirst.mockResolvedValueOnce(data);
31
- // const userRepository = new UserRepository();
32
- // expect(
33
- // await userRepository.findOne({
34
- // where: {
35
- // id: data.id,
36
- // },
37
- // }),
38
- // ).toEqual(data);
39
- // });
40
- // });
41
-
42
- // describe('create', () => {
43
- // it('should create user', async () => {
44
- // prismaMock.user.create.mockResolvedValueOnce(data);
45
- // const userRepository = new UserRepository();
46
- // expect(await userRepository.create(data)).toEqual(data);
47
- // });
48
- // });
49
-
50
- // describe('update', () => {
51
- // it('should update user', async () => {
52
- // prismaMock.user.update.mockResolvedValueOnce(data);
53
- // const userRepository = new UserRepository();
54
- // expect(
55
- // await userRepository.update(
56
- // {
57
- // where: {
58
- // id: data.id,
59
- // },
60
- // data: data,
61
- // },
62
- // data,
63
- // ),
64
- // ).toEqual(data);
65
- // });
66
- // });
67
-
68
- // describe('delete', () => {
69
- // it('should delete user', async () => {
70
- // prismaMock.user.delete.mockResolvedValueOnce(data);
71
- // const userRepository = new UserRepository();
72
- // expect(
73
- // await userRepository.delete({
74
- // where: {
75
- // id: data.id,
76
- // },
77
- // }),
78
- // ).toEqual(data);
79
- // });
80
- // });
81
- // });
@@ -1,88 +0,0 @@
1
- // import { SystemRepository } from '../../../../src/components/system/system.repository';
2
- // import { prismaMock } from '../../../../src/prisma-client/__mocks__/prisma';
3
-
4
- // describe('system.repository', () => {
5
- // const data = {
6
- // id: 175,
7
- // code: 'EZC',
8
- // name: 'EzCash',
9
- // description: 'Tomei Money Lending System',
10
- // accessUrl: 'https://app.ezcash.com.my:22443/staff/login',
11
- // googlePlayUrl: '',
12
- // appleStoreUrl: '',
13
- // apiKey: 'f3fef257jt',
14
- // logo: 'https://sso-api.tomei.com.my/upload/2023/01/10/FJ3DoHdRZKjf2bGkgA4E-BrowserIcon.png',
15
- // status: 'active',
16
- // visible: true,
17
- // createdAt: new Date(),
18
- // updatedAt: new Date(),
19
- // apiSecret: '12345',
20
- // updatedById: 61,
21
- // createdById: 100,
22
- // };
23
-
24
- // afterEach(() => {
25
- // jest.restoreAllMocks();
26
- // });
27
- // describe('findAll', () => {
28
- // it('should return list of system', async () => {
29
- // prismaMock.system.findMany.mockResolvedValueOnce([data]);
30
- // const systemRepository = new SystemRepository();
31
- // expect(await systemRepository.findAll({})).toEqual([data]);
32
- // });
33
- // });
34
-
35
- // describe('findOne', () => {
36
- // it('should return system', async () => {
37
- // prismaMock.system.findFirst.mockResolvedValueOnce(data);
38
- // const systemRepository = new SystemRepository();
39
- // expect(
40
- // await systemRepository.findOne({
41
- // where: {
42
- // id: data.id,
43
- // },
44
- // }),
45
- // ).toEqual(data);
46
- // });
47
- // });
48
-
49
- // describe('create', () => {
50
- // it('should create system', async () => {
51
- // prismaMock.system.create.mockResolvedValueOnce(data);
52
- // const systemRepository = new SystemRepository();
53
- // expect(await systemRepository.create(data)).toEqual(data);
54
- // });
55
- // });
56
-
57
- // describe('update', () => {
58
- // it('should update system', async () => {
59
- // prismaMock.system.update.mockResolvedValueOnce(data);
60
- // const systemRepository = new SystemRepository();
61
- // expect(
62
- // await systemRepository.update(
63
- // {
64
- // where: {
65
- // id: data.id,
66
- // },
67
- // data: data,
68
- // },
69
- // data,
70
- // ),
71
- // ).toEqual(data);
72
- // });
73
- // });
74
-
75
- // describe('delete', () => {
76
- // it('should delete system', async () => {
77
- // prismaMock.system.delete.mockResolvedValueOnce(data);
78
- // const systemRepository = new SystemRepository();
79
- // expect(
80
- // await systemRepository.delete({
81
- // where: {
82
- // id: data.id,
83
- // },
84
- // }),
85
- // ).toEqual(data);
86
- // });
87
- // });
88
- // });
@@ -1,78 +0,0 @@
1
- // import { SystemAccessRepository } from '../../../../src/components/system-access/system-access.repository';
2
- // import { prismaMock } from '../../../../src/prisma-client/__mocks__/prisma';
3
-
4
- // describe('system-access.repository', () => {
5
- // const data = {
6
- // userId: 1,
7
- // systemId: 175,
8
- // updatedAt: new Date(),
9
- // };
10
-
11
- // afterEach(() => {
12
- // jest.restoreAllMocks();
13
- // });
14
- // describe('findAll', () => {
15
- // it('should return list of system access', async () => {
16
- // prismaMock.systemAccess.findMany.mockResolvedValueOnce([data]);
17
- // const systemAccessRepository = new SystemAccessRepository();
18
- // expect(await systemAccessRepository.findAll({})).toEqual([data]);
19
- // });
20
- // });
21
-
22
- // describe('findOne', () => {
23
- // it('should return system access', async () => {
24
- // prismaMock.systemAccess.findFirst.mockResolvedValueOnce(data);
25
- // const systemAccessRepository = new SystemAccessRepository();
26
- // expect(
27
- // await systemAccessRepository.findOne({
28
- // where: {
29
- // userId: data.userId,
30
- // systemId: data.systemId,
31
- // },
32
- // }),
33
- // ).toEqual(data);
34
- // });
35
- // });
36
-
37
- // describe('create', () => {
38
- // it('should create system access', async () => {
39
- // prismaMock.systemAccess.create.mockResolvedValueOnce(data);
40
- // const systemAccessRepository = new SystemAccessRepository();
41
- // expect(await systemAccessRepository.create(data)).toEqual(data);
42
- // });
43
- // });
44
-
45
- // describe('update', () => {
46
- // it('should update system access', async () => {
47
- // prismaMock.systemAccess.update.mockResolvedValueOnce(data);
48
- // const systemAccessRepository = new SystemAccessRepository();
49
- // expect(
50
- // await systemAccessRepository.update(
51
- // {
52
- // where: {
53
- // userId: data.userId,
54
- // systemId: data.systemId,
55
- // },
56
- // data: data,
57
- // },
58
- // data,
59
- // ),
60
- // ).toEqual(data);
61
- // });
62
- // });
63
-
64
- // describe('delete', () => {
65
- // it('should delete system access', async () => {
66
- // prismaMock.systemAccess.delete.mockResolvedValueOnce(data);
67
- // const systemAccessRepository = new SystemAccessRepository();
68
- // expect(
69
- // await systemAccessRepository.delete({
70
- // where: {
71
- // userId: data.userId,
72
- // systemId: data.systemId,
73
- // },
74
- // }),
75
- // ).toEqual(data);
76
- // });
77
- // });
78
- // });
@@ -1 +0,0 @@
1
- //# sourceMappingURL=login-history.repository.spec.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"login-history.repository.spec.js","sourceRoot":"","sources":["../../../../../__tests__/unit/components/login-history/login-history.repository.spec.ts"],"names":[],"mappings":""}
@@ -1 +0,0 @@
1
- //# sourceMappingURL=user.repository.spec.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"user.repository.spec.js","sourceRoot":"","sources":["../../../../../__tests__/unit/components/login-user/user.repository.spec.ts"],"names":[],"mappings":""}
@@ -1 +0,0 @@
1
- //# sourceMappingURL=system.repository.spec.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"system.repository.spec.js","sourceRoot":"","sources":["../../../../../__tests__/unit/components/system/system.repository.spec.ts"],"names":[],"mappings":""}
@@ -1 +0,0 @@
1
- //# sourceMappingURL=system-access.repository.spec.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"system-access.repository.spec.js","sourceRoot":"","sources":["../../../../../__tests__/unit/components/system-access/system-access.repository.spec.ts"],"names":[],"mappings":""}