@uniorganization/uni-lib 4.0.51 → 4.1.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/active-loads.entity.d.ts +1 -0
- package/dist/entities/active-loads.entity.js +4 -0
- package/dist/entities/applications.entity.d.ts +1 -0
- package/dist/entities/applications.entity.js +4 -0
- package/dist/entities/audit.entity.d.ts +1 -0
- package/dist/entities/audit.entity.js +4 -0
- package/dist/entities/autofail-reasons.entity.d.ts +1 -0
- package/dist/entities/autofail-reasons.entity.js +4 -0
- package/dist/entities/blacklist.entity.d.ts +1 -0
- package/dist/entities/blacklist.entity.js +5 -1
- package/dist/entities/bp-alerts.entity.d.ts +1 -0
- package/dist/entities/bp-alerts.entity.js +4 -0
- package/dist/entities/business-schedule-day.entity.d.ts +1 -0
- package/dist/entities/business-schedule-day.entity.js +4 -0
- package/dist/entities/business-schedule.entity.d.ts +1 -0
- package/dist/entities/business-schedule.entity.js +4 -0
- package/dist/entities/call-driver-data.entity.d.ts +1 -0
- package/dist/entities/call-driver-data.entity.js +4 -0
- package/dist/entities/call-drivers.entity.d.ts +1 -0
- package/dist/entities/call-drivers.entity.js +4 -0
- package/dist/entities/cb-completed-reasons.entity.d.ts +1 -0
- package/dist/entities/cb-completed-reasons.entity.js +4 -0
- package/dist/entities/change-alert.entity.d.ts +1 -0
- package/dist/entities/change-alert.entity.js +4 -0
- package/dist/entities/claim-report.entity.d.ts +1 -0
- package/dist/entities/claim-report.entity.js +6 -2
- package/dist/entities/client-credential.entity.d.ts +17 -0
- package/dist/entities/client-credential.entity.js +87 -0
- package/dist/entities/client.entity.d.ts +12 -0
- package/dist/entities/client.entity.js +67 -0
- package/dist/entities/config.entity.d.ts +1 -0
- package/dist/entities/config.entity.js +4 -0
- package/dist/entities/contact-search.entity.d.ts +1 -0
- package/dist/entities/contact-search.entity.js +17 -13
- package/dist/entities/daily-payment-status.entity.d.ts +1 -0
- package/dist/entities/daily-payment-status.entity.js +4 -0
- package/dist/entities/daily-payment.entity.d.ts +58 -0
- package/dist/entities/daily-payment.entity.js +248 -0
- package/dist/entities/daily-pending.entity.d.ts +1 -0
- package/dist/entities/daily-pending.entity.js +5 -1
- package/dist/entities/depreciation-categories.entity.d.ts +1 -0
- package/dist/entities/depreciation-categories.entity.js +4 -0
- package/dist/entities/depreciation-details.entity.d.ts +1 -0
- package/dist/entities/depreciation-details.entity.js +4 -0
- package/dist/entities/detail-type.entity.d.ts +1 -0
- package/dist/entities/detail-type.entity.js +4 -0
- package/dist/entities/dispute-request.entity.d.ts +1 -0
- package/dist/entities/dispute-request.entity.js +4 -0
- package/dist/entities/enr-calculation-log.entity.d.ts +1 -0
- package/dist/entities/enr-calculation-log.entity.js +4 -0
- package/dist/entities/enr-inventory.entity.d.ts +1 -0
- package/dist/entities/enr-inventory.entity.js +4 -0
- package/dist/entities/enr-results.entity.d.ts +1 -0
- package/dist/entities/enr-results.entity.js +4 -0
- package/dist/entities/escalation-category.entity.d.ts +1 -0
- package/dist/entities/escalation-category.entity.js +4 -0
- package/dist/entities/escalation-notes.entity.d.ts +1 -0
- package/dist/entities/escalation-notes.entity.js +4 -0
- package/dist/entities/escalation-outcome.entity.d.ts +1 -0
- package/dist/entities/escalation-outcome.entity.js +4 -0
- package/dist/entities/escalation-status-log.entity.d.ts +1 -0
- package/dist/entities/escalation-status-log.entity.js +4 -0
- package/dist/entities/escalation-status.entity.d.ts +1 -0
- package/dist/entities/escalation-status.entity.js +4 -0
- package/dist/entities/escalation-type.entity.d.ts +1 -0
- package/dist/entities/escalation-type.entity.js +4 -0
- package/dist/entities/escalations.entity.d.ts +1 -0
- package/dist/entities/escalations.entity.js +4 -0
- package/dist/entities/evaluation-autofail-reasons.entity.d.ts +1 -0
- package/dist/entities/evaluation-autofail-reasons.entity.js +4 -0
- package/dist/entities/evaluation-data.entity.d.ts +1 -0
- package/dist/entities/evaluation-data.entity.js +4 -0
- package/dist/entities/evaluation-forms.entity.d.ts +1 -0
- package/dist/entities/evaluation-forms.entity.js +4 -0
- package/dist/entities/evaluation-questions.entity.d.ts +1 -0
- package/dist/entities/evaluation-questions.entity.js +4 -0
- package/dist/entities/evaluations.entity.d.ts +1 -0
- package/dist/entities/evaluations.entity.js +4 -0
- package/dist/entities/feedback.entity.d.ts +1 -0
- package/dist/entities/feedback.entity.js +4 -0
- package/dist/entities/file-contents.entity.d.ts +1 -0
- package/dist/entities/file-contents.entity.js +4 -0
- package/dist/entities/file-type.entity.d.ts +1 -0
- package/dist/entities/file-type.entity.js +5 -2
- package/dist/entities/file-upload.entity.d.ts +1 -0
- package/dist/entities/file-upload.entity.js +4 -0
- package/dist/entities/file.entity.d.ts +1 -0
- package/dist/entities/file.entity.js +4 -0
- package/dist/entities/form-definition.entity.d.ts +1 -0
- package/dist/entities/form-definition.entity.js +4 -0
- package/dist/entities/form-fields.entity.d.ts +1 -0
- package/dist/entities/form-fields.entity.js +4 -0
- package/dist/entities/form.entity.d.ts +1 -0
- package/dist/entities/form.entity.js +4 -0
- package/dist/entities/inbox/agent-extension-backup.entity.d.ts +1 -0
- package/dist/entities/inbox/agent-extension-backup.entity.js +10 -2
- package/dist/entities/inbox/agent-extension.entity.d.ts +1 -0
- package/dist/entities/inbox/agent-extension.entity.js +6 -2
- package/dist/entities/inbox/assignment.entity.d.ts +1 -0
- package/dist/entities/inbox/assignment.entity.js +5 -3
- package/dist/entities/inbox/case-event.entity.d.ts +1 -0
- package/dist/entities/inbox/case-event.entity.js +4 -0
- package/dist/entities/inbox/case-file.entity.d.ts +1 -0
- package/dist/entities/inbox/case-file.entity.js +4 -0
- package/dist/entities/inbox/case-link.entity.d.ts +1 -0
- package/dist/entities/inbox/case-link.entity.js +4 -0
- package/dist/entities/inbox/case-note.entity.d.ts +1 -0
- package/dist/entities/inbox/case-note.entity.js +4 -0
- package/dist/entities/inbox/case-tag.entity.d.ts +1 -0
- package/dist/entities/inbox/case-tag.entity.js +4 -0
- package/dist/entities/inbox/case-text.entity.d.ts +1 -0
- package/dist/entities/inbox/case-text.entity.js +5 -3
- package/dist/entities/inbox/contact-attempt.entity.d.ts +1 -0
- package/dist/entities/inbox/contact-attempt.entity.js +4 -0
- package/dist/entities/inbox/inbound-message.entity.d.ts +1 -0
- package/dist/entities/inbox/inbound-message.entity.js +5 -1
- package/dist/entities/inbox/message-case.entity.d.ts +1 -0
- package/dist/entities/inbox/message-case.entity.js +9 -3
- package/dist/entities/inbox/notification.entity.d.ts +1 -0
- package/dist/entities/inbox/notification.entity.js +4 -0
- package/dist/entities/inbox/sla-policy.entity.d.ts +1 -0
- package/dist/entities/inbox/sla-policy.entity.js +7 -2
- package/dist/entities/inbox/tag.entity.d.ts +1 -0
- package/dist/entities/inbox/tag.entity.js +7 -2
- package/dist/entities/incoterms.entity.d.ts +1 -0
- package/dist/entities/incoterms.entity.js +4 -0
- package/dist/entities/index.d.ts +2 -0
- package/dist/entities/index.js +2 -0
- package/dist/entities/inventory.entity.d.ts +1 -0
- package/dist/entities/inventory.entity.js +4 -0
- package/dist/entities/kenko.entity.d.ts +1 -0
- package/dist/entities/kenko.entity.js +4 -0
- package/dist/entities/lob-assignment.entity.d.ts +1 -0
- package/dist/entities/lob-assignment.entity.js +4 -0
- package/dist/entities/lob-call-drivers.entity.d.ts +1 -0
- package/dist/entities/lob-call-drivers.entity.js +4 -0
- package/dist/entities/location-addresses.entity.d.ts +1 -0
- package/dist/entities/location-addresses.entity.js +4 -0
- package/dist/entities/ltp-history-transactions.entity.d.ts +1 -0
- package/dist/entities/ltp-history-transactions.entity.js +4 -0
- package/dist/entities/ltp-stm-roster.entity.d.ts +1 -0
- package/dist/entities/ltp-stm-roster.entity.js +4 -0
- package/dist/entities/modules-roles.entity.d.ts +1 -0
- package/dist/entities/modules-roles.entity.js +4 -0
- package/dist/entities/offphone-activities.entity.d.ts +1 -0
- package/dist/entities/offphone-activities.entity.js +4 -0
- package/dist/entities/onsite-ordering.entity.d.ts +1 -0
- package/dist/entities/onsite-ordering.entity.js +4 -0
- package/dist/entities/ost.entity.d.ts +1 -0
- package/dist/entities/ost.entity.js +4 -0
- package/dist/entities/otwe-offers.entity.d.ts +1 -0
- package/dist/entities/otwe-offers.entity.js +4 -0
- package/dist/entities/outbound-ticket-history.entity.d.ts +1 -0
- package/dist/entities/outbound-ticket-history.entity.js +4 -0
- package/dist/entities/p1-service-center.entity.d.ts +1 -0
- package/dist/entities/p1-service-center.entity.js +4 -0
- package/dist/entities/p1-service-network.entity.d.ts +1 -0
- package/dist/entities/p1-service-network.entity.js +4 -0
- package/dist/entities/pending-ticket-history.entity.d.ts +1 -0
- package/dist/entities/pending-ticket-history.entity.js +4 -0
- package/dist/entities/product-codes.entity.d.ts +1 -0
- package/dist/entities/product-codes.entity.js +4 -0
- package/dist/entities/question-group.entity.d.ts +1 -0
- package/dist/entities/question-group.entity.js +4 -0
- package/dist/entities/questions.entity.d.ts +1 -0
- package/dist/entities/questions.entity.js +4 -0
- package/dist/entities/raw_roster.entity.d.ts +1 -0
- package/dist/entities/raw_roster.entity.js +4 -0
- package/dist/entities/regional-service-mgr.entity.d.ts +1 -0
- package/dist/entities/regional-service-mgr.entity.js +4 -0
- package/dist/entities/role-definition.entity.d.ts +1 -0
- package/dist/entities/role-definition.entity.js +4 -0
- package/dist/entities/role-privileges.entity.d.ts +1 -0
- package/dist/entities/role-privileges.entity.js +4 -0
- package/dist/entities/roster-personnel.entity.d.ts +1 -0
- package/dist/entities/roster-personnel.entity.js +4 -0
- package/dist/entities/sap-raw-data.entity.d.ts +1 -0
- package/dist/entities/sap-raw-data.entity.js +4 -0
- package/dist/entities/service-center-distance-cache.entity.d.ts +1 -0
- package/dist/entities/service-center-distance-cache.entity.js +5 -1
- package/dist/entities/service-center-geocode-cache.entity.d.ts +1 -0
- package/dist/entities/service-center-geocode-cache.entity.js +5 -1
- package/dist/entities/service-center-interaction.entity.d.ts +1 -0
- package/dist/entities/service-center-interaction.entity.js +4 -0
- package/dist/entities/service-center-phone.entity.d.ts +1 -0
- package/dist/entities/service-center-phone.entity.js +4 -0
- package/dist/entities/service-center-ranking.entity.d.ts +1 -0
- package/dist/entities/service-center-ranking.entity.js +4 -0
- package/dist/entities/service-center-review.entity.d.ts +1 -0
- package/dist/entities/service-center-review.entity.js +4 -0
- package/dist/entities/service-center-unsupported-model.entity.d.ts +1 -0
- package/dist/entities/service-center-unsupported-model.entity.js +5 -1
- package/dist/entities/service-center.entity.d.ts +1 -0
- package/dist/entities/service-center.entity.js +6 -2
- package/dist/entities/service-type.entity.d.ts +1 -0
- package/dist/entities/service-type.entity.js +4 -0
- package/dist/entities/skipped-ticket.entity.d.ts +1 -0
- package/dist/entities/skipped-ticket.entity.js +4 -0
- package/dist/entities/state.entity.d.ts +1 -0
- package/dist/entities/state.entity.js +4 -0
- package/dist/entities/template.entity.d.ts +1 -0
- package/dist/entities/template.entity.js +4 -0
- package/dist/entities/ticket-queue.entity.d.ts +1 -0
- package/dist/entities/ticket-queue.entity.js +4 -0
- package/dist/entities/ticket-service-center-match-loa-pricing.entity.d.ts +1 -0
- package/dist/entities/ticket-service-center-match-loa-pricing.entity.js +4 -0
- package/dist/entities/ticket-service-center-match-process.entity.d.ts +1 -0
- package/dist/entities/ticket-service-center-match-process.entity.js +4 -0
- package/dist/entities/transactions.entity.d.ts +1 -0
- package/dist/entities/transactions.entity.js +4 -0
- package/dist/entities/user-campaign.entity.d.ts +1 -0
- package/dist/entities/user-campaign.entity.js +4 -0
- package/dist/entities/user-roles.entity.d.ts +4 -0
- package/dist/entities/user-roles.entity.js +22 -3
- package/dist/entities/usr.entity.d.ts +1 -0
- package/dist/entities/usr.entity.js +4 -0
- package/dist/entities/vw-escalation-age.d.ts +1 -0
- package/dist/entities/vw-escalation-age.js +4 -0
- package/dist/entities/warranty-category.entity.d.ts +1 -0
- package/dist/entities/warranty-category.entity.js +4 -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/common.module.js +5 -4
- package/dist/modules/common/jwt-auth.guard.d.ts +5 -2
- package/dist/modules/common/jwt-auth.guard.js +20 -12
- package/dist/modules/common/jwt.strategy.d.ts +6 -18
- package/dist/modules/common/jwt.strategy.js +80 -16
- package/dist/modules/common/logged-user.decorator.js +2 -2
- package/dist/modules/common/skip-jwt-auth.decorator.d.ts +3 -1
- package/dist/modules/common/skip-jwt-auth.decorator.js +5 -2
- package/dist/modules/file-storage/file-storage.service.d.ts +5 -1
- package/dist/modules/file-storage/file-storage.service.js +64 -10
- package/dist/modules/index.d.ts +1 -0
- package/dist/modules/index.js +1 -0
- package/dist/modules/tenant/current-tenant.decorator.d.ts +1 -0
- package/dist/modules/tenant/current-tenant.decorator.js +14 -0
- package/dist/modules/tenant/index.d.ts +21 -0
- package/dist/modules/tenant/index.js +37 -0
- package/dist/modules/tenant/master-tenant.decorator.d.ts +1 -0
- package/dist/modules/tenant/master-tenant.decorator.js +7 -0
- package/dist/modules/tenant/master-tenant.guard.d.ts +7 -0
- package/dist/modules/tenant/master-tenant.guard.js +44 -0
- package/dist/modules/tenant/redis-tenant-state.store.d.ts +21 -0
- package/dist/modules/tenant/redis-tenant-state.store.js +165 -0
- package/dist/modules/tenant/tenant-audit.types.d.ts +15 -0
- package/dist/modules/tenant/tenant-audit.types.js +2 -0
- package/dist/modules/tenant/tenant-authorization.keys.d.ts +3 -0
- package/dist/modules/tenant/tenant-authorization.keys.js +28 -0
- package/dist/modules/tenant/tenant-authorization.service.d.ts +24 -0
- package/dist/modules/tenant/tenant-authorization.service.js +235 -0
- package/dist/modules/tenant/tenant-authorization.store.d.ts +8 -0
- package/dist/modules/tenant/tenant-authorization.store.js +4 -0
- package/dist/modules/tenant/tenant-authorization.types.d.ts +36 -0
- package/dist/modules/tenant/tenant-authorization.types.js +2 -0
- package/dist/modules/tenant/tenant-context.errors.d.ts +3 -0
- package/dist/modules/tenant/tenant-context.errors.js +10 -0
- package/dist/modules/tenant/tenant-context.interceptor.d.ts +9 -0
- package/dist/modules/tenant/tenant-context.interceptor.js +69 -0
- package/dist/modules/tenant/tenant-context.service.d.ts +15 -0
- package/dist/modules/tenant/tenant-context.service.js +56 -0
- package/dist/modules/tenant/tenant-context.storage.d.ts +6 -0
- package/dist/modules/tenant/tenant-context.storage.js +34 -0
- package/dist/modules/tenant/tenant-credential.guard.d.ts +13 -0
- package/dist/modules/tenant/tenant-credential.guard.js +119 -0
- package/dist/modules/tenant/tenant-ownership.service.d.ts +7 -0
- package/dist/modules/tenant/tenant-ownership.service.js +28 -0
- package/dist/modules/tenant/tenant-query.helpers.d.ts +12 -0
- package/dist/modules/tenant/tenant-query.helpers.js +37 -0
- package/dist/modules/tenant/tenant-runner.service.d.ts +7 -0
- package/dist/modules/tenant/tenant-runner.service.js +41 -0
- package/dist/modules/tenant/tenant-security-state.service.d.ts +11 -0
- package/dist/modules/tenant/tenant-security-state.service.js +75 -0
- package/dist/modules/tenant/tenant-security-state.store.d.ts +7 -0
- package/dist/modules/tenant/tenant-security-state.store.js +4 -0
- package/dist/modules/tenant/tenant.constants.d.ts +7 -0
- package/dist/modules/tenant/tenant.constants.js +10 -0
- package/dist/modules/tenant/tenant.module.d.ts +2 -0
- package/dist/modules/tenant/tenant.module.js +70 -0
- package/dist/modules/tenant/tenant.types.d.ts +69 -0
- package/dist/modules/tenant/tenant.types.js +2 -0
- package/package.json +14 -12
|
@@ -8,9 +8,6 @@ var __decorate = (this && this.__decorate) || function (decorators, target, key,
|
|
|
8
8
|
var __metadata = (this && this.__metadata) || function (k, v) {
|
|
9
9
|
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
10
10
|
};
|
|
11
|
-
var __param = (this && this.__param) || function (paramIndex, decorator) {
|
|
12
|
-
return function (target, key) { decorator(target, key, paramIndex); }
|
|
13
|
-
};
|
|
14
11
|
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
15
12
|
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
16
13
|
return new (P || (P = Promise))(function (resolve, reject) {
|
|
@@ -24,33 +21,100 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
24
21
|
exports.JwtStrategy = void 0;
|
|
25
22
|
const common_1 = require("@nestjs/common");
|
|
26
23
|
const passport_1 = require("@nestjs/passport");
|
|
27
|
-
const typeorm_1 = require("@nestjs/typeorm");
|
|
28
24
|
const passport_jwt_1 = require("passport-jwt");
|
|
29
|
-
const
|
|
30
|
-
const typeorm_2 = require("typeorm");
|
|
25
|
+
const tenant_1 = require("../tenant");
|
|
31
26
|
let JwtStrategy = class JwtStrategy extends (0, passport_1.PassportStrategy)(passport_jwt_1.Strategy) {
|
|
32
|
-
constructor(
|
|
27
|
+
constructor(authorization, securityState) {
|
|
33
28
|
super({
|
|
34
29
|
jwtFromRequest: passport_jwt_1.ExtractJwt.fromAuthHeaderAsBearerToken(),
|
|
35
|
-
ignoreExpiration:
|
|
30
|
+
ignoreExpiration: process.env.JWT_IGNORE_EXPIRATION === 'true',
|
|
36
31
|
secretOrKey: process.env.JWT_SECRET,
|
|
37
32
|
});
|
|
38
|
-
this.
|
|
33
|
+
this.authorization = authorization;
|
|
34
|
+
this.securityState = securityState;
|
|
39
35
|
}
|
|
40
36
|
validate(payload) {
|
|
41
37
|
return __awaiter(this, void 0, void 0, function* () {
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
38
|
+
var _a, _b, _c;
|
|
39
|
+
const signedUser = payload === null || payload === void 0 ? void 0 : payload.user;
|
|
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
|
+
const originalClientId = (_a = signedUser === null || signedUser === void 0 ? void 0 : signedUser.originalClientId) !== null && _a !== void 0 ? _a : null;
|
|
43
|
+
const now = Math.floor(Date.now() / 1000);
|
|
44
|
+
if ((payload === null || payload === void 0 ? void 0 : payload.type) !== 'access' ||
|
|
45
|
+
!signedUser ||
|
|
46
|
+
!Number.isInteger(signedUser.id) ||
|
|
47
|
+
String(signedUser.id) !== payload.sub ||
|
|
48
|
+
!Number.isInteger(effectiveClientId) ||
|
|
49
|
+
effectiveClientId <= 0 ||
|
|
50
|
+
!Number.isInteger(homeClientId) ||
|
|
51
|
+
homeClientId <= 0 ||
|
|
52
|
+
!Number.isInteger(payload.exp) ||
|
|
53
|
+
payload.exp <= now ||
|
|
54
|
+
!this.validTokenIdentifier(payload.jti) ||
|
|
55
|
+
signedUser.jti !== payload.jti ||
|
|
56
|
+
signedUser.tokenExpiresAt !== payload.exp) {
|
|
57
|
+
throw new common_1.UnauthorizedException();
|
|
58
|
+
}
|
|
59
|
+
if (yield this.securityState.isAccessTokenRevoked(payload.jti)) {
|
|
60
|
+
throw new common_1.UnauthorizedException();
|
|
45
61
|
}
|
|
46
|
-
const
|
|
47
|
-
|
|
62
|
+
const impersonating = originalClientId !== null;
|
|
63
|
+
if ((impersonating &&
|
|
64
|
+
(originalClientId !== tenant_1.NEWTECH_CLIENT_ID ||
|
|
65
|
+
homeClientId !== tenant_1.NEWTECH_CLIENT_ID ||
|
|
66
|
+
effectiveClientId === tenant_1.NEWTECH_CLIENT_ID ||
|
|
67
|
+
!((_b = signedUser.roles) === null || _b === void 0 ? void 0 : _b.includes(tenant_1.TENANT_IMPERSONATOR_ROLE)) ||
|
|
68
|
+
!signedUser.impersonatedAt ||
|
|
69
|
+
!signedUser.impersonationReason)) ||
|
|
70
|
+
(!impersonating && ((_c = signedUser.roles) === null || _c === void 0 ? void 0 : _c.includes(tenant_1.TENANT_IMPERSONATOR_ROLE)))) {
|
|
71
|
+
throw new common_1.UnauthorizedException();
|
|
72
|
+
}
|
|
73
|
+
const resolved = impersonating
|
|
74
|
+
? yield this.authorization.resolveImpersonation(signedUser.id, homeClientId, effectiveClientId)
|
|
75
|
+
: yield this.authorization.resolve(signedUser.id, effectiveClientId, homeClientId);
|
|
76
|
+
const { identity, snapshot } = resolved;
|
|
77
|
+
const isMasterTenantAdmin = !impersonating &&
|
|
78
|
+
snapshot.clientId === tenant_1.NEWTECH_CLIENT_ID &&
|
|
79
|
+
snapshot.roles.some((role) => role.moduleName.toLowerCase() === 'root' &&
|
|
80
|
+
role.roleName.toLowerCase() === 'sysadmin');
|
|
81
|
+
return {
|
|
82
|
+
id: identity.id,
|
|
83
|
+
first_name: identity.firstName,
|
|
84
|
+
username: identity.username,
|
|
85
|
+
last_name: identity.lastName,
|
|
86
|
+
division: identity.division,
|
|
87
|
+
lob: identity.lob,
|
|
88
|
+
fullName: identity.fullName,
|
|
89
|
+
ntgid: identity.ntgid,
|
|
90
|
+
profile: identity.profile,
|
|
91
|
+
password_expired: identity.passwordExpired,
|
|
92
|
+
viewEvaluations: identity.viewEvaluations,
|
|
93
|
+
ern: identity.ern,
|
|
94
|
+
homeClientId: identity.homeClientId,
|
|
95
|
+
clientId: snapshot.clientId,
|
|
96
|
+
clientAlias: snapshot.clientAlias,
|
|
97
|
+
clientName: snapshot.clientName,
|
|
98
|
+
jti: payload.jti,
|
|
99
|
+
tokenExpiresAt: payload.exp,
|
|
100
|
+
originalClientId,
|
|
101
|
+
impersonatedAt: impersonating ? signedUser.impersonatedAt : null,
|
|
102
|
+
impersonationReason: impersonating
|
|
103
|
+
? signedUser.impersonationReason
|
|
104
|
+
: null,
|
|
105
|
+
roles: Array.from(new Set(snapshot.roles.map((role) => role.roleName))),
|
|
106
|
+
privileges: snapshot.privileges,
|
|
107
|
+
isMasterTenantAdmin,
|
|
108
|
+
};
|
|
48
109
|
});
|
|
49
110
|
}
|
|
111
|
+
validTokenIdentifier(value) {
|
|
112
|
+
return /^[A-Za-z0-9._:-]{1,128}$/.test(value || '');
|
|
113
|
+
}
|
|
50
114
|
};
|
|
51
115
|
exports.JwtStrategy = JwtStrategy;
|
|
52
116
|
exports.JwtStrategy = JwtStrategy = __decorate([
|
|
53
117
|
(0, common_1.Injectable)(),
|
|
54
|
-
|
|
55
|
-
|
|
118
|
+
__metadata("design:paramtypes", [tenant_1.TenantAuthorizationService,
|
|
119
|
+
tenant_1.TenantSecurityStateService])
|
|
56
120
|
], JwtStrategy);
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.LoggedUser = void 0;
|
|
4
4
|
const common_1 = require("@nestjs/common");
|
|
5
|
-
exports.LoggedUser = (0, common_1.createParamDecorator)((
|
|
5
|
+
exports.LoggedUser = (0, common_1.createParamDecorator)((_data, ctx) => {
|
|
6
6
|
const request = ctx.switchToHttp().getRequest();
|
|
7
|
-
return request
|
|
7
|
+
return request.user;
|
|
8
8
|
});
|
|
@@ -1,2 +1,4 @@
|
|
|
1
|
+
import { PublicRouteOptions } from '../tenant';
|
|
1
2
|
export declare const SKIP_JWT_AUTH_KEY = "skipJwtAuth";
|
|
2
|
-
export declare const
|
|
3
|
+
export declare const Public: (options?: PublicRouteOptions) => <TFunction extends Function, Y>(target: TFunction | object, propertyKey?: string | symbol, descriptor?: TypedPropertyDescriptor<Y>) => void;
|
|
4
|
+
export declare const SkipJwtAuth: () => <TFunction extends Function, Y>(target: TFunction | object, propertyKey?: string | symbol, descriptor?: TypedPropertyDescriptor<Y>) => void;
|
|
@@ -1,7 +1,10 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.SkipJwtAuth = exports.SKIP_JWT_AUTH_KEY = void 0;
|
|
3
|
+
exports.SkipJwtAuth = exports.Public = exports.SKIP_JWT_AUTH_KEY = void 0;
|
|
4
4
|
const common_1 = require("@nestjs/common");
|
|
5
|
+
const tenant_1 = require("../tenant");
|
|
5
6
|
exports.SKIP_JWT_AUTH_KEY = 'skipJwtAuth';
|
|
6
|
-
const
|
|
7
|
+
const Public = (options = { tenant: 'tenantless' }) => (0, common_1.applyDecorators)((0, common_1.SetMetadata)(exports.SKIP_JWT_AUTH_KEY, true), (0, common_1.SetMetadata)(tenant_1.PUBLIC_ROUTE_METADATA_KEY, options));
|
|
8
|
+
exports.Public = Public;
|
|
9
|
+
const SkipJwtAuth = () => (0, exports.Public)({ tenant: 'tenantless' });
|
|
7
10
|
exports.SkipJwtAuth = SkipJwtAuth;
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { Repository } from 'typeorm';
|
|
2
2
|
import { FileEntity } from '../../entities/file.entity';
|
|
3
3
|
import { FileTypeEntity } from '../../entities/file-type.entity';
|
|
4
|
+
import { TenantContext } from '../tenant/tenant-context.service';
|
|
4
5
|
export interface FileStorageUploadOptions {
|
|
5
6
|
fileTypeCode?: string;
|
|
6
7
|
fileTypeId?: number;
|
|
@@ -16,13 +17,16 @@ export interface FileStorageUploadFile {
|
|
|
16
17
|
export declare class FileStorageService {
|
|
17
18
|
private readonly fileRepository;
|
|
18
19
|
private readonly fileTypeRepository;
|
|
20
|
+
private readonly tenantContext?;
|
|
19
21
|
private readonly logger;
|
|
20
22
|
private readonly s3Client;
|
|
21
|
-
constructor(fileRepository: Repository<FileEntity>, fileTypeRepository: Repository<FileTypeEntity
|
|
23
|
+
constructor(fileRepository: Repository<FileEntity>, fileTypeRepository: Repository<FileTypeEntity>, tenantContext?: TenantContext);
|
|
22
24
|
uploadDocument(file: FileStorageUploadFile, options: FileStorageUploadOptions): Promise<FileEntity>;
|
|
23
25
|
deleteDocument(file: Pick<FileEntity, 'id' | 'path'>): Promise<void>;
|
|
24
26
|
downloadDocument(bucketPath: string): Promise<Buffer>;
|
|
25
27
|
resolveFileType(fileTypeCode?: string, fileTypeId?: number): Promise<FileTypeEntity>;
|
|
28
|
+
private findFileType;
|
|
29
|
+
private getClientId;
|
|
26
30
|
private createS3Client;
|
|
27
31
|
private putObject;
|
|
28
32
|
private deleteObject;
|
|
@@ -37,11 +37,13 @@ const typeorm_2 = require("typeorm");
|
|
|
37
37
|
const node_crypto_1 = require("node:crypto");
|
|
38
38
|
const file_entity_1 = require("../../entities/file.entity");
|
|
39
39
|
const file_type_entity_1 = require("../../entities/file-type.entity");
|
|
40
|
+
const tenant_context_service_1 = require("../tenant/tenant-context.service");
|
|
40
41
|
const constants_1 = require("./constants");
|
|
41
42
|
let FileStorageService = FileStorageService_1 = class FileStorageService {
|
|
42
|
-
constructor(fileRepository, fileTypeRepository) {
|
|
43
|
+
constructor(fileRepository, fileTypeRepository, tenantContext) {
|
|
43
44
|
this.fileRepository = fileRepository;
|
|
44
45
|
this.fileTypeRepository = fileTypeRepository;
|
|
46
|
+
this.tenantContext = tenantContext;
|
|
45
47
|
this.logger = new common_1.Logger(FileStorageService_1.name);
|
|
46
48
|
this.s3Client = this.createS3Client();
|
|
47
49
|
}
|
|
@@ -58,11 +60,16 @@ let FileStorageService = FileStorageService_1 = class FileStorageService {
|
|
|
58
60
|
const extension = (0, constants_1.extractFileExtension)(file.originalname);
|
|
59
61
|
const uniqueId = (0, node_crypto_1.randomUUID)();
|
|
60
62
|
const bucketPrefix = process.env[constants_1.FILE_STORAGE_BUCKET_PREFIX_ENV];
|
|
63
|
+
const clientId = this.getClientId();
|
|
64
|
+
const tenantBucketPrefix = [bucketPrefix, `client-${clientId}`]
|
|
65
|
+
.filter(Boolean)
|
|
66
|
+
.join('/');
|
|
61
67
|
const bucketName = this.getRequiredEnv(constants_1.FILE_STORAGE_BUCKET_NAME_ENV);
|
|
62
|
-
const bucketPath = (0, constants_1.buildBucketPath)(
|
|
68
|
+
const bucketPath = (0, constants_1.buildBucketPath)(tenantBucketPrefix, fileType.code, uniqueId, file.originalname);
|
|
63
69
|
yield this.putObject(bucketName, bucketPath, file);
|
|
64
70
|
try {
|
|
65
71
|
const fileRecord = this.fileRepository.create({
|
|
72
|
+
clientId,
|
|
66
73
|
name: file.originalname,
|
|
67
74
|
typeId: fileType.id,
|
|
68
75
|
path: bucketPath,
|
|
@@ -82,17 +89,38 @@ let FileStorageService = FileStorageService_1 = class FileStorageService {
|
|
|
82
89
|
deleteDocument(file) {
|
|
83
90
|
return __awaiter(this, void 0, void 0, function* () {
|
|
84
91
|
const bucketName = this.getRequiredEnv(constants_1.FILE_STORAGE_BUCKET_NAME_ENV);
|
|
85
|
-
yield this.
|
|
86
|
-
|
|
92
|
+
const ownedFile = yield this.fileRepository.findOne({
|
|
93
|
+
where: {
|
|
94
|
+
id: file.id,
|
|
95
|
+
clientId: this.getClientId(),
|
|
96
|
+
},
|
|
97
|
+
});
|
|
98
|
+
if (!ownedFile) {
|
|
99
|
+
throw new Error('File not found');
|
|
100
|
+
}
|
|
101
|
+
yield this.deleteObject(bucketName, ownedFile.path);
|
|
102
|
+
yield this.fileRepository.softDelete({
|
|
103
|
+
id: ownedFile.id,
|
|
104
|
+
clientId: this.getClientId(),
|
|
105
|
+
});
|
|
87
106
|
});
|
|
88
107
|
}
|
|
89
108
|
downloadDocument(bucketPath) {
|
|
90
109
|
return __awaiter(this, void 0, void 0, function* () {
|
|
91
110
|
const bucketName = this.getRequiredEnv(constants_1.FILE_STORAGE_BUCKET_NAME_ENV);
|
|
111
|
+
const ownedFile = yield this.fileRepository.findOne({
|
|
112
|
+
where: {
|
|
113
|
+
path: bucketPath,
|
|
114
|
+
clientId: this.getClientId(),
|
|
115
|
+
},
|
|
116
|
+
});
|
|
117
|
+
if (!ownedFile) {
|
|
118
|
+
throw new Error('File not found');
|
|
119
|
+
}
|
|
92
120
|
try {
|
|
93
121
|
const response = yield this.s3Client.send(new client_s3_1.GetObjectCommand({
|
|
94
122
|
Bucket: bucketName,
|
|
95
|
-
Key:
|
|
123
|
+
Key: ownedFile.path,
|
|
96
124
|
}));
|
|
97
125
|
if (!response.Body) {
|
|
98
126
|
throw new Error(`Empty body returned for bucket path "${bucketPath}"`);
|
|
@@ -111,8 +139,8 @@ let FileStorageService = FileStorageService_1 = class FileStorageService {
|
|
|
111
139
|
return __awaiter(this, void 0, void 0, function* () {
|
|
112
140
|
if (fileTypeCode && typeof fileTypeId === 'number') {
|
|
113
141
|
const [byCode, byId] = yield Promise.all([
|
|
114
|
-
this.
|
|
115
|
-
this.
|
|
142
|
+
this.findFileType({ code: fileTypeCode }),
|
|
143
|
+
this.findFileType({ id: fileTypeId }),
|
|
116
144
|
]);
|
|
117
145
|
if (!byCode) {
|
|
118
146
|
throw new Error(`File type not found for code "${fileTypeCode}"`);
|
|
@@ -126,14 +154,14 @@ let FileStorageService = FileStorageService_1 = class FileStorageService {
|
|
|
126
154
|
return byCode;
|
|
127
155
|
}
|
|
128
156
|
if (fileTypeCode) {
|
|
129
|
-
const fileType = yield this.
|
|
157
|
+
const fileType = yield this.findFileType({ code: fileTypeCode });
|
|
130
158
|
if (!fileType) {
|
|
131
159
|
throw new Error(`File type not found for code "${fileTypeCode}"`);
|
|
132
160
|
}
|
|
133
161
|
return fileType;
|
|
134
162
|
}
|
|
135
163
|
if (typeof fileTypeId === 'number') {
|
|
136
|
-
const fileType = yield this.
|
|
164
|
+
const fileType = yield this.findFileType({ id: fileTypeId });
|
|
137
165
|
if (!fileType) {
|
|
138
166
|
throw new Error(`File type not found for id "${fileTypeId}"`);
|
|
139
167
|
}
|
|
@@ -142,6 +170,30 @@ let FileStorageService = FileStorageService_1 = class FileStorageService {
|
|
|
142
170
|
throw new Error('Either fileTypeCode or fileTypeId must be provided');
|
|
143
171
|
});
|
|
144
172
|
}
|
|
173
|
+
findFileType(options) {
|
|
174
|
+
const clientId = this.getClientId();
|
|
175
|
+
const query = this.fileTypeRepository
|
|
176
|
+
.createQueryBuilder('fileType')
|
|
177
|
+
.where('(fileType.client_id = :clientId OR fileType.client_id IS NULL)', {
|
|
178
|
+
clientId,
|
|
179
|
+
})
|
|
180
|
+
.andWhere('fileType.deletedDate IS NULL')
|
|
181
|
+
.orderBy('CASE WHEN fileType.client_id = :clientId THEN 0 ELSE 1 END', 'ASC')
|
|
182
|
+
.setParameter('clientId', clientId);
|
|
183
|
+
if (options.code) {
|
|
184
|
+
query.andWhere('fileType.code = :code', { code: options.code });
|
|
185
|
+
}
|
|
186
|
+
if (typeof options.id === 'number') {
|
|
187
|
+
query.andWhere('fileType.id = :id', { id: options.id });
|
|
188
|
+
}
|
|
189
|
+
return query.getOne();
|
|
190
|
+
}
|
|
191
|
+
getClientId() {
|
|
192
|
+
if (!this.tenantContext) {
|
|
193
|
+
throw new Error('File storage requires an active tenant context');
|
|
194
|
+
}
|
|
195
|
+
return this.tenantContext.getClientId();
|
|
196
|
+
}
|
|
145
197
|
createS3Client() {
|
|
146
198
|
const region = this.getRequiredEnv(constants_1.FILE_STORAGE_BUCKET_REGION_ENV);
|
|
147
199
|
const accessKeyId = this.getRequiredEnv(constants_1.FILE_STORAGE_BUCKET_ACCESS_KEY_ID_ENV);
|
|
@@ -229,6 +281,8 @@ exports.FileStorageService = FileStorageService = FileStorageService_1 = __decor
|
|
|
229
281
|
(0, common_1.Injectable)(),
|
|
230
282
|
__param(0, (0, typeorm_1.InjectRepository)(file_entity_1.FileEntity)),
|
|
231
283
|
__param(1, (0, typeorm_1.InjectRepository)(file_type_entity_1.FileTypeEntity)),
|
|
284
|
+
__param(2, (0, common_1.Optional)()),
|
|
232
285
|
__metadata("design:paramtypes", [typeorm_2.Repository,
|
|
233
|
-
typeorm_2.Repository
|
|
286
|
+
typeorm_2.Repository,
|
|
287
|
+
tenant_context_service_1.TenantContext])
|
|
234
288
|
], FileStorageService);
|
package/dist/modules/index.d.ts
CHANGED
package/dist/modules/index.js
CHANGED
|
@@ -21,3 +21,4 @@ __exportStar(require("./google-maps/google-maps.module"), exports);
|
|
|
21
21
|
__exportStar(require("./google-maps/google-maps.service"), exports);
|
|
22
22
|
__exportStar(require("./google-maps/google-maps.types"), exports);
|
|
23
23
|
__exportStar(require("./file-storage"), exports);
|
|
24
|
+
__exportStar(require("./tenant"), exports);
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const CurrentTenant: (...dataOrPipes: unknown[]) => ParameterDecorator;
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.CurrentTenant = void 0;
|
|
4
|
+
const common_1 = require("@nestjs/common");
|
|
5
|
+
const tenant_context_errors_1 = require("./tenant-context.errors");
|
|
6
|
+
exports.CurrentTenant = (0, common_1.createParamDecorator)((_data, context) => {
|
|
7
|
+
var _a;
|
|
8
|
+
const request = context.switchToHttp().getRequest();
|
|
9
|
+
const clientId = (_a = request.tenantContext) === null || _a === void 0 ? void 0 : _a.clientId;
|
|
10
|
+
if (!Number.isInteger(clientId) || !clientId || clientId <= 0) {
|
|
11
|
+
throw new tenant_context_errors_1.MissingTenantContextError();
|
|
12
|
+
}
|
|
13
|
+
return clientId;
|
|
14
|
+
});
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
export * from './current-tenant.decorator';
|
|
2
|
+
export * from './master-tenant.decorator';
|
|
3
|
+
export * from './master-tenant.guard';
|
|
4
|
+
export * from './redis-tenant-state.store';
|
|
5
|
+
export * from './tenant-audit.types';
|
|
6
|
+
export * from './tenant-authorization.keys';
|
|
7
|
+
export * from './tenant-authorization.service';
|
|
8
|
+
export * from './tenant-authorization.store';
|
|
9
|
+
export * from './tenant-authorization.types';
|
|
10
|
+
export * from './tenant.constants';
|
|
11
|
+
export * from './tenant-context.interceptor';
|
|
12
|
+
export * from './tenant-context.errors';
|
|
13
|
+
export * from './tenant-context.service';
|
|
14
|
+
export * from './tenant-credential.guard';
|
|
15
|
+
export * from './tenant.module';
|
|
16
|
+
export * from './tenant-ownership.service';
|
|
17
|
+
export * from './tenant-query.helpers';
|
|
18
|
+
export * from './tenant-runner.service';
|
|
19
|
+
export * from './tenant-security-state.service';
|
|
20
|
+
export * from './tenant-security-state.store';
|
|
21
|
+
export * from './tenant.types';
|
|
@@ -0,0 +1,37 @@
|
|
|
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("./current-tenant.decorator"), exports);
|
|
18
|
+
__exportStar(require("./master-tenant.decorator"), exports);
|
|
19
|
+
__exportStar(require("./master-tenant.guard"), exports);
|
|
20
|
+
__exportStar(require("./redis-tenant-state.store"), exports);
|
|
21
|
+
__exportStar(require("./tenant-audit.types"), exports);
|
|
22
|
+
__exportStar(require("./tenant-authorization.keys"), exports);
|
|
23
|
+
__exportStar(require("./tenant-authorization.service"), exports);
|
|
24
|
+
__exportStar(require("./tenant-authorization.store"), exports);
|
|
25
|
+
__exportStar(require("./tenant-authorization.types"), exports);
|
|
26
|
+
__exportStar(require("./tenant.constants"), exports);
|
|
27
|
+
__exportStar(require("./tenant-context.interceptor"), exports);
|
|
28
|
+
__exportStar(require("./tenant-context.errors"), exports);
|
|
29
|
+
__exportStar(require("./tenant-context.service"), exports);
|
|
30
|
+
__exportStar(require("./tenant-credential.guard"), exports);
|
|
31
|
+
__exportStar(require("./tenant.module"), exports);
|
|
32
|
+
__exportStar(require("./tenant-ownership.service"), exports);
|
|
33
|
+
__exportStar(require("./tenant-query.helpers"), exports);
|
|
34
|
+
__exportStar(require("./tenant-runner.service"), exports);
|
|
35
|
+
__exportStar(require("./tenant-security-state.service"), exports);
|
|
36
|
+
__exportStar(require("./tenant-security-state.store"), exports);
|
|
37
|
+
__exportStar(require("./tenant.types"), exports);
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const MasterTenant: () => import("@nestjs/common").CustomDecorator<string>;
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.MasterTenant = void 0;
|
|
4
|
+
const common_1 = require("@nestjs/common");
|
|
5
|
+
const tenant_constants_1 = require("./tenant.constants");
|
|
6
|
+
const MasterTenant = () => (0, common_1.SetMetadata)(tenant_constants_1.MASTER_TENANT_METADATA_KEY, true);
|
|
7
|
+
exports.MasterTenant = MasterTenant;
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { CanActivate, ExecutionContext } from '@nestjs/common';
|
|
2
|
+
import { Reflector } from '@nestjs/core';
|
|
3
|
+
export declare class MasterTenantGuard implements CanActivate {
|
|
4
|
+
private readonly reflector;
|
|
5
|
+
constructor(reflector: Reflector);
|
|
6
|
+
canActivate(context: ExecutionContext): boolean;
|
|
7
|
+
}
|
|
@@ -0,0 +1,44 @@
|
|
|
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.MasterTenantGuard = void 0;
|
|
13
|
+
const common_1 = require("@nestjs/common");
|
|
14
|
+
const core_1 = require("@nestjs/core");
|
|
15
|
+
const tenant_constants_1 = require("./tenant.constants");
|
|
16
|
+
let MasterTenantGuard = class MasterTenantGuard {
|
|
17
|
+
constructor(reflector) {
|
|
18
|
+
this.reflector = reflector;
|
|
19
|
+
}
|
|
20
|
+
canActivate(context) {
|
|
21
|
+
var _a, _b, _c, _d;
|
|
22
|
+
const required = this.reflector.getAllAndOverride(tenant_constants_1.MASTER_TENANT_METADATA_KEY, [context.getHandler(), context.getClass()]);
|
|
23
|
+
if (!required) {
|
|
24
|
+
return true;
|
|
25
|
+
}
|
|
26
|
+
const request = context.switchToHttp().getRequest();
|
|
27
|
+
if (!request.user || request.user === true) {
|
|
28
|
+
throw new common_1.UnauthorizedException();
|
|
29
|
+
}
|
|
30
|
+
const effectiveClientId = ((_a = request.tenantContext) === null || _a === void 0 ? void 0 : _a.clientId) || request.user.clientId;
|
|
31
|
+
const originalClientId = (_d = (_c = (_b = request.tenantContext) === null || _b === void 0 ? void 0 : _b.originalClientId) !== null && _c !== void 0 ? _c : request.user.originalClientId) !== null && _d !== void 0 ? _d : null;
|
|
32
|
+
if (effectiveClientId !== tenant_constants_1.NEWTECH_CLIENT_ID ||
|
|
33
|
+
originalClientId !== null ||
|
|
34
|
+
!request.user.isMasterTenantAdmin) {
|
|
35
|
+
throw new common_1.ForbiddenException();
|
|
36
|
+
}
|
|
37
|
+
return true;
|
|
38
|
+
}
|
|
39
|
+
};
|
|
40
|
+
exports.MasterTenantGuard = MasterTenantGuard;
|
|
41
|
+
exports.MasterTenantGuard = MasterTenantGuard = __decorate([
|
|
42
|
+
(0, common_1.Injectable)(),
|
|
43
|
+
__metadata("design:paramtypes", [core_1.Reflector])
|
|
44
|
+
], MasterTenantGuard);
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { OnModuleDestroy } from '@nestjs/common';
|
|
2
|
+
import { TenantAuthorizationStore } from './tenant-authorization.store';
|
|
3
|
+
import { TenantAuthorizationSnapshot } from './tenant-authorization.types';
|
|
4
|
+
import { TenantSecurityStateStore } from './tenant-security-state.store';
|
|
5
|
+
export declare class RedisTenantStateStore implements TenantAuthorizationStore, TenantSecurityStateStore, OnModuleDestroy {
|
|
6
|
+
private readonly logger;
|
|
7
|
+
private client;
|
|
8
|
+
get(key: string): Promise<TenantAuthorizationSnapshot | null>;
|
|
9
|
+
set(key: string, value: TenantAuthorizationSnapshot, ttlSeconds: number): Promise<void>;
|
|
10
|
+
delete(key: string): Promise<void>;
|
|
11
|
+
deleteMany(keys: readonly string[]): Promise<void>;
|
|
12
|
+
isRevoked(key: string): Promise<boolean>;
|
|
13
|
+
revoke(key: string, ttlSeconds: number): Promise<void>;
|
|
14
|
+
createPreAuth(key: string, userId: number, ttlSeconds: number): Promise<void>;
|
|
15
|
+
consumePreAuth(key: string, userId: number): Promise<boolean>;
|
|
16
|
+
onModuleDestroy(): Promise<void>;
|
|
17
|
+
private execute;
|
|
18
|
+
private getClient;
|
|
19
|
+
private positiveInteger;
|
|
20
|
+
private isAuthorizationSnapshot;
|
|
21
|
+
}
|