@tomei/sso 0.8.13 → 0.9.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.
- package/__tests__/unit/components/login-user/login-user.spec.ts +32 -24
- package/__tests__/unit/system-privilege/system-privilage.spec.ts +91 -0
- package/dist/__tests__/unit/components/login-user/login-user.spec.js +32 -22
- package/dist/__tests__/unit/components/login-user/login-user.spec.js.map +1 -1
- package/dist/__tests__/unit/system-privilege/system-privilage.spec.d.ts +0 -0
- package/dist/__tests__/unit/system-privilege/system-privilage.spec.js +6 -0
- package/dist/__tests__/unit/system-privilege/system-privilage.spec.js.map +1 -0
- package/dist/src/components/login-user/login-user.d.ts +2 -1
- package/dist/src/components/login-user/login-user.js +1 -3
- package/dist/src/components/login-user/login-user.js.map +1 -1
- package/dist/src/components/system-privilege/privilege.d.ts +6 -0
- package/dist/src/components/system-privilege/privilege.js +77 -0
- package/dist/src/components/system-privilege/privilege.js.map +1 -0
- package/dist/src/components/system-privilege/system-privilege.repository.d.ts +6 -0
- package/dist/src/components/system-privilege/system-privilege.repository.js +35 -0
- package/dist/src/components/system-privilege/system-privilege.repository.js.map +1 -0
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/package.json +3 -2
- package/src/components/login-user/login-user.ts +5 -5
- package/src/components/system-privilege/privilege.ts +74 -0
- package/src/components/system-privilege/system-privilege.repository.ts +23 -0
@@ -0,0 +1,77 @@
|
|
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.Privilege = void 0;
|
13
|
+
const system_repository_1 = require("../system/system.repository");
|
14
|
+
const system_privilege_repository_1 = require("./system-privilege.repository");
|
15
|
+
const cuid = require("cuid");
|
16
|
+
class Privilege {
|
17
|
+
static loadPrivileges(packageName, systemCode, transaction) {
|
18
|
+
return __awaiter(this, void 0, void 0, function* () {
|
19
|
+
try {
|
20
|
+
const system = yield Privilege._SystemRepository.findOne({
|
21
|
+
where: {
|
22
|
+
code: systemCode,
|
23
|
+
},
|
24
|
+
transaction,
|
25
|
+
});
|
26
|
+
if (!system) {
|
27
|
+
throw new Error('System not found');
|
28
|
+
}
|
29
|
+
if (Array.isArray(packageName)) {
|
30
|
+
for (const name of packageName) {
|
31
|
+
yield this.loadPrivilege(name, system.id, transaction);
|
32
|
+
}
|
33
|
+
}
|
34
|
+
else {
|
35
|
+
yield this.loadPrivilege(packageName, system.id, transaction);
|
36
|
+
}
|
37
|
+
}
|
38
|
+
catch (error) {
|
39
|
+
throw error;
|
40
|
+
}
|
41
|
+
});
|
42
|
+
}
|
43
|
+
static loadPrivilege(packageName, systemId, transaction) {
|
44
|
+
return __awaiter(this, void 0, void 0, function* () {
|
45
|
+
var _a;
|
46
|
+
try {
|
47
|
+
let privileges = [];
|
48
|
+
try {
|
49
|
+
const { Privileges } = yield (_a = `@tomei/${packageName}/privileges.json`, Promise.resolve().then(() => require(_a)));
|
50
|
+
privileges = Privileges;
|
51
|
+
}
|
52
|
+
catch (error) {
|
53
|
+
throw new Error('Module not found');
|
54
|
+
}
|
55
|
+
for (const privilege of privileges) {
|
56
|
+
const { Code, Description } = privilege;
|
57
|
+
yield Privilege._Repository.findOrCreate({
|
58
|
+
Code,
|
59
|
+
SystemId: systemId,
|
60
|
+
Description,
|
61
|
+
}, {
|
62
|
+
PrivilegeId: cuid(),
|
63
|
+
CreatedAt: new Date(),
|
64
|
+
UpdatedAt: new Date(),
|
65
|
+
}, transaction);
|
66
|
+
}
|
67
|
+
}
|
68
|
+
catch (error) {
|
69
|
+
throw error;
|
70
|
+
}
|
71
|
+
});
|
72
|
+
}
|
73
|
+
}
|
74
|
+
exports.Privilege = Privilege;
|
75
|
+
Privilege._Repository = new system_privilege_repository_1.SystemPrivilegeRepository();
|
76
|
+
Privilege._SystemRepository = new system_repository_1.SystemRepository();
|
77
|
+
//# sourceMappingURL=privilege.js.map
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"file":"privilege.js","sourceRoot":"","sources":["../../../../src/components/system-privilege/privilege.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,mEAA+D;AAC/D,+EAA0E;AAC1E,6BAA6B;AAE7B,MAAa,SAAS;IAIpB,MAAM,CAAO,cAAc,CACzB,WAA8B,EAC9B,UAAkB,EAClB,WAAiB;;YAEjB,IAAI;gBAEF,MAAM,MAAM,GAAG,MAAM,SAAS,CAAC,iBAAiB,CAAC,OAAO,CAAC;oBACvD,KAAK,EAAE;wBACL,IAAI,EAAE,UAAU;qBACjB;oBACD,WAAW;iBACZ,CAAC,CAAC;gBAEH,IAAI,CAAC,MAAM,EAAE;oBACX,MAAM,IAAI,KAAK,CAAC,kBAAkB,CAAC,CAAC;iBACrC;gBAED,IAAI,KAAK,CAAC,OAAO,CAAC,WAAW,CAAC,EAAE;oBAC9B,KAAK,MAAM,IAAI,IAAI,WAAW,EAAE;wBAC9B,MAAM,IAAI,CAAC,aAAa,CAAC,IAAI,EAAE,MAAM,CAAC,EAAE,EAAE,WAAW,CAAC,CAAC;qBACxD;iBACF;qBAAM;oBACL,MAAM,IAAI,CAAC,aAAa,CAAC,WAAW,EAAE,MAAM,CAAC,EAAE,EAAE,WAAW,CAAC,CAAC;iBAC/D;aACF;YAAC,OAAO,KAAK,EAAE;gBACd,MAAM,KAAK,CAAC;aACb;QACH,CAAC;KAAA;IAEO,MAAM,CAAO,aAAa,CAChC,WAAmB,EACnB,QAAgB,EAChB,WAAiB;;;YAEjB,IAAI;gBACF,IAAI,UAAU,GAAG,EAAE,CAAC;gBACpB,IAAI;oBACF,MAAM,EAAE,UAAU,EAAE,GAAG,YACrB,UAAU,WAAW,kBAAkB,4CACxC,CAAC;oBACF,UAAU,GAAG,UAAU,CAAC;iBACzB;gBAAC,OAAO,KAAK,EAAE;oBACd,MAAM,IAAI,KAAK,CAAC,kBAAkB,CAAC,CAAC;iBACrC;gBACD,KAAK,MAAM,SAAS,IAAI,UAAU,EAAE;oBAClC,MAAM,EAAE,IAAI,EAAE,WAAW,EAAE,GAAG,SAAS,CAAC;oBACxC,MAAM,SAAS,CAAC,WAAW,CAAC,YAAY,CACtC;wBACE,IAAI;wBACJ,QAAQ,EAAE,QAAQ;wBAClB,WAAW;qBACZ,EACD;wBACE,WAAW,EAAE,IAAI,EAAE;wBACnB,SAAS,EAAE,IAAI,IAAI,EAAE;wBACrB,SAAS,EAAE,IAAI,IAAI,EAAE;qBACtB,EACD,WAAW,CACZ,CAAC;iBACH;aACF;YAAC,OAAO,KAAK,EAAE;gBACd,MAAM,KAAK,CAAC;aACb;QACH,CAAC;KAAA;;AApEH,8BAqEC;AApEgB,qBAAW,GAAG,IAAI,uDAAyB,EAAE,CAAC;AAC9C,2BAAiB,GAAG,IAAI,oCAAgB,EAAE,CAAC"}
|
@@ -0,0 +1,6 @@
|
|
1
|
+
import SystemPrivilege from '../../models/system-privilege.entity';
|
2
|
+
import { RepositoryBase, IRepositoryBase } from '@tomei/general';
|
3
|
+
export declare class SystemPrivilegeRepository extends RepositoryBase<SystemPrivilege> implements IRepositoryBase<SystemPrivilege> {
|
4
|
+
constructor();
|
5
|
+
findOrCreate(where: any, defaults: any, transaction: any): Promise<[SystemPrivilege, boolean]>;
|
6
|
+
}
|
@@ -0,0 +1,35 @@
|
|
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.SystemPrivilegeRepository = void 0;
|
13
|
+
const system_privilege_entity_1 = require("../../models/system-privilege.entity");
|
14
|
+
const general_1 = require("@tomei/general");
|
15
|
+
class SystemPrivilegeRepository extends general_1.RepositoryBase {
|
16
|
+
constructor() {
|
17
|
+
super(system_privilege_entity_1.default);
|
18
|
+
}
|
19
|
+
findOrCreate(where, defaults, transaction) {
|
20
|
+
return __awaiter(this, void 0, void 0, function* () {
|
21
|
+
try {
|
22
|
+
return yield system_privilege_entity_1.default.findOrCreate({
|
23
|
+
where,
|
24
|
+
defaults,
|
25
|
+
transaction,
|
26
|
+
});
|
27
|
+
}
|
28
|
+
catch (error) {
|
29
|
+
throw error;
|
30
|
+
}
|
31
|
+
});
|
32
|
+
}
|
33
|
+
}
|
34
|
+
exports.SystemPrivilegeRepository = SystemPrivilegeRepository;
|
35
|
+
//# sourceMappingURL=system-privilege.repository.js.map
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"file":"system-privilege.repository.js","sourceRoot":"","sources":["../../../../src/components/system-privilege/system-privilege.repository.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,kFAAmE;AACnE,4CAAiE;AAEjE,MAAa,yBACX,SAAQ,wBAA+B;IAGvC;QACE,KAAK,CAAC,iCAAe,CAAC,CAAC;IACzB,CAAC;IAEK,YAAY,CAAC,KAAU,EAAE,QAAa,EAAE,WAAgB;;YAC5D,IAAI;gBACF,OAAO,MAAM,iCAAe,CAAC,YAAY,CAAC;oBACxC,KAAK;oBACL,QAAQ;oBACR,WAAW;iBACZ,CAAC,CAAC;aACJ;YAAC,OAAO,KAAK,EAAE;gBACd,MAAM,KAAK,CAAC;aACb;QACH,CAAC;KAAA;CACF;AAnBD,8DAmBC"}
|