@uniorganization/uni-lib 4.3.0 → 4.3.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.
- package/dist/entities/bp-alerts.entity.d.ts +2 -2
- package/dist/entities/bp-alerts.entity.js +4 -4
- package/dist/entities/business-schedule.entity.d.ts +2 -2
- package/dist/entities/business-schedule.entity.js +4 -4
- package/dist/entities/call-driver-data.entity.d.ts +2 -2
- package/dist/entities/call-driver-data.entity.js +4 -4
- package/dist/entities/call-drivers.entity.d.ts +1 -1
- package/dist/entities/call-drivers.entity.js +2 -2
- package/dist/entities/cb-completed-reasons.entity.d.ts +1 -1
- package/dist/entities/cb-completed-reasons.entity.js +2 -2
- package/dist/entities/claim-report.entity.d.ts +2 -2
- package/dist/entities/claim-report.entity.js +4 -4
- package/dist/entities/daily-payment.entity.d.ts +58 -0
- package/dist/entities/daily-payment.entity.js +248 -0
- package/dist/entities/dispute-request.entity.d.ts +2 -2
- package/dist/entities/dispute-request.entity.js +4 -4
- package/dist/entities/division.entity.d.ts +11 -0
- package/dist/entities/division.entity.js +52 -0
- package/dist/entities/enr-inventory.entity.d.ts +2 -2
- package/dist/entities/enr-inventory.entity.js +4 -4
- package/dist/entities/enr-results.entity.d.ts +1 -1
- package/dist/entities/enr-results.entity.js +2 -2
- package/dist/entities/escalations.entity.d.ts +2 -2
- package/dist/entities/escalations.entity.js +4 -4
- package/dist/entities/evaluation-forms.entity.d.ts +4 -4
- package/dist/entities/evaluations.entity.d.ts +2 -2
- package/dist/entities/evaluations.entity.js +4 -4
- package/dist/entities/form-fields.entity.d.ts +2 -2
- package/dist/entities/form-fields.entity.js +4 -4
- package/dist/entities/form.entity.d.ts +2 -2
- package/dist/entities/form.entity.js +4 -4
- package/dist/entities/inbox/message-case.entity.d.ts +2 -2
- package/dist/entities/inbox/message-case.entity.js +6 -8
- package/dist/entities/inbox/sla-policy.entity.d.ts +2 -2
- package/dist/entities/inbox/sla-policy.entity.js +4 -4
- package/dist/entities/index.d.ts +3 -0
- package/dist/entities/index.js +3 -0
- package/dist/entities/inventory.entity.d.ts +1 -1
- package/dist/entities/inventory.entity.js +2 -2
- package/dist/entities/lob-assignment.entity.d.ts +1 -1
- package/dist/entities/lob-assignment.entity.js +2 -2
- package/dist/entities/lob-call-drivers.entity.d.ts +1 -1
- package/dist/entities/lob-call-drivers.entity.js +2 -2
- package/dist/entities/lob.entity.d.ts +14 -0
- package/dist/entities/lob.entity.js +65 -0
- package/dist/entities/offphone-activities.entity.d.ts +1 -1
- package/dist/entities/offphone-activities.entity.js +2 -2
- package/dist/entities/otwe-offers.entity.d.ts +1 -1
- package/dist/entities/otwe-offers.entity.js +2 -2
- package/dist/entities/outbound-ticket-history.entity.d.ts +2 -2
- package/dist/entities/outbound-ticket-history.entity.js +4 -4
- package/dist/entities/pending-ticket-history.entity.d.ts +2 -2
- package/dist/entities/pending-ticket-history.entity.js +4 -4
- package/dist/entities/raw_roster.entity.d.ts +2 -2
- package/dist/entities/raw_roster.entity.js +4 -4
- package/dist/entities/roster.entity.d.ts +2 -2
- package/dist/entities/roster.entity.js +4 -4
- package/dist/entities/skipped-ticket.entity.d.ts +2 -2
- package/dist/entities/skipped-ticket.entity.js +4 -4
- package/dist/entities/template.entity.d.ts +2 -2
- package/dist/entities/template.entity.js +4 -4
- package/dist/entities/ticket-queue.entity.d.ts +2 -2
- package/dist/entities/ticket-queue.entity.js +4 -4
- package/dist/entities/user-roster.view.d.ts +2 -2
- package/dist/entities/user-roster.view.js +4 -4
- package/dist/entities/users-lobs.entity.d.ts +11 -0
- package/dist/entities/users-lobs.entity.js +57 -0
- package/dist/entities/usr.entity.d.ts +4 -2
- package/dist/entities/usr.entity.js +22 -14
- package/dist/entities/vw-escalation-age.d.ts +2 -0
- package/dist/entities/vw-escalation-age.js +8 -0
- package/dist/middlewares/index.d.ts +1 -0
- package/dist/middlewares/index.js +17 -0
- package/dist/middlewares/version-checker.middleware.d.ts +2 -0
- package/dist/middlewares/version-checker.middleware.js +27 -0
- package/dist/modules/common/jwt.strategy.js +2 -6
- package/dist/modules/tenant/redis-tenant-state.store.js +0 -3
- package/dist/modules/tenant/tenant-authorization.service.d.ts +2 -2
- package/dist/modules/tenant/tenant-authorization.service.js +37 -25
- package/dist/modules/tenant/tenant-authorization.types.d.ts +2 -2
- package/dist/modules/tenant/tenant.types.d.ts +0 -1
- package/package.json +13 -12
- package/dist/entities/user-client-context.entity.d.ts +0 -10
- package/dist/entities/user-client-context.entity.js +0 -59
- package/dist/modules/tenant/master-users.guard.d.ts +0 -4
- package/dist/modules/tenant/master-users.guard.js +0 -35
|
@@ -62,9 +62,9 @@ export declare class VwUserRoster {
|
|
|
62
62
|
phoenixId: string;
|
|
63
63
|
five9Id: string;
|
|
64
64
|
communityWfmId: string;
|
|
65
|
-
|
|
65
|
+
divisionId: string | null;
|
|
66
66
|
mainLine: string;
|
|
67
|
-
|
|
67
|
+
lobId: string | null;
|
|
68
68
|
employeeRole: string;
|
|
69
69
|
sector: string;
|
|
70
70
|
sprinklrId: string;
|
|
@@ -267,17 +267,17 @@ __decorate([
|
|
|
267
267
|
__metadata("design:type", String)
|
|
268
268
|
], VwUserRoster.prototype, "communityWfmId", void 0);
|
|
269
269
|
__decorate([
|
|
270
|
-
(0, typeorm_1.Column)({ name: '
|
|
270
|
+
(0, typeorm_1.Column)({ name: 'division_id', type: 'bigint', nullable: true }),
|
|
271
271
|
__metadata("design:type", String)
|
|
272
|
-
], VwUserRoster.prototype, "
|
|
272
|
+
], VwUserRoster.prototype, "divisionId", void 0);
|
|
273
273
|
__decorate([
|
|
274
274
|
(0, typeorm_1.Column)({ name: 'main_line', type: 'text' }),
|
|
275
275
|
__metadata("design:type", String)
|
|
276
276
|
], VwUserRoster.prototype, "mainLine", void 0);
|
|
277
277
|
__decorate([
|
|
278
|
-
(0, typeorm_1.Column)({ name: '
|
|
278
|
+
(0, typeorm_1.Column)({ name: 'lob_id', type: 'bigint', nullable: true }),
|
|
279
279
|
__metadata("design:type", String)
|
|
280
|
-
], VwUserRoster.prototype, "
|
|
280
|
+
], VwUserRoster.prototype, "lobId", void 0);
|
|
281
281
|
__decorate([
|
|
282
282
|
(0, typeorm_1.Column)({ name: 'employee_role', type: 'text' }),
|
|
283
283
|
__metadata("design:type", String)
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
3
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
4
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
5
|
+
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
6
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
7
|
+
};
|
|
8
|
+
var __metadata = (this && this.__metadata) || function (k, v) {
|
|
9
|
+
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
10
|
+
};
|
|
11
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
+
exports.UsersLobs = void 0;
|
|
13
|
+
const typeorm_1 = require("typeorm");
|
|
14
|
+
const lob_entity_1 = require("./lob.entity");
|
|
15
|
+
const usr_entity_1 = require("./usr.entity");
|
|
16
|
+
let UsersLobs = class UsersLobs {
|
|
17
|
+
};
|
|
18
|
+
exports.UsersLobs = UsersLobs;
|
|
19
|
+
__decorate([
|
|
20
|
+
(0, typeorm_1.PrimaryColumn)({ name: 'client_id', type: 'integer' }),
|
|
21
|
+
__metadata("design:type", Number)
|
|
22
|
+
], UsersLobs.prototype, "clientId", void 0);
|
|
23
|
+
__decorate([
|
|
24
|
+
(0, typeorm_1.PrimaryColumn)({ name: 'user_id', type: 'numeric' }),
|
|
25
|
+
__metadata("design:type", Number)
|
|
26
|
+
], UsersLobs.prototype, "userId", void 0);
|
|
27
|
+
__decorate([
|
|
28
|
+
(0, typeorm_1.PrimaryColumn)({ name: 'lob_id', type: 'bigint' }),
|
|
29
|
+
__metadata("design:type", String)
|
|
30
|
+
], UsersLobs.prototype, "lobId", void 0);
|
|
31
|
+
__decorate([
|
|
32
|
+
(0, typeorm_1.CreateDateColumn)({ name: 'created_at', type: 'timestamptz' }),
|
|
33
|
+
__metadata("design:type", Date)
|
|
34
|
+
], UsersLobs.prototype, "createdAt", void 0);
|
|
35
|
+
__decorate([
|
|
36
|
+
(0, typeorm_1.UpdateDateColumn)({ name: 'updated_at', type: 'timestamptz' }),
|
|
37
|
+
__metadata("design:type", Date)
|
|
38
|
+
], UsersLobs.prototype, "updatedAt", void 0);
|
|
39
|
+
__decorate([
|
|
40
|
+
(0, typeorm_1.ManyToOne)(() => usr_entity_1.Users, (user) => user.usersLobs, { onDelete: 'CASCADE' }),
|
|
41
|
+
(0, typeorm_1.JoinColumn)([
|
|
42
|
+
{ name: 'user_id', referencedColumnName: 'id' },
|
|
43
|
+
{ name: 'client_id', referencedColumnName: 'clientId' },
|
|
44
|
+
]),
|
|
45
|
+
__metadata("design:type", usr_entity_1.Users)
|
|
46
|
+
], UsersLobs.prototype, "user", void 0);
|
|
47
|
+
__decorate([
|
|
48
|
+
(0, typeorm_1.ManyToOne)(() => lob_entity_1.Lob, (lob) => lob.userLobs),
|
|
49
|
+
(0, typeorm_1.JoinColumn)([
|
|
50
|
+
{ name: 'lob_id', referencedColumnName: 'id' },
|
|
51
|
+
{ name: 'client_id', referencedColumnName: 'clientId' },
|
|
52
|
+
]),
|
|
53
|
+
__metadata("design:type", lob_entity_1.Lob)
|
|
54
|
+
], UsersLobs.prototype, "lob", void 0);
|
|
55
|
+
exports.UsersLobs = UsersLobs = __decorate([
|
|
56
|
+
(0, typeorm_1.Entity)('users_lobs', { schema: 'stm' })
|
|
57
|
+
], UsersLobs);
|
|
@@ -2,8 +2,8 @@ import { Timestamp } from 'typeorm';
|
|
|
2
2
|
import { UserCampaign } from './user-campaign.entity';
|
|
3
3
|
import { UserRoles } from './user-roles.entity';
|
|
4
4
|
import { RawRoster } from './raw_roster.entity';
|
|
5
|
+
import { UsersLobs } from './users-lobs.entity';
|
|
5
6
|
export declare class Users {
|
|
6
|
-
clientId: number;
|
|
7
7
|
id: number;
|
|
8
8
|
username: string;
|
|
9
9
|
password: string;
|
|
@@ -25,6 +25,8 @@ export declare class Users {
|
|
|
25
25
|
reportsTo: Users;
|
|
26
26
|
userCampaigns: UserCampaign[];
|
|
27
27
|
rawRoster: RawRoster;
|
|
28
|
+
usersLobs: UsersLobs[];
|
|
28
29
|
fullName: string;
|
|
29
|
-
|
|
30
|
+
applyDerivedScope(): void;
|
|
31
|
+
private firstLobDivision;
|
|
30
32
|
}
|
|
@@ -14,16 +14,28 @@ const typeorm_1 = require("typeorm");
|
|
|
14
14
|
const user_campaign_entity_1 = require("./user-campaign.entity");
|
|
15
15
|
const user_roles_entity_1 = require("./user-roles.entity");
|
|
16
16
|
const raw_roster_entity_1 = require("./raw_roster.entity");
|
|
17
|
+
const users_lobs_entity_1 = require("./users-lobs.entity");
|
|
17
18
|
let Users = class Users {
|
|
18
|
-
|
|
19
|
+
applyDerivedScope() {
|
|
20
|
+
var _a;
|
|
19
21
|
this.fullName = `${this.first_name} ${this.last_name}`;
|
|
22
|
+
const lobNames = ((_a = this.usersLobs) !== null && _a !== void 0 ? _a : [])
|
|
23
|
+
.map((assignment) => { var _a; return (_a = assignment.lob) === null || _a === void 0 ? void 0 : _a.name; })
|
|
24
|
+
.filter((name) => Boolean(name))
|
|
25
|
+
.sort((a, b) => a.localeCompare(b));
|
|
26
|
+
this.lob = lobNames.join(',');
|
|
27
|
+
this.division = lobNames.length > 0 ? this.firstLobDivision() : '';
|
|
28
|
+
}
|
|
29
|
+
firstLobDivision() {
|
|
30
|
+
var _a, _b;
|
|
31
|
+
const divisions = ((_a = this.usersLobs) !== null && _a !== void 0 ? _a : [])
|
|
32
|
+
.map((assignment) => { var _a, _b; return (_b = (_a = assignment.lob) === null || _a === void 0 ? void 0 : _a.division) === null || _b === void 0 ? void 0 : _b.name; })
|
|
33
|
+
.filter((name) => Boolean(name))
|
|
34
|
+
.sort((a, b) => a.localeCompare(b));
|
|
35
|
+
return (_b = divisions[0]) !== null && _b !== void 0 ? _b : '';
|
|
20
36
|
}
|
|
21
37
|
};
|
|
22
38
|
exports.Users = Users;
|
|
23
|
-
__decorate([
|
|
24
|
-
(0, typeorm_1.Column)({ name: 'client_id', type: 'integer' }),
|
|
25
|
-
__metadata("design:type", Number)
|
|
26
|
-
], Users.prototype, "clientId", void 0);
|
|
27
39
|
__decorate([
|
|
28
40
|
(0, typeorm_1.PrimaryGeneratedColumn)({ name: 'ID' }),
|
|
29
41
|
__metadata("design:type", Number)
|
|
@@ -72,14 +84,6 @@ __decorate([
|
|
|
72
84
|
(0, typeorm_1.Column)({ length: 250, name: 'ntgid' }),
|
|
73
85
|
__metadata("design:type", String)
|
|
74
86
|
], Users.prototype, "ntgid", void 0);
|
|
75
|
-
__decorate([
|
|
76
|
-
(0, typeorm_1.Column)({ length: 250, name: 'lob' }),
|
|
77
|
-
__metadata("design:type", String)
|
|
78
|
-
], Users.prototype, "lob", void 0);
|
|
79
|
-
__decorate([
|
|
80
|
-
(0, typeorm_1.Column)({ length: 250, name: 'division' }),
|
|
81
|
-
__metadata("design:type", String)
|
|
82
|
-
], Users.prototype, "division", void 0);
|
|
83
87
|
__decorate([
|
|
84
88
|
(0, typeorm_1.Column)({ length: 250, name: 'profile' }),
|
|
85
89
|
__metadata("design:type", String)
|
|
@@ -114,12 +118,16 @@ __decorate([
|
|
|
114
118
|
(0, typeorm_1.OneToOne)(() => raw_roster_entity_1.RawRoster, (rawRoster) => rawRoster.user),
|
|
115
119
|
__metadata("design:type", raw_roster_entity_1.RawRoster)
|
|
116
120
|
], Users.prototype, "rawRoster", void 0);
|
|
121
|
+
__decorate([
|
|
122
|
+
(0, typeorm_1.OneToMany)(() => users_lobs_entity_1.UsersLobs, (usersLobs) => usersLobs.user),
|
|
123
|
+
__metadata("design:type", Array)
|
|
124
|
+
], Users.prototype, "usersLobs", void 0);
|
|
117
125
|
__decorate([
|
|
118
126
|
(0, typeorm_1.AfterLoad)(),
|
|
119
127
|
__metadata("design:type", Function),
|
|
120
128
|
__metadata("design:paramtypes", []),
|
|
121
129
|
__metadata("design:returntype", void 0)
|
|
122
|
-
], Users.prototype, "
|
|
130
|
+
], Users.prototype, "applyDerivedScope", null);
|
|
123
131
|
exports.Users = Users = __decorate([
|
|
124
132
|
(0, typeorm_1.Entity)('USERS')
|
|
125
133
|
], Users);
|
|
@@ -34,6 +34,14 @@ __decorate([
|
|
|
34
34
|
(0, typeorm_1.ViewColumn)(),
|
|
35
35
|
__metadata("design:type", String)
|
|
36
36
|
], VwEscalationAge.prototype, "lob", void 0);
|
|
37
|
+
__decorate([
|
|
38
|
+
(0, typeorm_1.ViewColumn)({ name: 'division_id' }),
|
|
39
|
+
__metadata("design:type", String)
|
|
40
|
+
], VwEscalationAge.prototype, "divisionId", void 0);
|
|
41
|
+
__decorate([
|
|
42
|
+
(0, typeorm_1.ViewColumn)({ name: 'lob_id' }),
|
|
43
|
+
__metadata("design:type", String)
|
|
44
|
+
], VwEscalationAge.prototype, "lobId", void 0);
|
|
37
45
|
__decorate([
|
|
38
46
|
(0, typeorm_1.ViewColumn)(),
|
|
39
47
|
__metadata("design:type", String)
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './version-checker.middleware';
|
|
@@ -0,0 +1,17 @@
|
|
|
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("./version-checker.middleware"), exports);
|
|
@@ -0,0 +1,27 @@
|
|
|
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.versionChecker = versionChecker;
|
|
13
|
+
const fs = require("fs/promises");
|
|
14
|
+
const path = require("path");
|
|
15
|
+
function versionChecker(req, res, next) {
|
|
16
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
17
|
+
const version = (yield fs.readFile(path.join(process.cwd(), 'app-version.txt')))
|
|
18
|
+
.toString()
|
|
19
|
+
.trim();
|
|
20
|
+
if (req.headers['app-version'] !== version)
|
|
21
|
+
return res.status(409).json({
|
|
22
|
+
message: `You need to update the application version to ${version}`,
|
|
23
|
+
status: 409,
|
|
24
|
+
});
|
|
25
|
+
next();
|
|
26
|
+
});
|
|
27
|
+
}
|
|
@@ -38,7 +38,6 @@ let JwtStrategy = class JwtStrategy extends (0, passport_1.PassportStrategy)(pas
|
|
|
38
38
|
var _a, _b, _c;
|
|
39
39
|
const signedUser = payload === null || payload === void 0 ? void 0 : payload.user;
|
|
40
40
|
const effectiveClientId = Number(signedUser === null || signedUser === void 0 ? void 0 : signedUser.clientId);
|
|
41
|
-
const homeClientId = Number(signedUser === null || signedUser === void 0 ? void 0 : signedUser.homeClientId);
|
|
42
41
|
const originalClientId = (_a = signedUser === null || signedUser === void 0 ? void 0 : signedUser.originalClientId) !== null && _a !== void 0 ? _a : null;
|
|
43
42
|
const now = Math.floor(Date.now() / 1000);
|
|
44
43
|
if ((payload === null || payload === void 0 ? void 0 : payload.type) !== 'access' ||
|
|
@@ -47,8 +46,6 @@ let JwtStrategy = class JwtStrategy extends (0, passport_1.PassportStrategy)(pas
|
|
|
47
46
|
String(signedUser.id) !== payload.sub ||
|
|
48
47
|
!Number.isInteger(effectiveClientId) ||
|
|
49
48
|
effectiveClientId <= 0 ||
|
|
50
|
-
!Number.isInteger(homeClientId) ||
|
|
51
|
-
homeClientId <= 0 ||
|
|
52
49
|
!Number.isInteger(payload.exp) ||
|
|
53
50
|
payload.exp <= now ||
|
|
54
51
|
!this.validTokenIdentifier(payload.jti) ||
|
|
@@ -70,8 +67,8 @@ let JwtStrategy = class JwtStrategy extends (0, passport_1.PassportStrategy)(pas
|
|
|
70
67
|
throw new common_1.UnauthorizedException();
|
|
71
68
|
}
|
|
72
69
|
const resolved = impersonating
|
|
73
|
-
? yield this.authorization.resolveImpersonation(signedUser.id, originalClientId,
|
|
74
|
-
: yield this.authorization.resolve(signedUser.id, effectiveClientId
|
|
70
|
+
? yield this.authorization.resolveImpersonation(signedUser.id, originalClientId, effectiveClientId)
|
|
71
|
+
: yield this.authorization.resolve(signedUser.id, effectiveClientId);
|
|
75
72
|
const { identity, snapshot } = resolved;
|
|
76
73
|
const isMasterTenantAdmin = !impersonating &&
|
|
77
74
|
snapshot.clientId === tenant_1.NEWTECH_CLIENT_ID &&
|
|
@@ -91,7 +88,6 @@ let JwtStrategy = class JwtStrategy extends (0, passport_1.PassportStrategy)(pas
|
|
|
91
88
|
password_expired: identity.passwordExpired,
|
|
92
89
|
viewEvaluations: identity.viewEvaluations,
|
|
93
90
|
ern: identity.ern,
|
|
94
|
-
homeClientId: identity.homeClientId,
|
|
95
91
|
clientId: snapshot.clientId,
|
|
96
92
|
clientAlias: snapshot.clientAlias,
|
|
97
93
|
clientName: snapshot.clientName,
|
|
@@ -138,8 +138,6 @@ let RedisTenantStateStore = RedisTenantStateStore_1 = class RedisTenantStateStor
|
|
|
138
138
|
return Boolean(value &&
|
|
139
139
|
Number.isInteger(value.userId) &&
|
|
140
140
|
value.userId > 0 &&
|
|
141
|
-
Number.isInteger(value.homeClientId) &&
|
|
142
|
-
value.homeClientId > 0 &&
|
|
143
141
|
Number.isInteger(value.clientId) &&
|
|
144
142
|
value.clientId > 0 &&
|
|
145
143
|
typeof value.clientName === 'string' &&
|
|
@@ -165,7 +163,6 @@ let RedisTenantStateStore = RedisTenantStateStore_1 = class RedisTenantStateStor
|
|
|
165
163
|
Number.isInteger(value.authzVersion) &&
|
|
166
164
|
value.authzVersion > 0 &&
|
|
167
165
|
((_a = value.identity) === null || _a === void 0 ? void 0 : _a.id) === value.userId &&
|
|
168
|
-
value.identity.homeClientId === value.homeClientId &&
|
|
169
166
|
typeof value.cachedAt === 'string');
|
|
170
167
|
}
|
|
171
168
|
};
|
|
@@ -12,8 +12,8 @@ export declare class TenantAuthorizationService {
|
|
|
12
12
|
private readonly userRoleRepository;
|
|
13
13
|
private readonly logger;
|
|
14
14
|
constructor(store: TenantAuthorizationStore, userRepository: Repository<Users>, clientRepository: Repository<Client>, userRoleRepository: Repository<UserRoles>);
|
|
15
|
-
resolve(userId: number, clientId: number,
|
|
16
|
-
resolveImpersonation(userId: number, originClientId: number,
|
|
15
|
+
resolve(userId: number, clientId: number, _legacyOriginClientId?: number): Promise<ResolvedTenantAuthorization>;
|
|
16
|
+
resolveImpersonation(userId: number, originClientId: number, targetClientIdOrLegacyOriginClientId: number, legacyTargetClientId?: number): Promise<ResolvedTenantAuthorization>;
|
|
17
17
|
invalidate(userId: number, clientId: number): Promise<void>;
|
|
18
18
|
invalidateMany(clientId: number, userIds: readonly number[]): Promise<void>;
|
|
19
19
|
private loadFromDatabase;
|
|
@@ -41,36 +41,36 @@ let TenantAuthorizationService = TenantAuthorizationService_1 = class TenantAuth
|
|
|
41
41
|
this.userRoleRepository = userRoleRepository;
|
|
42
42
|
this.logger = new common_1.Logger(TenantAuthorizationService_1.name);
|
|
43
43
|
}
|
|
44
|
-
resolve(userId, clientId,
|
|
44
|
+
resolve(userId, clientId, _legacyOriginClientId) {
|
|
45
45
|
return __awaiter(this, void 0, void 0, function* () {
|
|
46
|
-
var _a;
|
|
46
|
+
var _a, _b;
|
|
47
47
|
this.assertPositiveInteger(userId);
|
|
48
48
|
this.assertPositiveInteger(clientId);
|
|
49
|
-
this.assertPositiveInteger(expectedHomeClientId);
|
|
50
49
|
const key = (0, tenant_authorization_keys_1.tenantAuthorizationKey)(clientId, userId);
|
|
51
50
|
const cached = yield this.readCache(key);
|
|
52
51
|
if (cached &&
|
|
53
52
|
cached.userId === userId &&
|
|
54
53
|
cached.clientId === clientId &&
|
|
55
|
-
cached.homeClientId === expectedHomeClientId &&
|
|
56
54
|
((_a = cached.identity) === null || _a === void 0 ? void 0 : _a.id) === userId &&
|
|
57
|
-
cached.identity.homeClientId === expectedHomeClientId &&
|
|
58
55
|
this.isFresh(cached.cachedAt) &&
|
|
59
|
-
cached.roles.length > 0
|
|
56
|
+
cached.roles.length > 0 &&
|
|
57
|
+
Array.isArray(cached.permissions) &&
|
|
58
|
+
((_b = cached.accessRole) === null || _b === void 0 ? void 0 : _b.id)) {
|
|
60
59
|
return { identity: cached.identity, snapshot: cached };
|
|
61
60
|
}
|
|
62
|
-
const resolved = yield this.loadFromDatabase(userId, clientId
|
|
61
|
+
const resolved = yield this.loadFromDatabase(userId, clientId);
|
|
63
62
|
yield this.writeCache(key, resolved.snapshot);
|
|
64
63
|
return resolved;
|
|
65
64
|
});
|
|
66
65
|
}
|
|
67
|
-
resolveImpersonation(userId, originClientId,
|
|
66
|
+
resolveImpersonation(userId, originClientId, targetClientIdOrLegacyOriginClientId, legacyTargetClientId) {
|
|
68
67
|
return __awaiter(this, void 0, void 0, function* () {
|
|
68
|
+
const targetClientId = legacyTargetClientId !== null && legacyTargetClientId !== void 0 ? legacyTargetClientId : targetClientIdOrLegacyOriginClientId;
|
|
69
69
|
if (originClientId !== tenant_constants_1.NEWTECH_CLIENT_ID ||
|
|
70
70
|
targetClientId === tenant_constants_1.NEWTECH_CLIENT_ID) {
|
|
71
71
|
throw new common_1.UnauthorizedException();
|
|
72
72
|
}
|
|
73
|
-
const origin = yield this.resolve(userId, originClientId
|
|
73
|
+
const origin = yield this.resolve(userId, originClientId);
|
|
74
74
|
const isNewtechMaster = origin.snapshot.permissions.includes('master.users.read') ||
|
|
75
75
|
origin.snapshot.roles.some((role) => role.moduleName.toLowerCase() === 'root' &&
|
|
76
76
|
role.roleName.toLowerCase() === 'sysadmin');
|
|
@@ -82,7 +82,6 @@ let TenantAuthorizationService = TenantAuthorizationService_1 = class TenantAuth
|
|
|
82
82
|
}
|
|
83
83
|
const snapshot = {
|
|
84
84
|
userId,
|
|
85
|
-
homeClientId,
|
|
86
85
|
clientId: targetClientId,
|
|
87
86
|
clientName: targetClient.name,
|
|
88
87
|
clientAlias: targetClient.alias,
|
|
@@ -123,10 +122,14 @@ let TenantAuthorizationService = TenantAuthorizationService_1 = class TenantAuth
|
|
|
123
122
|
}
|
|
124
123
|
});
|
|
125
124
|
}
|
|
126
|
-
loadFromDatabase(userId, clientId
|
|
125
|
+
loadFromDatabase(userId, clientId) {
|
|
127
126
|
return __awaiter(this, void 0, void 0, function* () {
|
|
127
|
+
var _a, _b;
|
|
128
128
|
const [user, client, assignments, accessRows] = yield Promise.all([
|
|
129
|
-
this.userRepository.findOne({
|
|
129
|
+
this.userRepository.findOne({
|
|
130
|
+
where: { id: userId },
|
|
131
|
+
relations: ['usersLobs', 'usersLobs.lob', 'usersLobs.lob.division'],
|
|
132
|
+
}),
|
|
130
133
|
this.clientRepository.findOne({
|
|
131
134
|
where: { id: clientId, deletedAt: (0, typeorm_2.IsNull)() },
|
|
132
135
|
}),
|
|
@@ -165,20 +168,31 @@ let TenantAuthorizationService = TenantAuthorizationService_1 = class TenantAuth
|
|
|
165
168
|
]);
|
|
166
169
|
if (!user ||
|
|
167
170
|
!Number(user.is_active) ||
|
|
168
|
-
user.clientId !== expectedHomeClientId ||
|
|
169
171
|
!client ||
|
|
170
|
-
accessRows.length
|
|
172
|
+
accessRows.length > 1 ||
|
|
173
|
+
(accessRows.length === 0 && assignments.length === 0)) {
|
|
171
174
|
throw new common_1.UnauthorizedException();
|
|
172
175
|
}
|
|
173
176
|
const accessRow = accessRows[0];
|
|
174
|
-
const
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
177
|
+
const usingLegacyCompatibility = accessRows.length === 0 || accessRow.code.startsWith('migrated-');
|
|
178
|
+
const legacyRole = (_a = assignments[0]) === null || _a === void 0 ? void 0 : _a.role;
|
|
179
|
+
const accessRole = accessRow
|
|
180
|
+
? {
|
|
181
|
+
id: Number(accessRow.id),
|
|
182
|
+
code: accessRow.code,
|
|
183
|
+
name: accessRow.name,
|
|
184
|
+
scope: accessRow.scope,
|
|
185
|
+
clientId: accessRow.roleClientId == null
|
|
186
|
+
? null
|
|
187
|
+
: Number(accessRow.roleClientId),
|
|
188
|
+
}
|
|
189
|
+
: {
|
|
190
|
+
id: Number(legacyRole === null || legacyRole === void 0 ? void 0 : legacyRole.id),
|
|
191
|
+
code: `legacy-${Number(legacyRole === null || legacyRole === void 0 ? void 0 : legacyRole.id)}`,
|
|
192
|
+
name: (_b = legacyRole === null || legacyRole === void 0 ? void 0 : legacyRole.roleName) !== null && _b !== void 0 ? _b : 'Legacy access',
|
|
193
|
+
scope: 'CLIENT',
|
|
194
|
+
clientId,
|
|
195
|
+
};
|
|
182
196
|
const roles = usingLegacyCompatibility && assignments.length
|
|
183
197
|
? assignments.map((assignment) => {
|
|
184
198
|
var _a, _b, _c, _d, _e, _f;
|
|
@@ -215,7 +229,6 @@ let TenantAuthorizationService = TenantAuthorizationService_1 = class TenantAuth
|
|
|
215
229
|
: [];
|
|
216
230
|
const identity = {
|
|
217
231
|
id: user.id,
|
|
218
|
-
homeClientId: user.clientId,
|
|
219
232
|
firstName: user.first_name,
|
|
220
233
|
username: user.username,
|
|
221
234
|
lastName: user.last_name,
|
|
@@ -230,7 +243,6 @@ let TenantAuthorizationService = TenantAuthorizationService_1 = class TenantAuth
|
|
|
230
243
|
};
|
|
231
244
|
const snapshot = {
|
|
232
245
|
userId,
|
|
233
|
-
homeClientId: user.clientId,
|
|
234
246
|
clientId,
|
|
235
247
|
clientName: client.name,
|
|
236
248
|
clientAlias: client.alias,
|
|
@@ -240,7 +252,7 @@ let TenantAuthorizationService = TenantAuthorizationService_1 = class TenantAuth
|
|
|
240
252
|
permissions: Array.isArray(accessRow.permissions)
|
|
241
253
|
? accessRow.permissions
|
|
242
254
|
: [],
|
|
243
|
-
authzVersion: Number(accessRow.authzVersion),
|
|
255
|
+
authzVersion: accessRow ? Number(accessRow.authzVersion) : 1,
|
|
244
256
|
identity,
|
|
245
257
|
cachedAt: new Date().toISOString(),
|
|
246
258
|
};
|
|
@@ -6,7 +6,6 @@ export interface TenantRoleAuthorization {
|
|
|
6
6
|
}
|
|
7
7
|
export interface TenantAuthorizationSnapshot {
|
|
8
8
|
userId: number;
|
|
9
|
-
homeClientId: number;
|
|
10
9
|
clientId: number;
|
|
11
10
|
clientName: string;
|
|
12
11
|
clientAlias: string;
|
|
@@ -17,6 +16,7 @@ export interface TenantAuthorizationSnapshot {
|
|
|
17
16
|
authzVersion: number;
|
|
18
17
|
identity: TenantAuthorizationIdentity;
|
|
19
18
|
cachedAt: string;
|
|
19
|
+
[key: string]: unknown;
|
|
20
20
|
}
|
|
21
21
|
export interface TenantAccessRoleAuthorization {
|
|
22
22
|
id: number;
|
|
@@ -27,7 +27,6 @@ export interface TenantAccessRoleAuthorization {
|
|
|
27
27
|
}
|
|
28
28
|
export interface TenantAuthorizationIdentity {
|
|
29
29
|
id: number;
|
|
30
|
-
homeClientId: number;
|
|
31
30
|
firstName?: string;
|
|
32
31
|
username?: string;
|
|
33
32
|
lastName?: string;
|
|
@@ -39,6 +38,7 @@ export interface TenantAuthorizationIdentity {
|
|
|
39
38
|
passwordExpired?: number;
|
|
40
39
|
viewEvaluations?: boolean;
|
|
41
40
|
ern?: string;
|
|
41
|
+
[key: string]: unknown;
|
|
42
42
|
}
|
|
43
43
|
export interface ResolvedTenantAuthorization {
|
|
44
44
|
identity: TenantAuthorizationIdentity;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@uniorganization/uni-lib",
|
|
3
|
-
"version": "4.3.
|
|
3
|
+
"version": "4.3.2",
|
|
4
4
|
"description": "UNI Library",
|
|
5
5
|
"author": "Jhomiguel",
|
|
6
6
|
"main": "dist/index.js",
|
|
@@ -9,6 +9,17 @@
|
|
|
9
9
|
"dist/**/*",
|
|
10
10
|
"*.md"
|
|
11
11
|
],
|
|
12
|
+
"scripts": {
|
|
13
|
+
"start:dev": "tsc -w",
|
|
14
|
+
"build": "tsc",
|
|
15
|
+
"prepublishOnly": "pnpm run build",
|
|
16
|
+
"format": "prettier --write \"src/**/*.ts\"",
|
|
17
|
+
"lint": "tslint -p tsconfig.json -c tslint.json",
|
|
18
|
+
"test": "jest",
|
|
19
|
+
"test:watch": "jest --watch",
|
|
20
|
+
"test:cov": "jest --coverage",
|
|
21
|
+
"test:e2e": "jest --config ./test/jest-e2e.json"
|
|
22
|
+
},
|
|
12
23
|
"dependencies": {
|
|
13
24
|
"@googlemaps/google-maps-services-js": "^3.4.2",
|
|
14
25
|
"@aws-sdk/client-s3": "^3.833.0",
|
|
@@ -71,15 +82,5 @@
|
|
|
71
82
|
},
|
|
72
83
|
"coverageDirectory": "../coverage",
|
|
73
84
|
"testEnvironment": "node"
|
|
74
|
-
},
|
|
75
|
-
"scripts": {
|
|
76
|
-
"start:dev": "tsc -w",
|
|
77
|
-
"build": "tsc",
|
|
78
|
-
"format": "prettier --write \"src/**/*.ts\"",
|
|
79
|
-
"lint": "tslint -p tsconfig.json -c tslint.json",
|
|
80
|
-
"test": "jest",
|
|
81
|
-
"test:watch": "jest --watch",
|
|
82
|
-
"test:cov": "jest --coverage",
|
|
83
|
-
"test:e2e": "jest --config ./test/jest-e2e.json"
|
|
84
85
|
}
|
|
85
|
-
}
|
|
86
|
+
}
|
|
@@ -1,59 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
3
|
-
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
4
|
-
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
5
|
-
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
6
|
-
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
7
|
-
};
|
|
8
|
-
var __metadata = (this && this.__metadata) || function (k, v) {
|
|
9
|
-
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
10
|
-
};
|
|
11
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
-
exports.UserClientContext = void 0;
|
|
13
|
-
const typeorm_1 = require("typeorm");
|
|
14
|
-
let UserClientContext = class UserClientContext {
|
|
15
|
-
};
|
|
16
|
-
exports.UserClientContext = UserClientContext;
|
|
17
|
-
__decorate([
|
|
18
|
-
(0, typeorm_1.PrimaryColumn)({ name: 'USER_ID', type: 'numeric' }),
|
|
19
|
-
__metadata("design:type", Number)
|
|
20
|
-
], UserClientContext.prototype, "userId", void 0);
|
|
21
|
-
__decorate([
|
|
22
|
-
(0, typeorm_1.PrimaryColumn)({ name: 'client_id', type: 'integer' }),
|
|
23
|
-
__metadata("design:type", Number)
|
|
24
|
-
], UserClientContext.prototype, "clientId", void 0);
|
|
25
|
-
__decorate([
|
|
26
|
-
(0, typeorm_1.Column)({ type: 'varchar', length: 250, default: '' }),
|
|
27
|
-
__metadata("design:type", String)
|
|
28
|
-
], UserClientContext.prototype, "profile", void 0);
|
|
29
|
-
__decorate([
|
|
30
|
-
(0, typeorm_1.Column)({ type: 'varchar', length: 250, default: '' }),
|
|
31
|
-
__metadata("design:type", String)
|
|
32
|
-
], UserClientContext.prototype, "division", void 0);
|
|
33
|
-
__decorate([
|
|
34
|
-
(0, typeorm_1.Column)({ type: 'varchar', length: 250, default: '' }),
|
|
35
|
-
__metadata("design:type", String)
|
|
36
|
-
], UserClientContext.prototype, "lob", void 0);
|
|
37
|
-
__decorate([
|
|
38
|
-
(0, typeorm_1.Column)({ name: 'REPORTS_TO', type: 'numeric', nullable: true }),
|
|
39
|
-
__metadata("design:type", Number)
|
|
40
|
-
], UserClientContext.prototype, "reportsToId", void 0);
|
|
41
|
-
__decorate([
|
|
42
|
-
(0, typeorm_1.CreateDateColumn)({
|
|
43
|
-
name: 'created_at',
|
|
44
|
-
type: 'timestamptz',
|
|
45
|
-
default: () => 'CURRENT_TIMESTAMP',
|
|
46
|
-
}),
|
|
47
|
-
__metadata("design:type", Date)
|
|
48
|
-
], UserClientContext.prototype, "createdAt", void 0);
|
|
49
|
-
__decorate([
|
|
50
|
-
(0, typeorm_1.UpdateDateColumn)({
|
|
51
|
-
name: 'updated_at',
|
|
52
|
-
type: 'timestamptz',
|
|
53
|
-
default: () => 'CURRENT_TIMESTAMP',
|
|
54
|
-
}),
|
|
55
|
-
__metadata("design:type", Date)
|
|
56
|
-
], UserClientContext.prototype, "updatedAt", void 0);
|
|
57
|
-
exports.UserClientContext = UserClientContext = __decorate([
|
|
58
|
-
(0, typeorm_1.Entity)('USER_CLIENT_CONTEXT', { schema: 'stm' })
|
|
59
|
-
], UserClientContext);
|