@uniorganization/uni-lib 4.0.50 → 4.1.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/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 +2 -0
- package/dist/entities/inbox/message-case.entity.js +18 -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/enums/inbox/event-type.enum.d.ts +2 -1
- package/dist/enums/inbox/event-type.enum.js +1 -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/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 +2 -1
|
@@ -0,0 +1,28 @@
|
|
|
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
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
9
|
+
exports.TenantOwnershipService = void 0;
|
|
10
|
+
const common_1 = require("@nestjs/common");
|
|
11
|
+
let TenantOwnershipService = class TenantOwnershipService {
|
|
12
|
+
assertOwned(record, clientId, resourceName = 'Resource') {
|
|
13
|
+
if (!record || record.clientId !== clientId) {
|
|
14
|
+
throw new common_1.NotFoundException(`${resourceName} not found`);
|
|
15
|
+
}
|
|
16
|
+
return record;
|
|
17
|
+
}
|
|
18
|
+
assertReadableGlobalOrOwned(record, clientId, resourceName = 'Resource') {
|
|
19
|
+
if (!record || (record.clientId !== null && record.clientId !== clientId)) {
|
|
20
|
+
throw new common_1.NotFoundException(`${resourceName} not found`);
|
|
21
|
+
}
|
|
22
|
+
return record;
|
|
23
|
+
}
|
|
24
|
+
};
|
|
25
|
+
exports.TenantOwnershipService = TenantOwnershipService;
|
|
26
|
+
exports.TenantOwnershipService = TenantOwnershipService = __decorate([
|
|
27
|
+
(0, common_1.Injectable)()
|
|
28
|
+
], TenantOwnershipService);
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { FindOptionsWhere, ObjectLiteral, SelectQueryBuilder } from 'typeorm';
|
|
2
|
+
export interface TenantOwnedRecord {
|
|
3
|
+
clientId: number;
|
|
4
|
+
}
|
|
5
|
+
export interface GlobalOrTenantRecord {
|
|
6
|
+
clientId: number | null;
|
|
7
|
+
}
|
|
8
|
+
export declare function tenantWhere<T extends TenantOwnedRecord>(clientId: number): FindOptionsWhere<T>;
|
|
9
|
+
export declare function globalOrTenantWhere<T extends GlobalOrTenantRecord>(clientId: number): FindOptionsWhere<T>[];
|
|
10
|
+
export declare function addTenantScope<T extends ObjectLiteral>(query: SelectQueryBuilder<T>, alias: string, clientId: number): SelectQueryBuilder<T>;
|
|
11
|
+
export declare function addGlobalOrTenantScope<T extends ObjectLiteral>(query: SelectQueryBuilder<T>, alias: string, clientId: number): SelectQueryBuilder<T>;
|
|
12
|
+
export declare function resolveGlobalTenantOverrides<T extends GlobalOrTenantRecord>(rows: readonly T[], naturalKey: (row: T) => string, clientId: number): T[];
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.tenantWhere = tenantWhere;
|
|
4
|
+
exports.globalOrTenantWhere = globalOrTenantWhere;
|
|
5
|
+
exports.addTenantScope = addTenantScope;
|
|
6
|
+
exports.addGlobalOrTenantScope = addGlobalOrTenantScope;
|
|
7
|
+
exports.resolveGlobalTenantOverrides = resolveGlobalTenantOverrides;
|
|
8
|
+
const typeorm_1 = require("typeorm");
|
|
9
|
+
function tenantWhere(clientId) {
|
|
10
|
+
return { clientId };
|
|
11
|
+
}
|
|
12
|
+
function globalOrTenantWhere(clientId) {
|
|
13
|
+
return [
|
|
14
|
+
{ clientId },
|
|
15
|
+
{ clientId: (0, typeorm_1.IsNull)() },
|
|
16
|
+
];
|
|
17
|
+
}
|
|
18
|
+
function addTenantScope(query, alias, clientId) {
|
|
19
|
+
return query.andWhere(`${alias}.client_id = :clientId`, { clientId });
|
|
20
|
+
}
|
|
21
|
+
function addGlobalOrTenantScope(query, alias, clientId) {
|
|
22
|
+
return query.andWhere(`(${alias}.client_id = :clientId OR ${alias}.client_id IS NULL)`, { clientId });
|
|
23
|
+
}
|
|
24
|
+
function resolveGlobalTenantOverrides(rows, naturalKey, clientId) {
|
|
25
|
+
const resolved = new Map();
|
|
26
|
+
for (const row of rows) {
|
|
27
|
+
if (row.clientId === null) {
|
|
28
|
+
resolved.set(naturalKey(row), row);
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
for (const row of rows) {
|
|
32
|
+
if (row.clientId === clientId) {
|
|
33
|
+
resolved.set(naturalKey(row), row);
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
return [...resolved.values()];
|
|
37
|
+
}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { TenantContextStorage } from './tenant-context.storage';
|
|
2
|
+
import { TenantRunnerMetadata } from './tenant.types';
|
|
3
|
+
export declare class TenantRunner {
|
|
4
|
+
private readonly tenantContextStorage;
|
|
5
|
+
constructor(tenantContextStorage: TenantContextStorage);
|
|
6
|
+
run<T>(clientId: number, metadata: TenantRunnerMetadata, callback: () => T): T;
|
|
7
|
+
}
|
|
@@ -0,0 +1,41 @@
|
|
|
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.TenantRunner = void 0;
|
|
13
|
+
const crypto_1 = require("crypto");
|
|
14
|
+
const common_1 = require("@nestjs/common");
|
|
15
|
+
const tenant_context_storage_1 = require("./tenant-context.storage");
|
|
16
|
+
let TenantRunner = class TenantRunner {
|
|
17
|
+
constructor(tenantContextStorage) {
|
|
18
|
+
this.tenantContextStorage = tenantContextStorage;
|
|
19
|
+
}
|
|
20
|
+
run(clientId, metadata, callback) {
|
|
21
|
+
var _a, _b;
|
|
22
|
+
if (!Number.isInteger(clientId) || clientId <= 0) {
|
|
23
|
+
throw new Error('TenantRunner requires a valid client ID');
|
|
24
|
+
}
|
|
25
|
+
return this.tenantContextStorage.run({
|
|
26
|
+
clientId,
|
|
27
|
+
originalClientId: null,
|
|
28
|
+
actorUserId: (_a = metadata.actorUserId) !== null && _a !== void 0 ? _a : null,
|
|
29
|
+
authenticationType: metadata.authenticationType,
|
|
30
|
+
impersonatedAt: null,
|
|
31
|
+
impersonationReason: null,
|
|
32
|
+
correlationId: metadata.correlationId || (0, crypto_1.randomUUID)(),
|
|
33
|
+
credentialId: (_b = metadata.credentialId) !== null && _b !== void 0 ? _b : null,
|
|
34
|
+
}, callback);
|
|
35
|
+
}
|
|
36
|
+
};
|
|
37
|
+
exports.TenantRunner = TenantRunner;
|
|
38
|
+
exports.TenantRunner = TenantRunner = __decorate([
|
|
39
|
+
(0, common_1.Injectable)(),
|
|
40
|
+
__metadata("design:paramtypes", [tenant_context_storage_1.TenantContextStorage])
|
|
41
|
+
], TenantRunner);
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { TenantSecurityStateStore } from './tenant-security-state.store';
|
|
2
|
+
export declare class TenantSecurityStateService {
|
|
3
|
+
private readonly store;
|
|
4
|
+
constructor(store: TenantSecurityStateStore);
|
|
5
|
+
isAccessTokenRevoked(jti: string): Promise<boolean>;
|
|
6
|
+
revokeAccessToken(jti: string, ttlSeconds: number): Promise<void>;
|
|
7
|
+
createPreAuth(jti: string, userId: number, ttlSeconds: number): Promise<void>;
|
|
8
|
+
consumePreAuth(jti: string, userId: number): Promise<boolean>;
|
|
9
|
+
private securityOperation;
|
|
10
|
+
private assertTtl;
|
|
11
|
+
}
|
|
@@ -0,0 +1,75 @@
|
|
|
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
|
+
var __param = (this && this.__param) || function (paramIndex, decorator) {
|
|
12
|
+
return function (target, key) { decorator(target, key, paramIndex); }
|
|
13
|
+
};
|
|
14
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
15
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
16
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
17
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
18
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
19
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
20
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
21
|
+
});
|
|
22
|
+
};
|
|
23
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
24
|
+
exports.TenantSecurityStateService = void 0;
|
|
25
|
+
const common_1 = require("@nestjs/common");
|
|
26
|
+
const tenant_authorization_keys_1 = require("./tenant-authorization.keys");
|
|
27
|
+
const tenant_security_state_store_1 = require("./tenant-security-state.store");
|
|
28
|
+
let TenantSecurityStateService = class TenantSecurityStateService {
|
|
29
|
+
constructor(store) {
|
|
30
|
+
this.store = store;
|
|
31
|
+
}
|
|
32
|
+
isAccessTokenRevoked(jti) {
|
|
33
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
34
|
+
return this.securityOperation(() => this.store.isRevoked((0, tenant_authorization_keys_1.revokedAccessTokenKey)(jti)));
|
|
35
|
+
});
|
|
36
|
+
}
|
|
37
|
+
revokeAccessToken(jti, ttlSeconds) {
|
|
38
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
39
|
+
this.assertTtl(ttlSeconds);
|
|
40
|
+
yield this.securityOperation(() => this.store.revoke((0, tenant_authorization_keys_1.revokedAccessTokenKey)(jti), ttlSeconds));
|
|
41
|
+
});
|
|
42
|
+
}
|
|
43
|
+
createPreAuth(jti, userId, ttlSeconds) {
|
|
44
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
45
|
+
this.assertTtl(ttlSeconds);
|
|
46
|
+
yield this.securityOperation(() => this.store.createPreAuth((0, tenant_authorization_keys_1.preAuthTokenKey)(jti), userId, ttlSeconds));
|
|
47
|
+
});
|
|
48
|
+
}
|
|
49
|
+
consumePreAuth(jti, userId) {
|
|
50
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
51
|
+
return this.securityOperation(() => this.store.consumePreAuth((0, tenant_authorization_keys_1.preAuthTokenKey)(jti), userId));
|
|
52
|
+
});
|
|
53
|
+
}
|
|
54
|
+
securityOperation(operation) {
|
|
55
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
56
|
+
try {
|
|
57
|
+
return yield operation();
|
|
58
|
+
}
|
|
59
|
+
catch (_a) {
|
|
60
|
+
throw new common_1.ServiceUnavailableException('Authentication security state is unavailable');
|
|
61
|
+
}
|
|
62
|
+
});
|
|
63
|
+
}
|
|
64
|
+
assertTtl(ttlSeconds) {
|
|
65
|
+
if (!Number.isInteger(ttlSeconds) || ttlSeconds <= 0) {
|
|
66
|
+
throw new common_1.ServiceUnavailableException('Authentication security state is unavailable');
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
};
|
|
70
|
+
exports.TenantSecurityStateService = TenantSecurityStateService;
|
|
71
|
+
exports.TenantSecurityStateService = TenantSecurityStateService = __decorate([
|
|
72
|
+
(0, common_1.Injectable)(),
|
|
73
|
+
__param(0, (0, common_1.Inject)(tenant_security_state_store_1.TENANT_SECURITY_STATE_STORE)),
|
|
74
|
+
__metadata("design:paramtypes", [Object])
|
|
75
|
+
], TenantSecurityStateService);
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
export declare const TENANT_SECURITY_STATE_STORE: unique symbol;
|
|
2
|
+
export interface TenantSecurityStateStore {
|
|
3
|
+
isRevoked(key: string): Promise<boolean>;
|
|
4
|
+
revoke(key: string, ttlSeconds: number): Promise<void>;
|
|
5
|
+
createPreAuth(key: string, userId: number, ttlSeconds: number): Promise<void>;
|
|
6
|
+
consumePreAuth(key: string, userId: number): Promise<boolean>;
|
|
7
|
+
}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
export declare const NEWTECH_CLIENT_ID = 1;
|
|
2
|
+
export declare const ALTERA_CLIENT_ID = 2;
|
|
3
|
+
export declare const TENANT_IMPERSONATOR_ROLE = "TENANT_IMPERSONATOR";
|
|
4
|
+
export declare const MASTER_TENANT_METADATA_KEY = "masterTenant";
|
|
5
|
+
export declare const PUBLIC_ROUTE_METADATA_KEY = "publicRoute";
|
|
6
|
+
export declare const TENANT_CONTEXT_REQUEST_KEY = "tenantContext";
|
|
7
|
+
export declare const TENANT_CREDENTIAL_HEADER = "x-client-credential";
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.TENANT_CREDENTIAL_HEADER = exports.TENANT_CONTEXT_REQUEST_KEY = exports.PUBLIC_ROUTE_METADATA_KEY = exports.MASTER_TENANT_METADATA_KEY = exports.TENANT_IMPERSONATOR_ROLE = exports.ALTERA_CLIENT_ID = exports.NEWTECH_CLIENT_ID = void 0;
|
|
4
|
+
exports.NEWTECH_CLIENT_ID = 1;
|
|
5
|
+
exports.ALTERA_CLIENT_ID = 2;
|
|
6
|
+
exports.TENANT_IMPERSONATOR_ROLE = 'TENANT_IMPERSONATOR';
|
|
7
|
+
exports.MASTER_TENANT_METADATA_KEY = 'masterTenant';
|
|
8
|
+
exports.PUBLIC_ROUTE_METADATA_KEY = 'publicRoute';
|
|
9
|
+
exports.TENANT_CONTEXT_REQUEST_KEY = 'tenantContext';
|
|
10
|
+
exports.TENANT_CREDENTIAL_HEADER = 'x-client-credential';
|
|
@@ -0,0 +1,70 @@
|
|
|
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
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
9
|
+
exports.TenantModule = void 0;
|
|
10
|
+
const common_1 = require("@nestjs/common");
|
|
11
|
+
const typeorm_1 = require("@nestjs/typeorm");
|
|
12
|
+
const client_credential_entity_1 = require("../../entities/client-credential.entity");
|
|
13
|
+
const client_entity_1 = require("../../entities/client.entity");
|
|
14
|
+
const user_roles_entity_1 = require("../../entities/user-roles.entity");
|
|
15
|
+
const usr_entity_1 = require("../../entities/usr.entity");
|
|
16
|
+
const redis_tenant_state_store_1 = require("./redis-tenant-state.store");
|
|
17
|
+
const tenant_authorization_store_1 = require("./tenant-authorization.store");
|
|
18
|
+
const tenant_authorization_service_1 = require("./tenant-authorization.service");
|
|
19
|
+
const tenant_security_state_store_1 = require("./tenant-security-state.store");
|
|
20
|
+
const tenant_security_state_service_1 = require("./tenant-security-state.service");
|
|
21
|
+
const tenant_context_storage_1 = require("./tenant-context.storage");
|
|
22
|
+
const tenant_context_service_1 = require("./tenant-context.service");
|
|
23
|
+
const tenant_context_interceptor_1 = require("./tenant-context.interceptor");
|
|
24
|
+
const tenant_credential_guard_1 = require("./tenant-credential.guard");
|
|
25
|
+
const master_tenant_guard_1 = require("./master-tenant.guard");
|
|
26
|
+
const tenant_ownership_service_1 = require("./tenant-ownership.service");
|
|
27
|
+
const tenant_runner_service_1 = require("./tenant-runner.service");
|
|
28
|
+
let TenantModule = class TenantModule {
|
|
29
|
+
};
|
|
30
|
+
exports.TenantModule = TenantModule;
|
|
31
|
+
exports.TenantModule = TenantModule = __decorate([
|
|
32
|
+
(0, common_1.Global)(),
|
|
33
|
+
(0, common_1.Module)({
|
|
34
|
+
imports: [
|
|
35
|
+
typeorm_1.TypeOrmModule.forFeature([client_credential_entity_1.ClientCredential, client_entity_1.Client, user_roles_entity_1.UserRoles, usr_entity_1.Users]),
|
|
36
|
+
],
|
|
37
|
+
providers: [
|
|
38
|
+
redis_tenant_state_store_1.RedisTenantStateStore,
|
|
39
|
+
{
|
|
40
|
+
provide: tenant_authorization_store_1.TENANT_AUTHORIZATION_STORE,
|
|
41
|
+
useExisting: redis_tenant_state_store_1.RedisTenantStateStore,
|
|
42
|
+
},
|
|
43
|
+
{
|
|
44
|
+
provide: tenant_security_state_store_1.TENANT_SECURITY_STATE_STORE,
|
|
45
|
+
useExisting: redis_tenant_state_store_1.RedisTenantStateStore,
|
|
46
|
+
},
|
|
47
|
+
tenant_authorization_service_1.TenantAuthorizationService,
|
|
48
|
+
tenant_security_state_service_1.TenantSecurityStateService,
|
|
49
|
+
tenant_context_storage_1.TenantContextStorage,
|
|
50
|
+
tenant_context_service_1.TenantContext,
|
|
51
|
+
tenant_runner_service_1.TenantRunner,
|
|
52
|
+
tenant_context_interceptor_1.TenantContextInterceptor,
|
|
53
|
+
tenant_credential_guard_1.TenantCredentialGuard,
|
|
54
|
+
master_tenant_guard_1.MasterTenantGuard,
|
|
55
|
+
tenant_ownership_service_1.TenantOwnershipService,
|
|
56
|
+
],
|
|
57
|
+
exports: [
|
|
58
|
+
tenant_authorization_store_1.TENANT_AUTHORIZATION_STORE,
|
|
59
|
+
tenant_security_state_store_1.TENANT_SECURITY_STATE_STORE,
|
|
60
|
+
tenant_authorization_service_1.TenantAuthorizationService,
|
|
61
|
+
tenant_security_state_service_1.TenantSecurityStateService,
|
|
62
|
+
tenant_context_service_1.TenantContext,
|
|
63
|
+
tenant_runner_service_1.TenantRunner,
|
|
64
|
+
tenant_context_interceptor_1.TenantContextInterceptor,
|
|
65
|
+
tenant_credential_guard_1.TenantCredentialGuard,
|
|
66
|
+
master_tenant_guard_1.MasterTenantGuard,
|
|
67
|
+
tenant_ownership_service_1.TenantOwnershipService,
|
|
68
|
+
],
|
|
69
|
+
})
|
|
70
|
+
], TenantModule);
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
export type TenantAuthenticationType = 'jwt' | 'client-credential' | 'internal-message' | 'scheduled-job';
|
|
2
|
+
export interface TenantContextState {
|
|
3
|
+
readonly clientId: number;
|
|
4
|
+
readonly originalClientId: number | null;
|
|
5
|
+
readonly actorUserId: number | null;
|
|
6
|
+
readonly authenticationType: TenantAuthenticationType;
|
|
7
|
+
readonly impersonatedAt: string | null;
|
|
8
|
+
readonly impersonationReason: string | null;
|
|
9
|
+
readonly correlationId: string;
|
|
10
|
+
readonly credentialId?: string | null;
|
|
11
|
+
readonly roles?: readonly string[];
|
|
12
|
+
}
|
|
13
|
+
export interface AuthenticatedTenantUser {
|
|
14
|
+
id: number;
|
|
15
|
+
homeClientId: number;
|
|
16
|
+
clientId: number;
|
|
17
|
+
clientAlias?: string;
|
|
18
|
+
clientName?: string;
|
|
19
|
+
jti: string;
|
|
20
|
+
tokenExpiresAt: number;
|
|
21
|
+
originalClientId: number | null;
|
|
22
|
+
impersonatedAt: string | null;
|
|
23
|
+
impersonationReason: string | null;
|
|
24
|
+
roles: string[];
|
|
25
|
+
privileges: string[];
|
|
26
|
+
isMasterTenantAdmin: boolean;
|
|
27
|
+
first_name?: string;
|
|
28
|
+
username?: string;
|
|
29
|
+
last_name?: string;
|
|
30
|
+
division?: string;
|
|
31
|
+
lob?: string;
|
|
32
|
+
fullName?: string;
|
|
33
|
+
ntgid?: string;
|
|
34
|
+
profile?: string;
|
|
35
|
+
password_expired?: number;
|
|
36
|
+
viewEvaluations?: boolean;
|
|
37
|
+
ern?: string;
|
|
38
|
+
[key: string]: unknown;
|
|
39
|
+
}
|
|
40
|
+
export interface TenantJwtPayload {
|
|
41
|
+
type: 'access';
|
|
42
|
+
user: AuthenticatedTenantUser;
|
|
43
|
+
sub: string;
|
|
44
|
+
iat: number;
|
|
45
|
+
exp: number;
|
|
46
|
+
jti: string;
|
|
47
|
+
}
|
|
48
|
+
export interface PreAuthJwtPayload {
|
|
49
|
+
type: 'pre-auth';
|
|
50
|
+
userId: number;
|
|
51
|
+
iat: number;
|
|
52
|
+
exp: number;
|
|
53
|
+
jti: string;
|
|
54
|
+
}
|
|
55
|
+
export interface TenantAwareRequest {
|
|
56
|
+
headers?: Record<string, string | string[] | undefined>;
|
|
57
|
+
user?: AuthenticatedTenantUser | true;
|
|
58
|
+
tenantContext?: Readonly<TenantContextState>;
|
|
59
|
+
}
|
|
60
|
+
export type PublicRouteTenantMode = 'tenantless' | 'credential';
|
|
61
|
+
export interface PublicRouteOptions {
|
|
62
|
+
tenant: PublicRouteTenantMode;
|
|
63
|
+
}
|
|
64
|
+
export interface TenantRunnerMetadata {
|
|
65
|
+
authenticationType: 'internal-message' | 'scheduled-job';
|
|
66
|
+
actorUserId?: number | null;
|
|
67
|
+
correlationId?: string;
|
|
68
|
+
credentialId?: string | null;
|
|
69
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@uniorganization/uni-lib",
|
|
3
|
-
"version": "4.
|
|
3
|
+
"version": "4.1.1",
|
|
4
4
|
"description": "UNI Library",
|
|
5
5
|
"author": "Jhomiguel",
|
|
6
6
|
"main": "dist/index.js",
|
|
@@ -18,6 +18,7 @@
|
|
|
18
18
|
"@nestjs/swagger": "^7.4.0",
|
|
19
19
|
"axios": "^1.13.2",
|
|
20
20
|
"csvtojson": "^2.0.10",
|
|
21
|
+
"ioredis": "5.4.1",
|
|
21
22
|
"passport": "^0.7.0",
|
|
22
23
|
"passport-jwt": "^4.0.1",
|
|
23
24
|
"swagger-ui-express": "^5.0.1",
|