@tomei/sso 0.8.14 → 0.9.2

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.
@@ -0,0 +1,91 @@
1
+ // import { Privilege } from '../../../src/components/system-privilege/privilege';
2
+ // import { SystemPrivilegeRepository } from '../../../src/components/system-privilege/system-privilege.repository';
3
+ // import { SystemRepository } from '../../../src/components/system/system.repository';
4
+ // describe('SystemPrivilege', () => {
5
+ // afterEach(async () => {
6
+ // jest.restoreAllMocks();
7
+ // });
8
+ // it('should be able to load single package privileges', async () => {
9
+ // let privilegeCalled = 0;
10
+ // const findOrCreateMock = jest
11
+ // .spyOn(SystemPrivilegeRepository.prototype, 'findOrCreate')
12
+ // .mockResolvedValueOnce([{}, true] as any);
13
+
14
+ // const systemRepositoryMock = jest
15
+ // .spyOn(SystemRepository.prototype, 'findOne')
16
+ // .mockResolvedValueOnce({
17
+ // id: 175,
18
+ // } as any);
19
+
20
+ // jest.mock('@tomei/mailer/privileges.json', () => {
21
+ // privilegeCalled++;
22
+ // return {
23
+ // Privileges: [
24
+ // {
25
+ // Code: 'Privilege1',
26
+ // Description: 'This is Privilege1',
27
+ // },
28
+ // ],
29
+ // };
30
+ // });
31
+
32
+ // await Privilege.loadPrivileges('mailer', 'EZC');
33
+ // expect(findOrCreateMock).toBeCalledTimes(1);
34
+ // expect(systemRepositoryMock).toBeCalledTimes(1);
35
+ // expect(privilegeCalled).toEqual(1);
36
+ // });
37
+
38
+ // it('should be able to load multiple package privileges', async () => {
39
+ // let privilegeCalled = 0;
40
+ // const findOrCreateMock = jest
41
+ // .spyOn(SystemPrivilegeRepository.prototype, 'findOrCreate')
42
+ // .mockResolvedValueOnce([{}, true] as any);
43
+
44
+ // const systemRepositoryMock = jest
45
+ // .spyOn(SystemRepository.prototype, 'findOne')
46
+ // .mockResolvedValueOnce({
47
+ // id: 175,
48
+ // } as any);
49
+
50
+ // jest.mock(
51
+ // '@tomei/mailer/privileges.json',
52
+ // () => {
53
+ // privilegeCalled++;
54
+ // return {
55
+ // Privileges: [
56
+ // {
57
+ // Code: 'Privilege1',
58
+ // Description: 'This is Privilege1',
59
+ // },
60
+ // ],
61
+ // };
62
+ // },
63
+ // );
64
+
65
+ // jest.mock(
66
+ // '@tomei/config/privileges.json',
67
+ // () => {
68
+ // privilegeCalled++;
69
+ // return {
70
+ // Privileges: [
71
+ // {
72
+ // Code: 'Privilege2',
73
+ // Description: 'This is Privilege2',
74
+ // },
75
+ // ],
76
+ // };
77
+ // },
78
+ // );
79
+
80
+ // await Privilege.loadPrivileges(['mailer', 'config'], 'EZC');
81
+ // expect(findOrCreateMock).toBeCalledTimes(2);
82
+ // expect(systemRepositoryMock).toBeCalledTimes(1);
83
+ // expect(privilegeCalled).toEqual(2);
84
+ // });
85
+ // });
86
+
87
+ describe('SystemPrivilege', () => {
88
+ it('should be true', () => {
89
+ expect(true).toBe(true);
90
+ });
91
+ });
@@ -0,0 +1,6 @@
1
+ describe('SystemPrivilege', () => {
2
+ it('should be true', () => {
3
+ expect(true).toBe(true);
4
+ });
5
+ });
6
+ //# sourceMappingURL=system-privilage.spec.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"system-privilage.spec.js","sourceRoot":"","sources":["../../../../__tests__/unit/system-privilege/system-privilage.spec.ts"],"names":[],"mappings":"AAsFA,QAAQ,CAAC,iBAAiB,EAAE,GAAG,EAAE;IAC/B,EAAE,CAAC,gBAAgB,EAAE,GAAG,EAAE;QACxB,MAAM,CAAC,IAAI,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;IAC1B,CAAC,CAAC,CAAC;AACL,CAAC,CAAC,CAAC"}
@@ -0,0 +1,6 @@
1
+ export declare class Privilege {
2
+ private static _Repository;
3
+ private static _SystemRepository;
4
+ static loadPrivileges(packageName: string | string[], systemCode: string, transaction?: any): Promise<void>;
5
+ private static loadPrivilege;
6
+ }
@@ -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"}