@tomei/sso 0.39.1 → 0.39.3

Sign up to get free protection for your applications and to get access to all the features.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tomei/sso",
3
- "version": "0.39.1",
3
+ "version": "0.39.3",
4
4
  "description": "Tomei SSO Package",
5
5
  "main": "dist/index.js",
6
6
  "scripts": {
@@ -17,7 +17,7 @@ export class APIKey extends ObjectBase {
17
17
  Name: string;
18
18
  Description: string;
19
19
  Status: APIKeyStatusEnum;
20
- ExperationDate: Date;
20
+ ExpirationDate: Date;
21
21
  _InvokedById: number;
22
22
  _InvokedAt: Date;
23
23
  _CreatedAt: Date;
@@ -57,7 +57,7 @@ export class APIKey extends ObjectBase {
57
57
  this.Name = apiKeyAttr.Name;
58
58
  this.Description = apiKeyAttr.Description;
59
59
  this.Status = apiKeyAttr.Status;
60
- this.ExperationDate = apiKeyAttr.ExperationDate;
60
+ this.ExpirationDate = apiKeyAttr.ExpirationDate;
61
61
  this._InvokedById = apiKeyAttr.InvokedById;
62
62
  this._InvokedAt = apiKeyAttr.InvokedAt;
63
63
  this._CreatedAt = apiKeyAttr.CreatedAt;
@@ -132,7 +132,7 @@ export class APIKey extends ObjectBase {
132
132
  ApiKey: this.ApiKey,
133
133
  Name: this.Name,
134
134
  Status: this.Status,
135
- ExpirationDate: this.ExperationDate,
135
+ ExpirationDate: this.ExpirationDate,
136
136
  CreatedAt: this.CreatedAt,
137
137
  CreatedById: this.CreatedById,
138
138
  InvokedAt: this.InvokedAt,
@@ -183,7 +183,7 @@ export class APIKey extends ObjectBase {
183
183
  ApiKey: this.ApiKey,
184
184
  Name: this.Name,
185
185
  Status: this.Status,
186
- ExpirationDate: this.ExperationDate,
186
+ ExpirationDate: this.ExpirationDate,
187
187
  CreatedAt: this.CreatedAt,
188
188
  CreatedById: this.CreatedById,
189
189
  InvokedAt: this.InvokedAt,
@@ -910,22 +910,25 @@ export class User extends UserBase {
910
910
  transaction: dbTransaction,
911
911
  });
912
912
 
913
+ const gp = group?.GroupPrivileges || [];
914
+ const op = objectPrivileges || [];
915
+
913
916
  let privileges: string[] = [];
914
917
  // Add privileges from the group to the privileges array
915
918
  const groupPrivileges: string[] = [];
916
- for (const groupPrivilege of group.GroupPrivileges) {
919
+ for (const groupPrivilege of gp) {
917
920
  groupPrivileges.push(groupPrivilege.Privilege.PrivilegeCode);
918
921
  }
919
922
 
920
923
  const ops: string[] = [];
921
- for (const objectPrivilege of objectPrivileges) {
924
+ for (const objectPrivilege of op) {
922
925
  ops.push(objectPrivilege.Privilege.PrivilegeCode);
923
926
  }
924
927
 
925
928
  privileges = [...privileges, ...groupPrivileges, ...ops];
926
929
 
927
930
  // Recursive call if not root and allow inherit privileges from parent group
928
- if (group.ParentGroupCode && group.InheritParentPrivilegeYN === 'Y') {
931
+ if (group?.ParentGroupCode && group?.InheritParentPrivilegeYN === 'Y') {
929
932
  const parentGroupPrivileges = await this.getInheritedPrivileges(
930
933
  group.ParentGroupCode,
931
934
  systemCode,
@@ -945,20 +948,21 @@ export class User extends UserBase {
945
948
  dbTransaction?: any,
946
949
  ): Promise<string[]> {
947
950
  try {
948
- const userPrivileges = await User._UserPrivilegeRepo.findAll({
949
- where: {
950
- UserId: this.UserId,
951
- Status: 'Active',
952
- },
953
- include: {
954
- model: SystemPrivilege,
951
+ const userPrivileges =
952
+ (await User._UserPrivilegeRepo.findAll({
955
953
  where: {
956
- SystemCode: systemCode,
954
+ UserId: this.UserId,
957
955
  Status: 'Active',
958
956
  },
959
- },
960
- transaction: dbTransaction,
961
- });
957
+ include: {
958
+ model: SystemPrivilege,
959
+ where: {
960
+ SystemCode: systemCode,
961
+ Status: 'Active',
962
+ },
963
+ },
964
+ transaction: dbTransaction,
965
+ })) || [];
962
966
 
963
967
  const privileges: string[] = userPrivileges.map(
964
968
  (u) => u.Privilege.PrivilegeCode,
@@ -974,19 +978,20 @@ export class User extends UserBase {
974
978
  dbTransaction?: any,
975
979
  ): Promise<string[]> {
976
980
  try {
977
- const userObjectPrivileges = await User._UserObjectPrivilegeRepo.findAll({
978
- where: {
979
- UserId: this.UserId,
980
- },
981
- include: {
982
- model: SystemPrivilege,
981
+ const userObjectPrivileges =
982
+ (await User._UserObjectPrivilegeRepo.findAll({
983
983
  where: {
984
- SystemCode: systemCode,
985
- Status: 'Active',
984
+ UserId: this.UserId,
986
985
  },
987
- },
988
- transaction: dbTransaction,
989
- });
986
+ include: {
987
+ model: SystemPrivilege,
988
+ where: {
989
+ SystemCode: systemCode,
990
+ Status: 'Active',
991
+ },
992
+ },
993
+ transaction: dbTransaction,
994
+ })) || [];
990
995
 
991
996
  const privilegesCodes: string[] = userObjectPrivileges.map(
992
997
  (u) => u.Privilege.PrivilegeCode,
package/src/index.ts CHANGED
@@ -3,4 +3,5 @@ export * from './components';
3
3
  export * from './interfaces';
4
4
  export * from './redis-client';
5
5
  export * from './session';
6
+ export * from './enum';
6
7
  export * as ssoDb from './database';
@@ -6,7 +6,7 @@ export interface IAPIKeyAttr {
6
6
  Name: string;
7
7
  Description: string;
8
8
  Status: APIKeyStatusEnum;
9
- ExperationDate: Date;
9
+ ExpirationDate: Date;
10
10
  CreatedById: number;
11
11
  InvokedById: number;
12
12
  CreatedAt: Date;
@@ -54,7 +54,7 @@ export default class APIKeyModel extends Model {
54
54
  type: DataType.DATE,
55
55
  allowNull: true,
56
56
  })
57
- ExperationDate: Date;
57
+ ExpirationDate: Date;
58
58
 
59
59
  @ForeignKey(() => User)
60
60
  @Column({