@kominal/common-nestjs 0.0.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/controllers/health.controller.d.ts +6 -0
- package/controllers/health.controller.js +38 -0
- package/controllers/health.controller.js.map +1 -0
- package/entities/access-token.entity.d.ts +21 -0
- package/entities/access-token.entity.js +38 -0
- package/entities/access-token.entity.js.map +1 -0
- package/entities/membership.entity.d.ts +40 -0
- package/entities/membership.entity.js +66 -0
- package/entities/membership.entity.js.map +1 -0
- package/entities/tenant.entity.d.ts +24 -0
- package/entities/tenant.entity.js +38 -0
- package/entities/tenant.entity.js.map +1 -0
- package/entities/user.entity.d.ts +20 -0
- package/entities/user.entity.js +34 -0
- package/entities/user.entity.js.map +1 -0
- package/guards/admin.guard.d.ts +7 -0
- package/guards/admin.guard.js +29 -0
- package/guards/admin.guard.js.map +1 -0
- package/guards/system.guard.d.ts +4 -0
- package/guards/system.guard.js +21 -0
- package/guards/system.guard.js.map +1 -0
- package/guards/tenant.guard.d.ts +11 -0
- package/guards/tenant.guard.js +71 -0
- package/guards/tenant.guard.js.map +1 -0
- package/guards/user.guard.d.ts +13 -0
- package/guards/user.guard.js +66 -0
- package/guards/user.guard.js.map +1 -0
- package/helpers/context.decorator.d.ts +7 -0
- package/helpers/context.decorator.js +11 -0
- package/helpers/context.decorator.js.map +1 -0
- package/helpers/custom-operation-name.decorator.d.ts +2 -0
- package/helpers/custom-operation-name.decorator.js +14 -0
- package/helpers/custom-operation-name.decorator.js.map +1 -0
- package/helpers/entity-service.helper.d.ts +56 -0
- package/helpers/entity-service.helper.js +86 -0
- package/helpers/entity-service.helper.js.map +1 -0
- package/helpers/exception-filter.d.ts +4 -0
- package/helpers/exception-filter.js +30 -0
- package/helpers/exception-filter.js.map +1 -0
- package/helpers/logger.d.ts +10 -0
- package/helpers/logger.js +39 -0
- package/helpers/logger.js.map +1 -0
- package/kominal-common.module.d.ts +2 -0
- package/kominal-common.module.js +29 -0
- package/kominal-common.module.js.map +1 -0
- package/middlewares/request-logging.middleware.d.ts +6 -0
- package/middlewares/request-logging.middleware.js +32 -0
- package/middlewares/request-logging.middleware.js.map +1 -0
- package/models/entity.model.d.ts +14 -0
- package/models/entity.model.js +50 -0
- package/models/entity.model.js.map +1 -0
- package/models/stored-file.model.d.ts +8 -0
- package/models/stored-file.model.js +10 -0
- package/models/stored-file.model.js.map +1 -0
- package/package.json +30 -0
- package/services/auth.service.d.ts +4 -0
- package/services/auth.service.js +34 -0
- package/services/auth.service.js.map +1 -0
- package/services/file.service.d.ts +7 -0
- package/services/file.service.js +57 -0
- package/services/file.service.js.map +1 -0
- package/services/health.service.d.ts +3 -0
- package/services/health.service.js +28 -0
- package/services/health.service.js.map +1 -0
- package/tsconfig.tsbuildinfo +1 -0
|
@@ -0,0 +1,38 @@
|
|
|
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.HealthController = void 0;
|
|
13
|
+
const common_1 = require("@nestjs/common");
|
|
14
|
+
const swagger_1 = require("@nestjs/swagger");
|
|
15
|
+
const custom_operation_name_decorator_1 = require("../helpers/custom-operation-name.decorator");
|
|
16
|
+
const health_service_1 = require("../services/health.service");
|
|
17
|
+
let HealthController = class HealthController {
|
|
18
|
+
constructor(healthService) {
|
|
19
|
+
this.healthService = healthService;
|
|
20
|
+
}
|
|
21
|
+
readHealth() {
|
|
22
|
+
return this.healthService.readHealth();
|
|
23
|
+
}
|
|
24
|
+
};
|
|
25
|
+
exports.HealthController = HealthController;
|
|
26
|
+
__decorate([
|
|
27
|
+
(0, common_1.Get)(),
|
|
28
|
+
(0, custom_operation_name_decorator_1.CustomOperationName)(),
|
|
29
|
+
__metadata("design:type", Function),
|
|
30
|
+
__metadata("design:paramtypes", []),
|
|
31
|
+
__metadata("design:returntype", Promise)
|
|
32
|
+
], HealthController.prototype, "readHealth", null);
|
|
33
|
+
exports.HealthController = HealthController = __decorate([
|
|
34
|
+
(0, swagger_1.ApiTags)('health'),
|
|
35
|
+
(0, common_1.Controller)('health'),
|
|
36
|
+
__metadata("design:paramtypes", [health_service_1.HealthService])
|
|
37
|
+
], HealthController);
|
|
38
|
+
//# sourceMappingURL=health.controller.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"health.controller.js","sourceRoot":"","sources":["../../src/controllers/health.controller.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,2CAAiD;AACjD,6CAA0C;AAC1C,gGAAiF;AACjF,+DAA2D;AAIpD,IAAM,gBAAgB,GAAtB,MAAM,gBAAgB;IAC5B,YAA2B,aAA4B;QAA5B,kBAAa,GAAb,aAAa,CAAe;IAAG,CAAC;IAIpD,UAAU;QAChB,OAAO,IAAI,CAAC,aAAa,CAAC,UAAU,EAAE,CAAC;IACxC,CAAC;CACD,CAAA;AARY,4CAAgB;AAKrB;IAFN,IAAA,YAAG,GAAE;IACL,IAAA,qDAAmB,GAAE;;;;kDAGrB;2BAPW,gBAAgB;IAF5B,IAAA,iBAAO,EAAC,QAAQ,CAAC;IACjB,IAAA,mBAAU,EAAC,QAAQ,CAAC;qCAEsB,8BAAa;GAD3C,gBAAgB,CAQ5B"}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { Model } from 'mongoose';
|
|
2
|
+
import { TenantEntity } from '../models/entity.model';
|
|
3
|
+
export declare class AccessToken extends TenantEntity {
|
|
4
|
+
userId: string;
|
|
5
|
+
name: string;
|
|
6
|
+
token: string;
|
|
7
|
+
}
|
|
8
|
+
export type AccessTokenModel = Model<AccessToken>;
|
|
9
|
+
export declare const AccessTokenSchema: import("mongoose").Schema<AccessToken, Model<AccessToken, any, any, any, import("mongoose").Document<unknown, any, AccessToken> & AccessToken & Required<{
|
|
10
|
+
_id: string;
|
|
11
|
+
}> & {
|
|
12
|
+
__v: number;
|
|
13
|
+
}, any>, {}, {}, {}, {}, import("mongoose").DefaultSchemaOptions, AccessToken, import("mongoose").Document<unknown, {}, import("mongoose").FlatRecord<AccessToken>> & import("mongoose").FlatRecord<AccessToken> & Required<{
|
|
14
|
+
_id: string;
|
|
15
|
+
}> & {
|
|
16
|
+
__v: number;
|
|
17
|
+
}>;
|
|
18
|
+
declare const AccessTokenRequest_base: import("@nestjs/common").Type<Omit<AccessToken, keyof TenantEntity>>;
|
|
19
|
+
export declare class AccessTokenRequest extends AccessTokenRequest_base {
|
|
20
|
+
}
|
|
21
|
+
export {};
|
|
@@ -0,0 +1,38 @@
|
|
|
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.AccessTokenRequest = exports.AccessTokenSchema = exports.AccessToken = void 0;
|
|
13
|
+
const mongoose_1 = require("@nestjs/mongoose");
|
|
14
|
+
const swagger_1 = require("@nestjs/swagger");
|
|
15
|
+
const entity_model_1 = require("../models/entity.model");
|
|
16
|
+
let AccessToken = class AccessToken extends entity_model_1.TenantEntity {
|
|
17
|
+
};
|
|
18
|
+
exports.AccessToken = AccessToken;
|
|
19
|
+
__decorate([
|
|
20
|
+
(0, mongoose_1.Prop)(),
|
|
21
|
+
__metadata("design:type", String)
|
|
22
|
+
], AccessToken.prototype, "userId", void 0);
|
|
23
|
+
__decorate([
|
|
24
|
+
(0, mongoose_1.Prop)(),
|
|
25
|
+
__metadata("design:type", String)
|
|
26
|
+
], AccessToken.prototype, "name", void 0);
|
|
27
|
+
__decorate([
|
|
28
|
+
(0, mongoose_1.Prop)(),
|
|
29
|
+
__metadata("design:type", String)
|
|
30
|
+
], AccessToken.prototype, "token", void 0);
|
|
31
|
+
exports.AccessToken = AccessToken = __decorate([
|
|
32
|
+
(0, mongoose_1.Schema)()
|
|
33
|
+
], AccessToken);
|
|
34
|
+
exports.AccessTokenSchema = mongoose_1.SchemaFactory.createForClass(AccessToken).index({ tenantId: 1 }).index({ tenantId: 1, uuid: 1 }, { unique: true });
|
|
35
|
+
class AccessTokenRequest extends (0, swagger_1.OmitType)(AccessToken, entity_model_1.TECHNICAL_KEYS) {
|
|
36
|
+
}
|
|
37
|
+
exports.AccessTokenRequest = AccessTokenRequest;
|
|
38
|
+
//# sourceMappingURL=access-token.entity.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"access-token.entity.js","sourceRoot":"","sources":["../../src/entities/access-token.entity.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,+CAA+D;AAC/D,6CAA2C;AAE3C,yDAAsE;AAG/D,IAAM,WAAW,GAAjB,MAAM,WAAY,SAAQ,2BAAY;CAI5C,CAAA;AAJY,kCAAW;AACP;IAAd,IAAA,eAAI,GAAE;;2CAAuB;AACf;IAAd,IAAA,eAAI,GAAE;;yCAAqB;AACb;IAAd,IAAA,eAAI,GAAE;;0CAAsB;sBAHlB,WAAW;IADvB,IAAA,iBAAM,GAAE;GACI,WAAW,CAIvB;AAIY,QAAA,iBAAiB,GAAG,wBAAa,CAAC,cAAc,CAAC,WAAW,CAAC,CAAC,KAAK,CAAC,EAAE,QAAQ,EAAE,CAAC,EAAE,CAAC,CAAC,KAAK,CAAC,EAAE,QAAQ,EAAE,CAAC,EAAE,IAAI,EAAE,CAAC,EAAE,EAAE,EAAE,MAAM,EAAE,IAAI,EAAE,CAAC,CAAC;AAEpJ,MAAa,kBAAmB,SAAQ,IAAA,kBAAQ,EAAC,WAAW,EAAE,6BAAc,CAAC;CAAG;AAAhF,gDAAgF"}
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import { Model } from 'mongoose';
|
|
2
|
+
import { TenantEntity } from '../models/entity.model';
|
|
3
|
+
import { User } from './user.entity';
|
|
4
|
+
export declare enum MembershipStatus {
|
|
5
|
+
INVITED = "INVITED",
|
|
6
|
+
ACTIVE = "ACTIVE",
|
|
7
|
+
DISABLED = "DISABLED"
|
|
8
|
+
}
|
|
9
|
+
export declare const MembershipStatusDecorator: PropertyDecorator;
|
|
10
|
+
export declare class Membership extends TenantEntity {
|
|
11
|
+
userId: string;
|
|
12
|
+
email: string;
|
|
13
|
+
permissions: string[];
|
|
14
|
+
roles: string[];
|
|
15
|
+
status: MembershipStatus;
|
|
16
|
+
}
|
|
17
|
+
export type MembershipModel = Model<Membership>;
|
|
18
|
+
export declare const MembershipSchema: import("mongoose").Schema<Membership, Model<Membership, any, any, any, import("mongoose").Document<unknown, any, Membership> & Membership & Required<{
|
|
19
|
+
_id: string;
|
|
20
|
+
}> & {
|
|
21
|
+
__v: number;
|
|
22
|
+
}, any>, {}, {}, {}, {}, import("mongoose").DefaultSchemaOptions, Membership, import("mongoose").Document<unknown, {}, import("mongoose").FlatRecord<Membership>> & import("mongoose").FlatRecord<Membership> & Required<{
|
|
23
|
+
_id: string;
|
|
24
|
+
}> & {
|
|
25
|
+
__v: number;
|
|
26
|
+
}>;
|
|
27
|
+
export declare class MembershipCreateRequest {
|
|
28
|
+
email: string;
|
|
29
|
+
}
|
|
30
|
+
declare const MembershipPopulated_base: import("@nestjs/common").Type<Partial<Membership>>;
|
|
31
|
+
export declare class MembershipPopulated extends MembershipPopulated_base {
|
|
32
|
+
user: User;
|
|
33
|
+
}
|
|
34
|
+
export declare class MembershipUpdateRequest {
|
|
35
|
+
permissions: string[];
|
|
36
|
+
}
|
|
37
|
+
export declare class MembershipPathParams {
|
|
38
|
+
userId: string;
|
|
39
|
+
}
|
|
40
|
+
export {};
|
|
@@ -0,0 +1,66 @@
|
|
|
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.MembershipPathParams = exports.MembershipUpdateRequest = exports.MembershipPopulated = exports.MembershipCreateRequest = exports.MembershipSchema = exports.Membership = exports.MembershipStatusDecorator = exports.MembershipStatus = void 0;
|
|
13
|
+
const mongoose_1 = require("@nestjs/mongoose");
|
|
14
|
+
const swagger_1 = require("@nestjs/swagger");
|
|
15
|
+
const entity_model_1 = require("../models/entity.model");
|
|
16
|
+
var MembershipStatus;
|
|
17
|
+
(function (MembershipStatus) {
|
|
18
|
+
MembershipStatus["INVITED"] = "INVITED";
|
|
19
|
+
MembershipStatus["ACTIVE"] = "ACTIVE";
|
|
20
|
+
MembershipStatus["DISABLED"] = "DISABLED";
|
|
21
|
+
})(MembershipStatus || (exports.MembershipStatus = MembershipStatus = {}));
|
|
22
|
+
exports.MembershipStatusDecorator = (0, swagger_1.ApiProperty)({ enum: MembershipStatus, enumName: 'MembershipStatus' });
|
|
23
|
+
let Membership = class Membership extends entity_model_1.TenantEntity {
|
|
24
|
+
};
|
|
25
|
+
exports.Membership = Membership;
|
|
26
|
+
__decorate([
|
|
27
|
+
(0, mongoose_1.Prop)(),
|
|
28
|
+
__metadata("design:type", String)
|
|
29
|
+
], Membership.prototype, "userId", void 0);
|
|
30
|
+
__decorate([
|
|
31
|
+
(0, mongoose_1.Prop)(),
|
|
32
|
+
__metadata("design:type", String)
|
|
33
|
+
], Membership.prototype, "email", void 0);
|
|
34
|
+
__decorate([
|
|
35
|
+
(0, mongoose_1.Prop)(),
|
|
36
|
+
__metadata("design:type", Array)
|
|
37
|
+
], Membership.prototype, "permissions", void 0);
|
|
38
|
+
__decorate([
|
|
39
|
+
(0, mongoose_1.Prop)(),
|
|
40
|
+
__metadata("design:type", Array)
|
|
41
|
+
], Membership.prototype, "roles", void 0);
|
|
42
|
+
__decorate([
|
|
43
|
+
(0, mongoose_1.Prop)(),
|
|
44
|
+
exports.MembershipStatusDecorator,
|
|
45
|
+
__metadata("design:type", String)
|
|
46
|
+
], Membership.prototype, "status", void 0);
|
|
47
|
+
exports.Membership = Membership = __decorate([
|
|
48
|
+
(0, mongoose_1.Schema)()
|
|
49
|
+
], Membership);
|
|
50
|
+
exports.MembershipSchema = mongoose_1.SchemaFactory.createForClass(Membership)
|
|
51
|
+
.index({ tenantId: 1 })
|
|
52
|
+
.index({ tenantId: 1, uuid: 1 }, { unique: true })
|
|
53
|
+
.index({ tenantId: 1, userId: 1 }, { unique: true });
|
|
54
|
+
class MembershipCreateRequest {
|
|
55
|
+
}
|
|
56
|
+
exports.MembershipCreateRequest = MembershipCreateRequest;
|
|
57
|
+
class MembershipPopulated extends (0, swagger_1.PartialType)(Membership) {
|
|
58
|
+
}
|
|
59
|
+
exports.MembershipPopulated = MembershipPopulated;
|
|
60
|
+
class MembershipUpdateRequest {
|
|
61
|
+
}
|
|
62
|
+
exports.MembershipUpdateRequest = MembershipUpdateRequest;
|
|
63
|
+
class MembershipPathParams {
|
|
64
|
+
}
|
|
65
|
+
exports.MembershipPathParams = MembershipPathParams;
|
|
66
|
+
//# sourceMappingURL=membership.entity.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"membership.entity.js","sourceRoot":"","sources":["../../src/entities/membership.entity.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,+CAA+D;AAC/D,6CAA2D;AAE3D,yDAAsD;AAGtD,IAAY,gBAIX;AAJD,WAAY,gBAAgB;IAC1B,uCAAmB,CAAA;IACnB,qCAAiB,CAAA;IACjB,yCAAqB,CAAA;AACvB,CAAC,EAJW,gBAAgB,gCAAhB,gBAAgB,QAI3B;AACY,QAAA,yBAAyB,GAAG,IAAA,qBAAW,EAAC,EAAE,IAAI,EAAE,gBAAgB,EAAE,QAAQ,EAAE,kBAAkB,EAAE,CAAC,CAAC;AAGxG,IAAM,UAAU,GAAhB,MAAM,UAAW,SAAQ,2BAAY;CAM3C,CAAA;AANY,gCAAU;AACN;IAAd,IAAA,eAAI,GAAE;;0CAAuB;AACf;IAAd,IAAA,eAAI,GAAE;;yCAAsB;AACd;IAAd,IAAA,eAAI,GAAE;;+CAA8B;AACtB;IAAd,IAAA,eAAI,GAAE;;yCAAwB;AACW;IAAzC,IAAA,eAAI,GAAE;IAAE,iCAAyB;;0CAAiC;qBALxD,UAAU;IADtB,IAAA,iBAAM,GAAE;GACI,UAAU,CAMtB;AAIY,QAAA,gBAAgB,GAAG,wBAAa,CAAC,cAAc,CAAC,UAAU,CAAC;KACrE,KAAK,CAAC,EAAE,QAAQ,EAAE,CAAC,EAAE,CAAC;KACtB,KAAK,CAAC,EAAE,QAAQ,EAAE,CAAC,EAAE,IAAI,EAAE,CAAC,EAAE,EAAE,EAAE,MAAM,EAAE,IAAI,EAAE,CAAC;KACjD,KAAK,CAAC,EAAE,QAAQ,EAAE,CAAC,EAAE,MAAM,EAAE,CAAC,EAAE,EAAE,EAAE,MAAM,EAAE,IAAI,EAAE,CAAC,CAAC;AAEvD,MAAa,uBAAuB;CAEnC;AAFD,0DAEC;AAED,MAAa,mBAAoB,SAAQ,IAAA,qBAAW,EAAC,UAAU,CAAC;CAE/D;AAFD,kDAEC;AAED,MAAa,uBAAuB;CAEnC;AAFD,0DAEC;AAED,MAAa,oBAAoB;CAEhC;AAFD,oDAEC"}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { Model } from 'mongoose';
|
|
2
|
+
import { BaseEntity } from '../models/entity.model';
|
|
3
|
+
import { StoredFile } from '../models/stored-file.model';
|
|
4
|
+
export declare class Tenant extends BaseEntity {
|
|
5
|
+
name: string;
|
|
6
|
+
logo?: StoredFile;
|
|
7
|
+
}
|
|
8
|
+
export type TenantModel = Model<Tenant>;
|
|
9
|
+
export declare const TenantSchema: import("mongoose").Schema<Tenant, Model<Tenant, any, any, any, import("mongoose").Document<unknown, any, Tenant> & Tenant & Required<{
|
|
10
|
+
_id: string;
|
|
11
|
+
}> & {
|
|
12
|
+
__v: number;
|
|
13
|
+
}, any>, {}, {}, {}, {}, import("mongoose").DefaultSchemaOptions, Tenant, import("mongoose").Document<unknown, {}, import("mongoose").FlatRecord<Tenant>> & import("mongoose").FlatRecord<Tenant> & Required<{
|
|
14
|
+
_id: string;
|
|
15
|
+
}> & {
|
|
16
|
+
__v: number;
|
|
17
|
+
}>;
|
|
18
|
+
declare const TenantCreateRequest_base: import("@nestjs/common").Type<Omit<Tenant, keyof BaseEntity | "logo">>;
|
|
19
|
+
export declare class TenantCreateRequest extends TenantCreateRequest_base {
|
|
20
|
+
}
|
|
21
|
+
declare const TenantUpdateRequest_base: import("@nestjs/common").Type<Omit<Tenant, keyof BaseEntity>>;
|
|
22
|
+
export declare class TenantUpdateRequest extends TenantUpdateRequest_base {
|
|
23
|
+
}
|
|
24
|
+
export {};
|
|
@@ -0,0 +1,38 @@
|
|
|
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.TenantUpdateRequest = exports.TenantCreateRequest = exports.TenantSchema = exports.Tenant = void 0;
|
|
13
|
+
const mongoose_1 = require("@nestjs/mongoose");
|
|
14
|
+
const swagger_1 = require("@nestjs/swagger");
|
|
15
|
+
const entity_model_1 = require("../models/entity.model");
|
|
16
|
+
const stored_file_model_1 = require("../models/stored-file.model");
|
|
17
|
+
let Tenant = class Tenant extends entity_model_1.BaseEntity {
|
|
18
|
+
};
|
|
19
|
+
exports.Tenant = Tenant;
|
|
20
|
+
__decorate([
|
|
21
|
+
(0, mongoose_1.Prop)(),
|
|
22
|
+
__metadata("design:type", String)
|
|
23
|
+
], Tenant.prototype, "name", void 0);
|
|
24
|
+
__decorate([
|
|
25
|
+
(0, mongoose_1.Prop)(),
|
|
26
|
+
__metadata("design:type", stored_file_model_1.StoredFile)
|
|
27
|
+
], Tenant.prototype, "logo", void 0);
|
|
28
|
+
exports.Tenant = Tenant = __decorate([
|
|
29
|
+
(0, mongoose_1.Schema)()
|
|
30
|
+
], Tenant);
|
|
31
|
+
exports.TenantSchema = mongoose_1.SchemaFactory.createForClass(Tenant).index({ uuid: 1 }, { unique: true });
|
|
32
|
+
class TenantCreateRequest extends (0, swagger_1.OmitType)(Tenant, [...entity_model_1.TECHNICAL_KEYS_BASE_ENTITY, 'logo']) {
|
|
33
|
+
}
|
|
34
|
+
exports.TenantCreateRequest = TenantCreateRequest;
|
|
35
|
+
class TenantUpdateRequest extends (0, swagger_1.OmitType)(Tenant, entity_model_1.TECHNICAL_KEYS_BASE_ENTITY) {
|
|
36
|
+
}
|
|
37
|
+
exports.TenantUpdateRequest = TenantUpdateRequest;
|
|
38
|
+
//# sourceMappingURL=tenant.entity.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"tenant.entity.js","sourceRoot":"","sources":["../../src/entities/tenant.entity.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,+CAA+D;AAC/D,6CAA2C;AAE3C,yDAAgF;AAChF,mEAAyD;AAGlD,IAAM,MAAM,GAAZ,MAAM,MAAO,SAAQ,yBAAU;CAGrC,CAAA;AAHY,wBAAM;AACF;IAAd,IAAA,eAAI,GAAE;;oCAAqB;AACb;IAAd,IAAA,eAAI,GAAE;8BAAe,8BAAU;oCAAC;iBAFtB,MAAM;IADlB,IAAA,iBAAM,GAAE;GACI,MAAM,CAGlB;AAIY,QAAA,YAAY,GAAG,wBAAa,CAAC,cAAc,CAAC,MAAM,CAAC,CAAC,KAAK,CAAC,EAAE,IAAI,EAAE,CAAC,EAAE,EAAE,EAAE,MAAM,EAAE,IAAI,EAAE,CAAC,CAAC;AAEtG,MAAa,mBAAoB,SAAQ,IAAA,kBAAQ,EAAC,MAAM,EAAE,CAAC,GAAG,yCAA0B,EAAE,MAAM,CAAC,CAAC;CAAG;AAArG,kDAAqG;AAErG,MAAa,mBAAoB,SAAQ,IAAA,kBAAQ,EAAC,MAAM,EAAE,yCAA0B,CAAC;CAAG;AAAxF,kDAAwF"}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { Model } from 'mongoose';
|
|
2
|
+
import { BaseEntity } from '../models/entity.model';
|
|
3
|
+
export declare class User extends BaseEntity {
|
|
4
|
+
userId: string;
|
|
5
|
+
lastActivity: Date;
|
|
6
|
+
}
|
|
7
|
+
export type UserModel = Model<User>;
|
|
8
|
+
export declare const UserSchema: import("mongoose").Schema<User, Model<User, any, any, any, import("mongoose").Document<unknown, any, User> & User & Required<{
|
|
9
|
+
_id: string;
|
|
10
|
+
}> & {
|
|
11
|
+
__v: number;
|
|
12
|
+
}, any>, {}, {}, {}, {}, import("mongoose").DefaultSchemaOptions, User, import("mongoose").Document<unknown, {}, import("mongoose").FlatRecord<User>> & import("mongoose").FlatRecord<User> & Required<{
|
|
13
|
+
_id: string;
|
|
14
|
+
}> & {
|
|
15
|
+
__v: number;
|
|
16
|
+
}>;
|
|
17
|
+
declare const UserUpdateRequest_base: import("@nestjs/common").Type<Omit<User, keyof BaseEntity>>;
|
|
18
|
+
export declare class UserUpdateRequest extends UserUpdateRequest_base {
|
|
19
|
+
}
|
|
20
|
+
export {};
|
|
@@ -0,0 +1,34 @@
|
|
|
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.UserUpdateRequest = exports.UserSchema = exports.User = void 0;
|
|
13
|
+
const mongoose_1 = require("@nestjs/mongoose");
|
|
14
|
+
const swagger_1 = require("@nestjs/swagger");
|
|
15
|
+
const entity_model_1 = require("../models/entity.model");
|
|
16
|
+
let User = class User extends entity_model_1.BaseEntity {
|
|
17
|
+
};
|
|
18
|
+
exports.User = User;
|
|
19
|
+
__decorate([
|
|
20
|
+
(0, mongoose_1.Prop)(),
|
|
21
|
+
__metadata("design:type", String)
|
|
22
|
+
], User.prototype, "userId", void 0);
|
|
23
|
+
__decorate([
|
|
24
|
+
(0, mongoose_1.Prop)(),
|
|
25
|
+
__metadata("design:type", Date)
|
|
26
|
+
], User.prototype, "lastActivity", void 0);
|
|
27
|
+
exports.User = User = __decorate([
|
|
28
|
+
(0, mongoose_1.Schema)()
|
|
29
|
+
], User);
|
|
30
|
+
exports.UserSchema = mongoose_1.SchemaFactory.createForClass(User).index({ uuid: 1 }, { unique: true });
|
|
31
|
+
class UserUpdateRequest extends (0, swagger_1.OmitType)(User, entity_model_1.TECHNICAL_KEYS_BASE_ENTITY) {
|
|
32
|
+
}
|
|
33
|
+
exports.UserUpdateRequest = UserUpdateRequest;
|
|
34
|
+
//# sourceMappingURL=user.entity.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"user.entity.js","sourceRoot":"","sources":["../../src/entities/user.entity.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,+CAA+D;AAC/D,6CAA2C;AAE3C,yDAAgF;AAGzE,IAAM,IAAI,GAAV,MAAM,IAAK,SAAQ,yBAAU;CAGnC,CAAA;AAHY,oBAAI;AACA;IAAd,IAAA,eAAI,GAAE;;oCAAuB;AACf;IAAd,IAAA,eAAI,GAAE;8BAAsB,IAAI;0CAAC;eAFvB,IAAI;IADhB,IAAA,iBAAM,GAAE;GACI,IAAI,CAGhB;AAIY,QAAA,UAAU,GAAG,wBAAa,CAAC,cAAc,CAAC,IAAI,CAAC,CAAC,KAAK,CAAC,EAAE,IAAI,EAAE,CAAC,EAAE,EAAE,EAAE,MAAM,EAAE,IAAI,EAAE,CAAC,CAAC;AAElG,MAAa,iBAAkB,SAAQ,IAAA,kBAAQ,EAAC,IAAI,EAAE,yCAA0B,CAAC;CAAG;AAApF,8CAAoF"}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { CanActivate, ExecutionContext } from '@nestjs/common';
|
|
2
|
+
import { UserGuard } from './user.guard';
|
|
3
|
+
export declare class AdminGuard implements CanActivate {
|
|
4
|
+
private userGuard;
|
|
5
|
+
constructor(userGuard: UserGuard);
|
|
6
|
+
canActivate(context: ExecutionContext): Promise<boolean>;
|
|
7
|
+
}
|
|
@@ -0,0 +1,29 @@
|
|
|
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.AdminGuard = void 0;
|
|
13
|
+
const common_1 = require("@nestjs/common");
|
|
14
|
+
const user_guard_1 = require("./user.guard");
|
|
15
|
+
let AdminGuard = class AdminGuard {
|
|
16
|
+
constructor(userGuard) {
|
|
17
|
+
this.userGuard = userGuard;
|
|
18
|
+
}
|
|
19
|
+
async canActivate(context) {
|
|
20
|
+
const userContext = await this.userGuard.populateUserContext(context);
|
|
21
|
+
return !!userContext && userContext.admin;
|
|
22
|
+
}
|
|
23
|
+
};
|
|
24
|
+
exports.AdminGuard = AdminGuard;
|
|
25
|
+
exports.AdminGuard = AdminGuard = __decorate([
|
|
26
|
+
(0, common_1.Injectable)(),
|
|
27
|
+
__metadata("design:paramtypes", [user_guard_1.UserGuard])
|
|
28
|
+
], AdminGuard);
|
|
29
|
+
//# sourceMappingURL=admin.guard.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"admin.guard.js","sourceRoot":"","sources":["../../src/guards/admin.guard.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,2CAA2E;AAC3E,6CAAyC;AAGlC,IAAM,UAAU,GAAhB,MAAM,UAAU;IACrB,YAA2B,SAAoB;QAApB,cAAS,GAAT,SAAS,CAAW;IAAG,CAAC;IAE5C,KAAK,CAAC,WAAW,CAAC,OAAyB;QAChD,MAAM,WAAW,GAAG,MAAM,IAAI,CAAC,SAAS,CAAC,mBAAmB,CAAC,OAAO,CAAC,CAAC;QACtE,OAAO,CAAC,CAAC,WAAW,IAAI,WAAW,CAAC,KAAK,CAAC;IAC5C,CAAC;CACF,CAAA;AAPY,gCAAU;qBAAV,UAAU;IADtB,IAAA,mBAAU,GAAE;qCAE2B,sBAAS;GADpC,UAAU,CAOtB"}
|
|
@@ -0,0 +1,21 @@
|
|
|
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.SystemGuard = void 0;
|
|
10
|
+
const common_1 = require("@nestjs/common");
|
|
11
|
+
let SystemGuard = class SystemGuard {
|
|
12
|
+
async canActivate(context) {
|
|
13
|
+
const bearerHeader = context.switchToHttp().getRequest().headers.authorization;
|
|
14
|
+
return bearerHeader && bearerHeader.split(' ')[1] === process.env.SYSTEM_API_SECRET;
|
|
15
|
+
}
|
|
16
|
+
};
|
|
17
|
+
exports.SystemGuard = SystemGuard;
|
|
18
|
+
exports.SystemGuard = SystemGuard = __decorate([
|
|
19
|
+
(0, common_1.Injectable)()
|
|
20
|
+
], SystemGuard);
|
|
21
|
+
//# sourceMappingURL=system.guard.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"system.guard.js","sourceRoot":"","sources":["../../src/guards/system.guard.ts"],"names":[],"mappings":";;;;;;;;;AAAA,2CAA2E;AAGpE,IAAM,WAAW,GAAjB,MAAM,WAAW;IACf,KAAK,CAAC,WAAW,CAAC,OAAyB;QAChD,MAAM,YAAY,GAAG,OAAO,CAAC,YAAY,EAAE,CAAC,UAAU,EAAE,CAAC,OAAO,CAAC,aAAa,CAAC;QAC/E,OAAO,YAAY,IAAI,YAAY,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,KAAK,OAAO,CAAC,GAAG,CAAC,iBAAiB,CAAC;IACtF,CAAC;CACF,CAAA;AALY,kCAAW;sBAAX,WAAW;IADvB,IAAA,mBAAU,GAAE;GACA,WAAW,CAKvB"}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { CanActivate, ExecutionContext } from '@nestjs/common';
|
|
2
|
+
import { AccessTokenModel } from '../entities/access-token.entity';
|
|
3
|
+
import { MembershipModel } from '../entities/membership.entity';
|
|
4
|
+
import { UserGuard } from './user.guard';
|
|
5
|
+
export declare class TenantGuard implements CanActivate {
|
|
6
|
+
private membershipModel;
|
|
7
|
+
private accessTokenModel;
|
|
8
|
+
private userGuard;
|
|
9
|
+
constructor(membershipModel: MembershipModel, accessTokenModel: AccessTokenModel, userGuard: UserGuard);
|
|
10
|
+
canActivate(context: ExecutionContext): Promise<boolean>;
|
|
11
|
+
}
|
|
@@ -0,0 +1,71 @@
|
|
|
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
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
|
+
exports.TenantGuard = void 0;
|
|
16
|
+
const common_1 = require("@nestjs/common");
|
|
17
|
+
const mongoose_1 = require("@nestjs/mongoose");
|
|
18
|
+
const access_token_entity_1 = require("../entities/access-token.entity");
|
|
19
|
+
const membership_entity_1 = require("../entities/membership.entity");
|
|
20
|
+
const user_guard_1 = require("./user.guard");
|
|
21
|
+
let TenantGuard = class TenantGuard {
|
|
22
|
+
constructor(membershipModel, accessTokenModel, userGuard) {
|
|
23
|
+
this.membershipModel = membershipModel;
|
|
24
|
+
this.accessTokenModel = accessTokenModel;
|
|
25
|
+
this.userGuard = userGuard;
|
|
26
|
+
}
|
|
27
|
+
async canActivate(context) {
|
|
28
|
+
const req = context.switchToHttp().getRequest();
|
|
29
|
+
const { tenantId } = req.params;
|
|
30
|
+
if (!tenantId) {
|
|
31
|
+
return false;
|
|
32
|
+
}
|
|
33
|
+
const bearerHeader = req.headers.authorization;
|
|
34
|
+
if (!bearerHeader) {
|
|
35
|
+
return false;
|
|
36
|
+
}
|
|
37
|
+
const [type, token] = bearerHeader.split(' ');
|
|
38
|
+
if (type === 'Bearer') {
|
|
39
|
+
const userContext = await this.userGuard.populateUserContext(context);
|
|
40
|
+
if (!userContext) {
|
|
41
|
+
return false;
|
|
42
|
+
}
|
|
43
|
+
if (userContext.admin) {
|
|
44
|
+
return true;
|
|
45
|
+
}
|
|
46
|
+
await this.membershipModel.exists({ tenantId, userId: userContext.userId }).orFail(new common_1.HttpException('exception.notFound', 404));
|
|
47
|
+
return true;
|
|
48
|
+
}
|
|
49
|
+
if (type === 'AccessToken') {
|
|
50
|
+
const { userId, uuid } = await this.accessTokenModel.findOne({ tenantId, token }).orFail(new common_1.HttpException('exception.notFound', 404));
|
|
51
|
+
const { email } = await this.membershipModel.findOne({ tenantId, userId }).orFail(new common_1.HttpException('exception.notFound', 404));
|
|
52
|
+
const userContext = {
|
|
53
|
+
userId,
|
|
54
|
+
accessTokenId: uuid,
|
|
55
|
+
email,
|
|
56
|
+
admin: false,
|
|
57
|
+
};
|
|
58
|
+
req.userContext = userContext;
|
|
59
|
+
return true;
|
|
60
|
+
}
|
|
61
|
+
return false;
|
|
62
|
+
}
|
|
63
|
+
};
|
|
64
|
+
exports.TenantGuard = TenantGuard;
|
|
65
|
+
exports.TenantGuard = TenantGuard = __decorate([
|
|
66
|
+
(0, common_1.Injectable)(),
|
|
67
|
+
__param(0, (0, mongoose_1.InjectModel)(membership_entity_1.Membership.name)),
|
|
68
|
+
__param(1, (0, mongoose_1.InjectModel)(access_token_entity_1.AccessToken.name)),
|
|
69
|
+
__metadata("design:paramtypes", [Object, Object, user_guard_1.UserGuard])
|
|
70
|
+
], TenantGuard);
|
|
71
|
+
//# sourceMappingURL=tenant.guard.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"tenant.guard.js","sourceRoot":"","sources":["../../src/guards/tenant.guard.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;AAAA,2CAA0F;AAC1F,+CAA+C;AAC/C,yEAAgF;AAChF,qEAA4E;AAE5E,6CAAyC;AAGlC,IAAM,WAAW,GAAjB,MAAM,WAAW;IACtB,YACwC,eAAgC,EAC/B,gBAAkC,EACjE,SAAoB;QAFU,oBAAe,GAAf,eAAe,CAAiB;QAC/B,qBAAgB,GAAhB,gBAAgB,CAAkB;QACjE,cAAS,GAAT,SAAS,CAAW;IAC3B,CAAC;IAEG,KAAK,CAAC,WAAW,CAAC,OAAyB;QAChD,MAAM,GAAG,GAAG,OAAO,CAAC,YAAY,EAAE,CAAC,UAAU,EAAE,CAAC;QAEhD,MAAM,EAAE,QAAQ,EAAE,GAAG,GAAG,CAAC,MAAM,CAAC;QAEhC,IAAI,CAAC,QAAQ,EAAE,CAAC;YACd,OAAO,KAAK,CAAC;QACf,CAAC;QAED,MAAM,YAAY,GAAG,GAAG,CAAC,OAAO,CAAC,aAAa,CAAC;QAE/C,IAAI,CAAC,YAAY,EAAE,CAAC;YAClB,OAAO,KAAK,CAAC;QACf,CAAC;QAED,MAAM,CAAC,IAAI,EAAE,KAAK,CAAC,GAAG,YAAY,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC;QAE9C,IAAI,IAAI,KAAK,QAAQ,EAAE,CAAC;YACtB,MAAM,WAAW,GAAG,MAAM,IAAI,CAAC,SAAS,CAAC,mBAAmB,CAAC,OAAO,CAAC,CAAC;YAEtE,IAAI,CAAC,WAAW,EAAE,CAAC;gBACjB,OAAO,KAAK,CAAC;YACf,CAAC;YAED,IAAI,WAAW,CAAC,KAAK,EAAE,CAAC;gBACtB,OAAO,IAAI,CAAC;YACd,CAAC;YAED,MAAM,IAAI,CAAC,eAAe,CAAC,MAAM,CAAC,EAAE,QAAQ,EAAE,MAAM,EAAE,WAAW,CAAC,MAAM,EAAE,CAAC,CAAC,MAAM,CAAC,IAAI,sBAAa,CAAC,oBAAoB,EAAE,GAAG,CAAC,CAAC,CAAC;YAEjI,OAAO,IAAI,CAAC;QACd,CAAC;QAED,IAAI,IAAI,KAAK,aAAa,EAAE,CAAC;YAC3B,MAAM,EAAE,MAAM,EAAE,IAAI,EAAE,GAAG,MAAM,IAAI,CAAC,gBAAgB,CAAC,OAAO,CAAC,EAAE,QAAQ,EAAE,KAAK,EAAE,CAAC,CAAC,MAAM,CAAC,IAAI,sBAAa,CAAC,oBAAoB,EAAE,GAAG,CAAC,CAAC,CAAC;YACvI,MAAM,EAAE,KAAK,EAAE,GAAG,MAAM,IAAI,CAAC,eAAe,CAAC,OAAO,CAAC,EAAE,QAAQ,EAAE,MAAM,EAAE,CAAC,CAAC,MAAM,CAAC,IAAI,sBAAa,CAAC,oBAAoB,EAAE,GAAG,CAAC,CAAC,CAAC;YAEhI,MAAM,WAAW,GAAgB;gBAC/B,MAAM;gBACN,aAAa,EAAE,IAAI;gBACnB,KAAK;gBACL,KAAK,EAAE,KAAK;aACb,CAAC;YACF,GAAG,CAAC,WAAW,GAAG,WAAW,CAAC;YAE9B,OAAO,IAAI,CAAC;QACd,CAAC;QAED,OAAO,KAAK,CAAC;IACf,CAAC;CACF,CAAA;AAzDY,kCAAW;sBAAX,WAAW;IADvB,IAAA,mBAAU,GAAE;IAGR,WAAA,IAAA,sBAAW,EAAC,8BAAU,CAAC,IAAI,CAAC,CAAA;IAC5B,WAAA,IAAA,sBAAW,EAAC,iCAAW,CAAC,IAAI,CAAC,CAAA;qDACX,sBAAS;GAJnB,WAAW,CAyDvB"}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { CanActivate, ExecutionContext } from '@nestjs/common';
|
|
2
|
+
import { MembershipModel } from '../entities/membership.entity';
|
|
3
|
+
import { UserModel } from '../entities/user.entity';
|
|
4
|
+
import { UserContext } from '../helpers/context.decorator';
|
|
5
|
+
import { AuthService } from '../services/auth.service';
|
|
6
|
+
export declare class UserGuard implements CanActivate {
|
|
7
|
+
private membershipModel;
|
|
8
|
+
private userModel;
|
|
9
|
+
private authService;
|
|
10
|
+
constructor(membershipModel: MembershipModel, userModel: UserModel, authService: AuthService);
|
|
11
|
+
populateUserContext(context: ExecutionContext): Promise<UserContext | undefined>;
|
|
12
|
+
canActivate(context: ExecutionContext): Promise<boolean>;
|
|
13
|
+
}
|
|
@@ -0,0 +1,66 @@
|
|
|
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
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
|
+
exports.UserGuard = void 0;
|
|
16
|
+
const common_1 = require("@nestjs/common");
|
|
17
|
+
const mongoose_1 = require("@nestjs/mongoose");
|
|
18
|
+
const uuid_1 = require("uuid");
|
|
19
|
+
const membership_entity_1 = require("../entities/membership.entity");
|
|
20
|
+
const user_entity_1 = require("../entities/user.entity");
|
|
21
|
+
const auth_service_1 = require("../services/auth.service");
|
|
22
|
+
let UserGuard = class UserGuard {
|
|
23
|
+
constructor(membershipModel, userModel, authService) {
|
|
24
|
+
this.membershipModel = membershipModel;
|
|
25
|
+
this.userModel = userModel;
|
|
26
|
+
this.authService = authService;
|
|
27
|
+
}
|
|
28
|
+
async populateUserContext(context) {
|
|
29
|
+
const req = context.switchToHttp().getRequest();
|
|
30
|
+
const claims = await this.authService.getClaims(req.headers.authorization);
|
|
31
|
+
if (!claims) {
|
|
32
|
+
return undefined;
|
|
33
|
+
}
|
|
34
|
+
const userContext = {
|
|
35
|
+
userId: claims.sub,
|
|
36
|
+
email: claims.email,
|
|
37
|
+
admin: claims.admin || false,
|
|
38
|
+
};
|
|
39
|
+
req.userContext = userContext;
|
|
40
|
+
await this.userModel.updateOne({ userId: userContext.userId }, {
|
|
41
|
+
lastActivity: new Date(),
|
|
42
|
+
$setOnInsert: {
|
|
43
|
+
uuid: (0, uuid_1.v4)(),
|
|
44
|
+
createdAt: new Date(),
|
|
45
|
+
createdBy: userContext.email,
|
|
46
|
+
updatedAt: new Date(),
|
|
47
|
+
updatedBy: userContext.email,
|
|
48
|
+
},
|
|
49
|
+
}, { upsert: true });
|
|
50
|
+
const invitations = await this.membershipModel.find({ email: userContext.email, status: membership_entity_1.MembershipStatus.INVITED });
|
|
51
|
+
await Promise.all(invitations.map(async (invitation) => invitation.updateOne({ userId: userContext.userId, status: membership_entity_1.MembershipStatus.ACTIVE })));
|
|
52
|
+
return userContext;
|
|
53
|
+
}
|
|
54
|
+
async canActivate(context) {
|
|
55
|
+
const userContext = await this.populateUserContext(context);
|
|
56
|
+
return !!userContext;
|
|
57
|
+
}
|
|
58
|
+
};
|
|
59
|
+
exports.UserGuard = UserGuard;
|
|
60
|
+
exports.UserGuard = UserGuard = __decorate([
|
|
61
|
+
(0, common_1.Injectable)(),
|
|
62
|
+
__param(0, (0, mongoose_1.InjectModel)(membership_entity_1.Membership.name)),
|
|
63
|
+
__param(1, (0, mongoose_1.InjectModel)(user_entity_1.User.name)),
|
|
64
|
+
__metadata("design:paramtypes", [Object, Object, auth_service_1.AuthService])
|
|
65
|
+
], UserGuard);
|
|
66
|
+
//# sourceMappingURL=user.guard.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"user.guard.js","sourceRoot":"","sources":["../../src/guards/user.guard.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;AAAA,2CAA2E;AAC3E,+CAA+C;AAC/C,+BAA0B;AAC1B,qEAA8F;AAC9F,yDAA0D;AAE1D,2DAAuD;AAGhD,IAAM,SAAS,GAAf,MAAM,SAAS;IACpB,YACwC,eAAgC,EACtC,SAAoB,EAC5C,WAAwB;QAFM,oBAAe,GAAf,eAAe,CAAiB;QACtC,cAAS,GAAT,SAAS,CAAW;QAC5C,gBAAW,GAAX,WAAW,CAAa;IAC/B,CAAC;IAEG,KAAK,CAAC,mBAAmB,CAAC,OAAyB;QACxD,MAAM,GAAG,GAAG,OAAO,CAAC,YAAY,EAAE,CAAC,UAAU,EAAE,CAAC;QAEhD,MAAM,MAAM,GAAG,MAAM,IAAI,CAAC,WAAW,CAAC,SAAS,CAAC,GAAG,CAAC,OAAO,CAAC,aAAa,CAAC,CAAC;QAE3E,IAAI,CAAC,MAAM,EAAE,CAAC;YACZ,OAAO,SAAS,CAAC;QACnB,CAAC;QAED,MAAM,WAAW,GAAgB;YAC/B,MAAM,EAAE,MAAM,CAAC,GAAG;YAClB,KAAK,EAAE,MAAM,CAAC,KAAK;YACnB,KAAK,EAAE,MAAM,CAAC,KAAK,IAAI,KAAK;SAC7B,CAAC;QACF,GAAG,CAAC,WAAW,GAAG,WAAW,CAAC;QAE9B,MAAM,IAAI,CAAC,SAAS,CAAC,SAAS,CAC5B,EAAE,MAAM,EAAE,WAAW,CAAC,MAAM,EAAE,EAC9B;YACE,YAAY,EAAE,IAAI,IAAI,EAAE;YACxB,YAAY,EAAE;gBACZ,IAAI,EAAE,IAAA,SAAE,GAAE;gBACV,SAAS,EAAE,IAAI,IAAI,EAAE;gBACrB,SAAS,EAAE,WAAW,CAAC,KAAK;gBAC5B,SAAS,EAAE,IAAI,IAAI,EAAE;gBACrB,SAAS,EAAE,WAAW,CAAC,KAAK;aAC7B;SACF,EACD,EAAE,MAAM,EAAE,IAAI,EAAE,CACjB,CAAC;QAEF,MAAM,WAAW,GAAG,MAAM,IAAI,CAAC,eAAe,CAAC,IAAI,CAAC,EAAE,KAAK,EAAE,WAAW,CAAC,KAAK,EAAE,MAAM,EAAE,oCAAgB,CAAC,OAAO,EAAE,CAAC,CAAC;QACpH,MAAM,OAAO,CAAC,GAAG,CAAC,WAAW,CAAC,GAAG,CAAC,KAAK,EAAE,UAAU,EAAE,EAAE,CAAC,UAAU,CAAC,SAAS,CAAC,EAAE,MAAM,EAAE,WAAW,CAAC,MAAM,EAAE,MAAM,EAAE,oCAAgB,CAAC,MAAM,EAAE,CAAC,CAAC,CAAC,CAAC;QAEhJ,OAAO,WAAW,CAAC;IACrB,CAAC;IAEM,KAAK,CAAC,WAAW,CAAC,OAAyB;QAChD,MAAM,WAAW,GAAG,MAAM,IAAI,CAAC,mBAAmB,CAAC,OAAO,CAAC,CAAC;QAC5D,OAAO,CAAC,CAAC,WAAW,CAAC;IACvB,CAAC;CACF,CAAA;AAhDY,8BAAS;oBAAT,SAAS;IADrB,IAAA,mBAAU,GAAE;IAGR,WAAA,IAAA,sBAAW,EAAC,8BAAU,CAAC,IAAI,CAAC,CAAA;IAC5B,WAAA,IAAA,sBAAW,EAAC,kBAAI,CAAC,IAAI,CAAC,CAAA;qDACF,0BAAW;GAJvB,SAAS,CAgDrB"}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
export declare class UserContext {
|
|
2
|
+
userId: string;
|
|
3
|
+
accessTokenId?: string;
|
|
4
|
+
email: string;
|
|
5
|
+
admin: boolean;
|
|
6
|
+
}
|
|
7
|
+
export declare const UserCtx: (...dataOrPipes: (import("@nestjs/common").PipeTransform<any, any> | import("@nestjs/common").Type<import("@nestjs/common").PipeTransform<any, any>>)[]) => ParameterDecorator;
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.UserCtx = exports.UserContext = void 0;
|
|
4
|
+
const common_1 = require("@nestjs/common");
|
|
5
|
+
class UserContext {
|
|
6
|
+
}
|
|
7
|
+
exports.UserContext = UserContext;
|
|
8
|
+
exports.UserCtx = (0, common_1.createParamDecorator)((_, context) => {
|
|
9
|
+
return context.switchToHttp().getRequest().userContext;
|
|
10
|
+
});
|
|
11
|
+
//# sourceMappingURL=context.decorator.js.map
|