itlab-internal-services 2.2.1 → 2.3.0
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/env.d.ts +14 -0
- package/dist/env.js +14 -0
- package/dist/exceptions/bad-body.exception.d.ts +14 -0
- package/dist/exceptions/bad-body.exception.js +16 -0
- package/dist/exceptions/duplicate.exception.d.ts +14 -0
- package/dist/exceptions/duplicate.exception.js +16 -0
- package/dist/exceptions/index.d.ts +11 -0
- package/dist/exceptions/index.js +11 -0
- package/dist/exceptions/not-found.exception.d.ts +14 -0
- package/dist/exceptions/not-found.exception.js +16 -0
- package/dist/favicon.controller.d.ts +12 -0
- package/dist/favicon.controller.js +13 -0
- package/dist/guards/perms.guard.d.ts +28 -0
- package/dist/guards/perms.guard.js +40 -2
- package/dist/guards/puplic.guard.d.ts +5 -0
- package/dist/guards/puplic.guard.js +5 -0
- package/dist/http.logger.d.ts +6 -0
- package/dist/http.logger.js +9 -1
- package/dist/index.d.ts +2 -0
- package/dist/index.js +2 -0
- package/dist/interceptors/errors.interceptor.d.ts +33 -1
- package/dist/interceptors/errors.interceptor.js +41 -3
- package/dist/liveness.probe.d.ts +12 -2
- package/dist/liveness.probe.js +15 -13
- package/dist/models/content.d.ts +8 -0
- package/dist/models/content.js +21 -0
- package/dist/models/filter/index.d.ts +49 -0
- package/dist/models/filter/index.js +88 -0
- package/dist/models/filter/limit.property.d.ts +4 -0
- package/dist/models/filter/limit.property.js +11 -0
- package/dist/models/filter/skip.property.d.ts +4 -0
- package/dist/models/filter/skip.property.js +16 -0
- package/dist/models/filter/sort-direction.property.d.ts +4 -0
- package/dist/models/filter/sort-direction.property.js +16 -0
- package/dist/models/filter/sort-field.property.d.ts +4 -0
- package/dist/models/filter/sort-field.property.js +17 -0
- package/dist/models/index.d.ts +4 -0
- package/dist/models/index.js +20 -0
- package/dist/models/search-result.d.ts +14 -0
- package/dist/models/search-result.js +32 -0
- package/dist/models/thumbnail/alt.property.d.ts +8 -0
- package/dist/models/thumbnail/alt.property.js +18 -0
- package/dist/models/thumbnail/background.property.d.ts +8 -0
- package/dist/models/thumbnail/background.property.js +27 -0
- package/dist/models/thumbnail/contain.property.d.ts +8 -0
- package/dist/models/thumbnail/contain.property.js +18 -0
- package/dist/models/thumbnail/index.d.ts +30 -0
- package/dist/models/thumbnail/index.js +68 -0
- package/dist/models/thumbnail/max-height.property.d.ts +8 -0
- package/dist/models/thumbnail/max-height.property.js +20 -0
- package/dist/models/thumbnail/src.property.d.ts +8 -0
- package/dist/models/thumbnail/src.property.js +21 -0
- package/dist/modules/authentication/authentication.module.d.ts +14 -0
- package/dist/modules/authentication/authentication.module.js +10 -0
- package/dist/modules/authentication/internal/internal.constants.d.ts +4 -0
- package/dist/modules/authentication/internal/internal.constants.js +4 -0
- package/dist/modules/authentication/internal/internal.decorators.d.ts +4 -0
- package/dist/modules/authentication/internal/internal.decorators.js +4 -0
- package/dist/modules/authentication/internal/internal.guard.d.ts +5 -0
- package/dist/modules/authentication/internal/internal.guard.js +5 -0
- package/dist/modules/authentication/internal/internal.strategy.d.ts +17 -0
- package/dist/modules/authentication/internal/internal.strategy.js +17 -0
- package/dist/modules/authentication/jwt/jwt.constants.d.ts +20 -0
- package/dist/modules/authentication/jwt/jwt.constants.js +12 -0
- package/dist/modules/authentication/jwt/jwt.decorators.d.ts +15 -3
- package/dist/modules/authentication/jwt/jwt.decorators.js +16 -7
- package/dist/modules/authentication/jwt/jwt.guard.d.ts +15 -0
- package/dist/modules/authentication/jwt/jwt.guard.js +17 -0
- package/dist/modules/authentication/jwt/jwt.strategy.d.ts +16 -1
- package/dist/modules/authentication/jwt/jwt.strategy.js +16 -1
- package/dist/modules/database/database.module-options.d.ts +6 -0
- package/dist/modules/database/database.module.d.ts +19 -0
- package/dist/modules/database/database.module.js +41 -0
- package/dist/modules/database/index.js +12 -0
- package/dist/modules/database/model-service/model.service.d.ts +29 -0
- package/dist/modules/database/model-service/model.service.js +31 -0
- package/dist/modules/database/model-service/schemas/hub-account.schemas.d.ts +10 -0
- package/dist/modules/database/model-service/schemas/hub-account.schemas.js +7 -0
- package/dist/modules/database/model-service/schemas/hub-hackschool.schemas.js +3 -0
- package/dist/modules/database/model-service/schemas/hub-tech-radar.schemas.js +2 -0
- package/dist/modules/database/populate-service/populate.service.d.ts +35 -0
- package/dist/modules/database/populate-service/populate.service.js +35 -0
- package/dist/modules/database/service-mapper-service/service-mapper.service.d.ts +23 -0
- package/dist/modules/database/service-mapper-service/service-mapper.service.js +23 -0
- package/dist/modules/index.d.ts +1 -0
- package/dist/modules/index.js +1 -0
- package/dist/modules/like/index.d.ts +1 -0
- package/dist/modules/like/index.js +8 -0
- package/dist/modules/like/like.controller.d.ts +38 -0
- package/dist/modules/like/like.controller.js +119 -0
- package/dist/modules/like/like.module-options.d.ts +17 -0
- package/dist/modules/like/like.module-options.js +17 -0
- package/dist/modules/like/like.module.d.ts +18 -0
- package/dist/modules/like/like.module.js +45 -0
- package/dist/modules/like/like.service.d.ts +48 -0
- package/dist/modules/like/like.service.js +107 -0
- package/dist/modules/services/account-service/account.service.d.ts +15 -0
- package/dist/modules/services/account-service/account.service.js +15 -0
- package/dist/modules/services/comment-service/comment-service.definitions.d.ts +11 -0
- package/dist/modules/services/comment-service/comment-service.definitions.js +8 -0
- package/dist/modules/services/comment-service/comment.service.d.ts +26 -0
- package/dist/modules/services/comment-service/comment.service.js +26 -0
- package/dist/modules/services/content-service/content.service.d.ts +33 -1
- package/dist/modules/services/content-service/content.service.js +34 -2
- package/dist/modules/services/index.js +18 -0
- package/dist/modules/services/mail-service/mail-service.definitions.d.ts +15 -0
- package/dist/modules/services/mail-service/mail-service.definitions.js +6 -0
- package/dist/modules/services/mail-service/mail.service.d.ts +31 -0
- package/dist/modules/services/mail-service/mail.service.js +31 -0
- package/dist/modules/services/search-service/search-service.definitions.d.ts +13 -0
- package/dist/modules/services/search-service/search-service.definitions.js +9 -0
- package/dist/modules/services/search-service/search.service.d.ts +25 -0
- package/dist/modules/services/search-service/search.service.js +25 -0
- package/dist/modules/services/services.module-utils.d.ts +9 -0
- package/dist/modules/services/services.module-utils.js +5 -0
- package/dist/modules/services/services.module.d.ts +17 -0
- package/dist/modules/services/services.module.js +9 -0
- package/dist/pipes/hid.pipe.d.ts +30 -0
- package/dist/pipes/hid.pipe.js +49 -5
- package/dist/pipes/id.pipe.d.ts +20 -0
- package/dist/pipes/id.pipe.js +40 -4
- package/dist/pipes/target.pipe.d.ts +23 -0
- package/dist/pipes/target.pipe.js +48 -6
- package/dist/swagger.config.d.ts +36 -2
- package/dist/swagger.config.js +40 -3
- package/dist/transform/_trim.d.ts +7 -0
- package/dist/transform/_trim.js +16 -0
- package/dist/transform/index.d.ts +6 -0
- package/dist/transform/index.js +17 -0
- package/dist/transform/transformImage.d.ts +4 -0
- package/dist/transform/transformImage.js +16 -0
- package/dist/transform/transformString.d.ts +5 -0
- package/dist/transform/transformString.js +16 -0
- package/dist/transform/transformStringArray.d.ts +6 -0
- package/dist/transform/transformStringArray.js +24 -0
- package/dist/transform/transformStringLike.d.ts +20 -0
- package/dist/transform/transformStringLike.js +37 -0
- package/dist/transform/transformStringLowerCase.d.ts +5 -0
- package/dist/transform/transformStringLowerCase.js +16 -0
- package/dist/transform/transformStringSet.d.ts +6 -0
- package/dist/transform/transformStringSet.js +25 -0
- package/dist/virtuals.d.ts +43 -0
- package/dist/virtuals.js +44 -0
- package/package.json +3 -1
|
@@ -1,7 +1,21 @@
|
|
|
1
1
|
import { DynamicModule } from '@nestjs/common';
|
|
2
2
|
export interface AuthenticationModuleOptions {
|
|
3
|
+
/**
|
|
4
|
+
* If "true", registers `AuthenticationModule` as a global module.
|
|
5
|
+
* See: https://docs.nestjs.com/modules#global-modules
|
|
6
|
+
*/
|
|
3
7
|
isGlobal?: boolean;
|
|
4
8
|
}
|
|
9
|
+
/**
|
|
10
|
+
* Authentication module
|
|
11
|
+
* @class AuthenticationModule
|
|
12
|
+
*/
|
|
5
13
|
export declare class AuthenticationModule {
|
|
14
|
+
/**
|
|
15
|
+
* Create a new module with the provided options.
|
|
16
|
+
*
|
|
17
|
+
* @param {AuthenticationModuleOptions} options - optional options for the authentication module
|
|
18
|
+
* @return {DynamicModule} the newly created dynamic module
|
|
19
|
+
*/
|
|
6
20
|
static forRoot(options?: AuthenticationModuleOptions): DynamicModule;
|
|
7
21
|
}
|
|
@@ -11,7 +11,17 @@ exports.AuthenticationModule = void 0;
|
|
|
11
11
|
const common_1 = require("@nestjs/common");
|
|
12
12
|
const internal_strategy_1 = require("./internal/internal.strategy");
|
|
13
13
|
const jwt_strategy_1 = require("./jwt/jwt.strategy");
|
|
14
|
+
/**
|
|
15
|
+
* Authentication module
|
|
16
|
+
* @class AuthenticationModule
|
|
17
|
+
*/
|
|
14
18
|
let AuthenticationModule = AuthenticationModule_1 = class AuthenticationModule {
|
|
19
|
+
/**
|
|
20
|
+
* Create a new module with the provided options.
|
|
21
|
+
*
|
|
22
|
+
* @param {AuthenticationModuleOptions} options - optional options for the authentication module
|
|
23
|
+
* @return {DynamicModule} the newly created dynamic module
|
|
24
|
+
*/
|
|
15
25
|
static forRoot(options) {
|
|
16
26
|
return {
|
|
17
27
|
global: options ? options.isGlobal : false,
|
|
@@ -1,5 +1,9 @@
|
|
|
1
1
|
import { HttpStatus } from '@nestjs/common';
|
|
2
|
+
/** Header key for internal authentication */
|
|
2
3
|
export declare const INTERNAL_HEADER_KEY = "X-itlab-k8s-auth";
|
|
4
|
+
/** Internal authentication strategy name */
|
|
3
5
|
export declare const INTERNAL_STRATEGY_NAME = "itlab-internal-auth";
|
|
6
|
+
/** Internal authentication description on error */
|
|
4
7
|
export declare const INTERNAL_DESCRIPTION = "Application unauthorized";
|
|
8
|
+
/** Internal authentication status on error */
|
|
5
9
|
export declare const INTERNAL_STATUS = HttpStatus.FORBIDDEN;
|
|
@@ -2,7 +2,11 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.INTERNAL_STATUS = exports.INTERNAL_DESCRIPTION = exports.INTERNAL_STRATEGY_NAME = exports.INTERNAL_HEADER_KEY = void 0;
|
|
4
4
|
const common_1 = require("@nestjs/common");
|
|
5
|
+
/** Header key for internal authentication */
|
|
5
6
|
exports.INTERNAL_HEADER_KEY = 'X-itlab-k8s-auth';
|
|
7
|
+
/** Internal authentication strategy name */
|
|
6
8
|
exports.INTERNAL_STRATEGY_NAME = 'itlab-internal-auth';
|
|
9
|
+
/** Internal authentication description on error */
|
|
7
10
|
exports.INTERNAL_DESCRIPTION = 'Application unauthorized';
|
|
11
|
+
/** Internal authentication status on error */
|
|
8
12
|
exports.INTERNAL_STATUS = common_1.HttpStatus.FORBIDDEN;
|
|
@@ -5,5 +5,9 @@ const common_1 = require("@nestjs/common");
|
|
|
5
5
|
const swagger_1 = require("@nestjs/swagger");
|
|
6
6
|
const internal_constants_1 = require("./internal.constants");
|
|
7
7
|
const internal_guard_1 = require("./internal.guard");
|
|
8
|
+
/**
|
|
9
|
+
* Creates an ApiBasicAuth decorator
|
|
10
|
+
* @returns An ApiBasicAuth decorator
|
|
11
|
+
*/
|
|
8
12
|
const Internal = () => (0, common_1.applyDecorators)((0, swagger_1.ApiBasicAuth)(internal_constants_1.INTERNAL_HEADER_KEY), (0, common_1.UseGuards)(internal_guard_1.InternalGuard), (0, swagger_1.ApiResponse)({ description: internal_constants_1.INTERNAL_DESCRIPTION, status: internal_constants_1.INTERNAL_STATUS }));
|
|
9
13
|
exports.Internal = Internal;
|
|
@@ -1,4 +1,9 @@
|
|
|
1
1
|
declare const InternalGuard_base: import("@nestjs/passport").Type<import("@nestjs/passport").IAuthGuard>;
|
|
2
|
+
/**
|
|
3
|
+
* Internal authentication guard
|
|
4
|
+
* @class InternalGuard
|
|
5
|
+
* @extends {AuthGuard}
|
|
6
|
+
*/
|
|
2
7
|
export declare class InternalGuard extends InternalGuard_base {
|
|
3
8
|
}
|
|
4
9
|
export {};
|
|
@@ -10,6 +10,11 @@ exports.InternalGuard = void 0;
|
|
|
10
10
|
const common_1 = require("@nestjs/common");
|
|
11
11
|
const passport_1 = require("@nestjs/passport");
|
|
12
12
|
const internal_constants_1 = require("./internal.constants");
|
|
13
|
+
/**
|
|
14
|
+
* Internal authentication guard
|
|
15
|
+
* @class InternalGuard
|
|
16
|
+
* @extends {AuthGuard}
|
|
17
|
+
*/
|
|
13
18
|
let InternalGuard = class InternalGuard extends (0, passport_1.AuthGuard)(internal_constants_1.INTERNAL_STRATEGY_NAME) {
|
|
14
19
|
};
|
|
15
20
|
InternalGuard = __decorate([
|
|
@@ -2,9 +2,26 @@ import { ConfigService } from '@nestjs/config';
|
|
|
2
2
|
import { Request } from 'express';
|
|
3
3
|
import { Strategy, VerifiedCallback } from 'passport-custom';
|
|
4
4
|
declare const InternalStrategy_base: new (...args: any[]) => Strategy;
|
|
5
|
+
/**
|
|
6
|
+
* Internal authentication strategy
|
|
7
|
+
* @class InternalStrategy
|
|
8
|
+
* @extends {PassportStrategy}
|
|
9
|
+
*/
|
|
5
10
|
export declare class InternalStrategy extends InternalStrategy_base {
|
|
6
11
|
private readonly configService;
|
|
12
|
+
/**
|
|
13
|
+
* Constructor for initializing the ConfigService.
|
|
14
|
+
*
|
|
15
|
+
* @param {ConfigService} configService - the configuration service
|
|
16
|
+
*/
|
|
7
17
|
constructor(configService: ConfigService);
|
|
18
|
+
/**
|
|
19
|
+
* Check if requester is allowed to access the route by comparing the token
|
|
20
|
+
*
|
|
21
|
+
* @param {Request} req - the request object
|
|
22
|
+
* @param {VerifiedCallback} done - callback function for when the validation is done
|
|
23
|
+
* @return {void} no return value
|
|
24
|
+
*/
|
|
8
25
|
validate(req: Request, done: VerifiedCallback): void;
|
|
9
26
|
}
|
|
10
27
|
export {};
|
|
@@ -16,11 +16,28 @@ const passport_1 = require("@nestjs/passport");
|
|
|
16
16
|
const passport_custom_1 = require("passport-custom");
|
|
17
17
|
const env_1 = require("../../../env");
|
|
18
18
|
const internal_constants_1 = require("./internal.constants");
|
|
19
|
+
/**
|
|
20
|
+
* Internal authentication strategy
|
|
21
|
+
* @class InternalStrategy
|
|
22
|
+
* @extends {PassportStrategy}
|
|
23
|
+
*/
|
|
19
24
|
let InternalStrategy = class InternalStrategy extends (0, passport_1.PassportStrategy)(passport_custom_1.Strategy, internal_constants_1.INTERNAL_STRATEGY_NAME) {
|
|
25
|
+
/**
|
|
26
|
+
* Constructor for initializing the ConfigService.
|
|
27
|
+
*
|
|
28
|
+
* @param {ConfigService} configService - the configuration service
|
|
29
|
+
*/
|
|
20
30
|
constructor(configService) {
|
|
21
31
|
super();
|
|
22
32
|
this.configService = configService;
|
|
23
33
|
}
|
|
34
|
+
/**
|
|
35
|
+
* Check if requester is allowed to access the route by comparing the token
|
|
36
|
+
*
|
|
37
|
+
* @param {Request} req - the request object
|
|
38
|
+
* @param {VerifiedCallback} done - callback function for when the validation is done
|
|
39
|
+
* @return {void} no return value
|
|
40
|
+
*/
|
|
24
41
|
validate(req, done) {
|
|
25
42
|
const headerToken = req.header(internal_constants_1.INTERNAL_HEADER_KEY);
|
|
26
43
|
const token = this.configService.getOrThrow(env_1.ENV_K8S_TOKEN);
|
|
@@ -1,8 +1,28 @@
|
|
|
1
1
|
import { HttpStatus } from '@nestjs/common';
|
|
2
|
+
/** The name of the JWT strategy */
|
|
2
3
|
export declare const JWT_STRATEGY_NAME = "itlab-jwt-auth";
|
|
4
|
+
/** The description of a failed JWT strategy */
|
|
3
5
|
export declare const JWT_DESCRIPTION = "Unauthorized";
|
|
6
|
+
/** The status code of a failed JWT strategy */
|
|
4
7
|
export declare const JWT_STATUS = HttpStatus.UNAUTHORIZED;
|
|
8
|
+
/**
|
|
9
|
+
* Represents a lab account with id and permissions.
|
|
10
|
+
* @class LabAccount
|
|
11
|
+
* @property {string} id - The unique identifier for the account.
|
|
12
|
+
* @property {string[]} perms - The array of permissions for the account.
|
|
13
|
+
* @property {string} [username] - Optional: The username for the account.
|
|
14
|
+
* @property {string} [email] - Optional: The email for the account.
|
|
15
|
+
* @property {string} [avatar] - Optional: The avatar for the account.
|
|
16
|
+
*/
|
|
5
17
|
export declare class LabAccount {
|
|
18
|
+
/** The unique identifier for the account. */
|
|
6
19
|
id: string;
|
|
20
|
+
/** The array of permissions for the account. */
|
|
7
21
|
perms: string[];
|
|
22
|
+
/** Optional: The username for the account. */
|
|
23
|
+
username?: string;
|
|
24
|
+
/** Optional: The email for the account. */
|
|
25
|
+
email?: string;
|
|
26
|
+
/** Optional: The avatar for the account. */
|
|
27
|
+
avatar?: string;
|
|
8
28
|
}
|
|
@@ -2,9 +2,21 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.LabAccount = exports.JWT_STATUS = exports.JWT_DESCRIPTION = exports.JWT_STRATEGY_NAME = void 0;
|
|
4
4
|
const common_1 = require("@nestjs/common");
|
|
5
|
+
/** The name of the JWT strategy */
|
|
5
6
|
exports.JWT_STRATEGY_NAME = 'itlab-jwt-auth';
|
|
7
|
+
/** The description of a failed JWT strategy */
|
|
6
8
|
exports.JWT_DESCRIPTION = 'Unauthorized';
|
|
9
|
+
/** The status code of a failed JWT strategy */
|
|
7
10
|
exports.JWT_STATUS = common_1.HttpStatus.UNAUTHORIZED;
|
|
11
|
+
/**
|
|
12
|
+
* Represents a lab account with id and permissions.
|
|
13
|
+
* @class LabAccount
|
|
14
|
+
* @property {string} id - The unique identifier for the account.
|
|
15
|
+
* @property {string[]} perms - The array of permissions for the account.
|
|
16
|
+
* @property {string} [username] - Optional: The username for the account.
|
|
17
|
+
* @property {string} [email] - Optional: The email for the account.
|
|
18
|
+
* @property {string} [avatar] - Optional: The avatar for the account.
|
|
19
|
+
*/
|
|
8
20
|
class LabAccount {
|
|
9
21
|
}
|
|
10
22
|
exports.LabAccount = LabAccount;
|
|
@@ -1,5 +1,17 @@
|
|
|
1
|
+
import { LabAccount } from './jwt.constants';
|
|
2
|
+
/**
|
|
3
|
+
* Creates an ApiJwt decorator
|
|
4
|
+
* @returns A decorator that creates an API JWT
|
|
5
|
+
*/
|
|
1
6
|
export declare const Jwt: () => <TFunction extends Function, Y>(target: object | TFunction, propertyKey?: string | symbol, descriptor?: TypedPropertyDescriptor<Y>) => void;
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
7
|
+
/**
|
|
8
|
+
* Used to parse a authorized account from the request header
|
|
9
|
+
* @param {string} attr - Optional: The attribute of the account to extract
|
|
10
|
+
* @returns The extracted account or attr of the account
|
|
11
|
+
*/
|
|
12
|
+
export declare const Account: (...dataOrPipes: (keyof LabAccount | import("@nestjs/common").PipeTransform<any, any> | import("@nestjs/common").Type<import("@nestjs/common").PipeTransform<any, any>>)[]) => ParameterDecorator;
|
|
13
|
+
/**
|
|
14
|
+
* Used to parse a JWT token from the request header
|
|
15
|
+
* @returns The extracted JWT token
|
|
16
|
+
*/
|
|
5
17
|
export declare const JwtToken: (...dataOrPipes: any[]) => ParameterDecorator;
|
|
@@ -1,20 +1,29 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.JwtToken = exports.
|
|
3
|
+
exports.JwtToken = exports.Account = exports.Jwt = void 0;
|
|
4
4
|
const common_1 = require("@nestjs/common");
|
|
5
5
|
const swagger_1 = require("@nestjs/swagger");
|
|
6
6
|
const jwt_constants_1 = require("./jwt.constants");
|
|
7
7
|
const jwt_guard_1 = require("./jwt.guard");
|
|
8
|
+
/**
|
|
9
|
+
* Creates an ApiJwt decorator
|
|
10
|
+
* @returns A decorator that creates an API JWT
|
|
11
|
+
*/
|
|
8
12
|
const Jwt = () => (0, common_1.applyDecorators)((0, swagger_1.ApiBearerAuth)(), (0, common_1.UseGuards)(jwt_guard_1.JwtGuard), (0, swagger_1.ApiUnauthorizedResponse)({ description: jwt_constants_1.JWT_DESCRIPTION, status: jwt_constants_1.JWT_STATUS }));
|
|
9
13
|
exports.Jwt = Jwt;
|
|
10
|
-
|
|
14
|
+
/**
|
|
15
|
+
* Used to parse a authorized account from the request header
|
|
16
|
+
* @param {string} attr - Optional: The attribute of the account to extract
|
|
17
|
+
* @returns The extracted account or attr of the account
|
|
18
|
+
*/
|
|
19
|
+
exports.Account = (0, common_1.createParamDecorator)((attr, ctx) => {
|
|
11
20
|
const { user } = ctx.switchToHttp().getRequest();
|
|
12
|
-
return
|
|
21
|
+
return attr ? user === null || user === void 0 ? void 0 : user[attr] : user;
|
|
13
22
|
});
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
23
|
+
/**
|
|
24
|
+
* Used to parse a JWT token from the request header
|
|
25
|
+
* @returns The extracted JWT token
|
|
26
|
+
*/
|
|
18
27
|
exports.JwtToken = (0, common_1.createParamDecorator)((_, ctx) => {
|
|
19
28
|
const h = ctx.switchToHttp().getRequest().header('Authorization');
|
|
20
29
|
return h.replace('Bearer ', '');
|
|
@@ -1,9 +1,24 @@
|
|
|
1
1
|
import { ExecutionContext } from '@nestjs/common';
|
|
2
2
|
import { Reflector } from '@nestjs/core';
|
|
3
3
|
declare const JwtGuard_base: import("@nestjs/passport").Type<import("@nestjs/passport").IAuthGuard>;
|
|
4
|
+
/**
|
|
5
|
+
* JWT authentication guard
|
|
6
|
+
* @class JwtGuard
|
|
7
|
+
* @extends {AuthGuard}
|
|
8
|
+
*/
|
|
4
9
|
export declare class JwtGuard extends JwtGuard_base {
|
|
5
10
|
private readonly reflector;
|
|
11
|
+
/**
|
|
12
|
+
* Constructor for the JwtGuard.
|
|
13
|
+
*
|
|
14
|
+
* @param {Reflector} reflector - the reflector object
|
|
15
|
+
*/
|
|
6
16
|
constructor(reflector: Reflector);
|
|
17
|
+
/**
|
|
18
|
+
* Check if requester is allowed to access the route
|
|
19
|
+
* @param context - The execution context
|
|
20
|
+
* @returns A boolean indicating if the route is allowed to be accessed
|
|
21
|
+
*/
|
|
7
22
|
canActivate(context: ExecutionContext): boolean | Promise<boolean> | import("rxjs").Observable<boolean>;
|
|
8
23
|
}
|
|
9
24
|
export {};
|
|
@@ -15,18 +15,35 @@ const core_1 = require("@nestjs/core");
|
|
|
15
15
|
const passport_1 = require("@nestjs/passport");
|
|
16
16
|
const puplic_guard_1 = require("../../../guards/puplic.guard");
|
|
17
17
|
const jwt_constants_1 = require("./jwt.constants");
|
|
18
|
+
/**
|
|
19
|
+
* JWT authentication guard
|
|
20
|
+
* @class JwtGuard
|
|
21
|
+
* @extends {AuthGuard}
|
|
22
|
+
*/
|
|
18
23
|
let JwtGuard = class JwtGuard extends (0, passport_1.AuthGuard)(jwt_constants_1.JWT_STRATEGY_NAME) {
|
|
24
|
+
/**
|
|
25
|
+
* Constructor for the JwtGuard.
|
|
26
|
+
*
|
|
27
|
+
* @param {Reflector} reflector - the reflector object
|
|
28
|
+
*/
|
|
19
29
|
constructor(reflector) {
|
|
20
30
|
super();
|
|
21
31
|
this.reflector = reflector;
|
|
22
32
|
}
|
|
33
|
+
/**
|
|
34
|
+
* Check if requester is allowed to access the route
|
|
35
|
+
* @param context - The execution context
|
|
36
|
+
* @returns A boolean indicating if the route is allowed to be accessed
|
|
37
|
+
*/
|
|
23
38
|
canActivate(context) {
|
|
39
|
+
// Check if the route is marked as public
|
|
24
40
|
const isPublic = this.reflector.getAllAndOverride(puplic_guard_1.IS_PUBLIC_META, [
|
|
25
41
|
context.getHandler(),
|
|
26
42
|
context.getClass(),
|
|
27
43
|
]);
|
|
28
44
|
if (isPublic)
|
|
29
45
|
return true;
|
|
46
|
+
// If not marked as public, use the parent canActivate method
|
|
30
47
|
return super.canActivate(context);
|
|
31
48
|
}
|
|
32
49
|
};
|
|
@@ -1,9 +1,24 @@
|
|
|
1
1
|
import { ConfigService } from '@nestjs/config';
|
|
2
2
|
import { LabAccount } from './jwt.constants';
|
|
3
3
|
declare const JwtStrategy_base: new (...args: any[]) => any;
|
|
4
|
+
/**
|
|
5
|
+
* JWT authentication strategy
|
|
6
|
+
* @class JwtStrategy
|
|
7
|
+
* @extends {PassportStrategy}
|
|
8
|
+
*/
|
|
4
9
|
export declare class JwtStrategy extends JwtStrategy_base {
|
|
5
|
-
|
|
10
|
+
/**
|
|
11
|
+
* Constructor for creating a new instance of JwtStrategy
|
|
12
|
+
*
|
|
13
|
+
* @param {ConfigService} configService - the configuration service
|
|
14
|
+
*/
|
|
6
15
|
constructor(configService: ConfigService);
|
|
16
|
+
/**
|
|
17
|
+
* Validate the payload and return a LabAccount object.
|
|
18
|
+
*
|
|
19
|
+
* @param {any} payload - the payload to validate
|
|
20
|
+
* @return {LabAccount} the validated LabAccount object
|
|
21
|
+
*/
|
|
7
22
|
validate(payload: any): LabAccount;
|
|
8
23
|
}
|
|
9
24
|
export {};
|
|
@@ -16,14 +16,29 @@ const passport_1 = require("@nestjs/passport");
|
|
|
16
16
|
const passport_jwt_1 = require("passport-jwt");
|
|
17
17
|
const env_1 = require("../../../env");
|
|
18
18
|
const jwt_constants_1 = require("./jwt.constants");
|
|
19
|
+
/**
|
|
20
|
+
* JWT authentication strategy
|
|
21
|
+
* @class JwtStrategy
|
|
22
|
+
* @extends {PassportStrategy}
|
|
23
|
+
*/
|
|
19
24
|
let JwtStrategy = class JwtStrategy extends (0, passport_1.PassportStrategy)(passport_jwt_1.Strategy, jwt_constants_1.JWT_STRATEGY_NAME) {
|
|
25
|
+
/**
|
|
26
|
+
* Constructor for creating a new instance of JwtStrategy
|
|
27
|
+
*
|
|
28
|
+
* @param {ConfigService} configService - the configuration service
|
|
29
|
+
*/
|
|
20
30
|
constructor(configService) {
|
|
21
31
|
super({
|
|
22
32
|
jwtFromRequest: passport_jwt_1.ExtractJwt.fromAuthHeaderAsBearerToken(),
|
|
23
33
|
secretOrKey: configService.getOrThrow(env_1.ENV_JWT_SECRET),
|
|
24
34
|
});
|
|
25
|
-
this.configService = configService;
|
|
26
35
|
}
|
|
36
|
+
/**
|
|
37
|
+
* Validate the payload and return a LabAccount object.
|
|
38
|
+
*
|
|
39
|
+
* @param {any} payload - the payload to validate
|
|
40
|
+
* @return {LabAccount} the validated LabAccount object
|
|
41
|
+
*/
|
|
27
42
|
validate(payload) {
|
|
28
43
|
return { id: payload.id, perms: payload.perms || [] };
|
|
29
44
|
}
|
|
@@ -1,6 +1,25 @@
|
|
|
1
1
|
import { DynamicModule } from '@nestjs/common';
|
|
2
|
+
import { ModelDefinition } from '@nestjs/mongoose';
|
|
2
3
|
import { DatabaseModuleOptions } from './database.module-options';
|
|
4
|
+
/**
|
|
5
|
+
* Database module
|
|
6
|
+
* @class DatabaseModule
|
|
7
|
+
*/
|
|
3
8
|
export declare class DatabaseModule {
|
|
9
|
+
/** The Logger instance */
|
|
4
10
|
private static logger;
|
|
11
|
+
/**
|
|
12
|
+
* Register mongodb models to use in the module
|
|
13
|
+
*
|
|
14
|
+
* @param {ModelDefinition[]} models - array of model definitions
|
|
15
|
+
* @return {DynamicModule} Module with registered models
|
|
16
|
+
*/
|
|
17
|
+
static forFeature(...models: ModelDefinition[]): DynamicModule;
|
|
18
|
+
/**
|
|
19
|
+
* Creates a DatabaseModule for the root, with the provided options
|
|
20
|
+
*
|
|
21
|
+
* @param {DatabaseModuleOptions} options - the options for the DatabaseModule
|
|
22
|
+
* @return {DynamicModule} the DatabaseModule
|
|
23
|
+
*/
|
|
5
24
|
static forRoot(options: DatabaseModuleOptions): DynamicModule;
|
|
6
25
|
}
|
|
@@ -57,7 +57,26 @@ const env_1 = require("../../env");
|
|
|
57
57
|
const model_service_1 = require("./model-service/model.service");
|
|
58
58
|
const populate_service_1 = require("./populate-service/populate.service");
|
|
59
59
|
const service_mapper_service_1 = require("./service-mapper-service/service-mapper.service");
|
|
60
|
+
/**
|
|
61
|
+
* Database module
|
|
62
|
+
* @class DatabaseModule
|
|
63
|
+
*/
|
|
60
64
|
let DatabaseModule = DatabaseModule_1 = class DatabaseModule {
|
|
65
|
+
/**
|
|
66
|
+
* Register mongodb models to use in the module
|
|
67
|
+
*
|
|
68
|
+
* @param {ModelDefinition[]} models - array of model definitions
|
|
69
|
+
* @return {DynamicModule} Module with registered models
|
|
70
|
+
*/
|
|
71
|
+
static forFeature(...models) {
|
|
72
|
+
return mongoose_1.MongooseModule.forFeature(models);
|
|
73
|
+
}
|
|
74
|
+
/**
|
|
75
|
+
* Creates a DatabaseModule for the root, with the provided options
|
|
76
|
+
*
|
|
77
|
+
* @param {DatabaseModuleOptions} options - the options for the DatabaseModule
|
|
78
|
+
* @return {DynamicModule} the DatabaseModule
|
|
79
|
+
*/
|
|
61
80
|
static forRoot(options) {
|
|
62
81
|
return {
|
|
63
82
|
global: true,
|
|
@@ -76,6 +95,7 @@ let DatabaseModule = DatabaseModule_1 = class DatabaseModule {
|
|
|
76
95
|
const tlsDir = (0, path_1.join)(process.cwd(), configService.get(env_1.ENV_MONGO_CERT_DIR, 'mongo-tls'));
|
|
77
96
|
const tlsCAFile = (0, path_1.join)(tlsDir, 'hub-services-mongodb.ca.pem');
|
|
78
97
|
const tlsCertificateKeyFile = (0, path_1.join)(tlsDir, 'hub-services-mongodb.cert-key.pem');
|
|
98
|
+
// Production
|
|
79
99
|
if (production) {
|
|
80
100
|
this.logger.log('Running in production mode... Creating certificates');
|
|
81
101
|
(0, fs_1.mkdirSync)(tlsDir, { recursive: true });
|
|
@@ -89,6 +109,7 @@ let DatabaseModule = DatabaseModule_1 = class DatabaseModule {
|
|
|
89
109
|
(0, fs_1.writeFileSync)(tlsCertificateKeyFile, `${tlsCrt}\n${tlsKey}`);
|
|
90
110
|
this.logger.log('Created Client Certificate and Key (.pem)');
|
|
91
111
|
}
|
|
112
|
+
// Development
|
|
92
113
|
else {
|
|
93
114
|
this.logger.log(`Running in development mode... Using local certificates in ${tlsDir}`);
|
|
94
115
|
if (!(0, fs_1.existsSync)(tlsCAFile))
|
|
@@ -117,30 +138,50 @@ let DatabaseModule = DatabaseModule_1 = class DatabaseModule {
|
|
|
117
138
|
};
|
|
118
139
|
}
|
|
119
140
|
};
|
|
141
|
+
/** The Logger instance */
|
|
120
142
|
DatabaseModule.logger = new common_1.Logger(DatabaseModule_1.name);
|
|
121
143
|
DatabaseModule = DatabaseModule_1 = __decorate([
|
|
122
144
|
(0, common_1.Module)({})
|
|
123
145
|
], DatabaseModule);
|
|
124
146
|
exports.DatabaseModule = DatabaseModule;
|
|
147
|
+
/**
|
|
148
|
+
* Controller for kubernetes liveness probe
|
|
149
|
+
* @class DatabaseLivenessProbe
|
|
150
|
+
*/
|
|
125
151
|
let DatabaseLivenessProbe = class DatabaseLivenessProbe {
|
|
152
|
+
/**
|
|
153
|
+
* Constructor
|
|
154
|
+
* @param connection - The connection to the database
|
|
155
|
+
*/
|
|
126
156
|
constructor(connection) {
|
|
127
157
|
this.connection = connection;
|
|
128
158
|
}
|
|
159
|
+
/**
|
|
160
|
+
* Checks if the database is connected
|
|
161
|
+
*
|
|
162
|
+
* @param {Response} response - The response object
|
|
163
|
+
* @return {Promise<void>} Promise that resolves to void
|
|
164
|
+
*/
|
|
129
165
|
getAlive(response) {
|
|
130
166
|
return __awaiter(this, void 0, void 0, function* () {
|
|
167
|
+
// If the database is not connected, return an error
|
|
131
168
|
if (!this.connection || this.connection.readyState !== 1) {
|
|
132
169
|
response.status(500).send('Not connected to MongoDB');
|
|
133
170
|
return;
|
|
134
171
|
}
|
|
135
172
|
try {
|
|
173
|
+
// Ping the database
|
|
136
174
|
const result = yield this.connection.db.admin().ping();
|
|
175
|
+
// If the ping was successful, return 200
|
|
137
176
|
if (!!((result === null || result === void 0 ? void 0 : result.ok) === 1)) {
|
|
138
177
|
response.status(200).send({ ok: 1, db: 1 });
|
|
139
178
|
return;
|
|
140
179
|
}
|
|
180
|
+
// Otherwise, return an error
|
|
141
181
|
throw new Error('Could not connect to MongoDB');
|
|
142
182
|
}
|
|
143
183
|
catch (error) {
|
|
184
|
+
// If the ping failed, return an error
|
|
144
185
|
response.status(500).send("Couldn't connect to MongoDB");
|
|
145
186
|
}
|
|
146
187
|
});
|
|
@@ -1,11 +1,23 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.ServiceMapperService = exports.PopulateService = exports.ModelService = exports.DatabaseModule = void 0;
|
|
4
|
+
/*
|
|
5
|
+
* Database Module
|
|
6
|
+
*/
|
|
4
7
|
var database_module_1 = require("./database.module");
|
|
5
8
|
Object.defineProperty(exports, "DatabaseModule", { enumerable: true, get: function () { return database_module_1.DatabaseModule; } });
|
|
9
|
+
/*
|
|
10
|
+
* Model Service
|
|
11
|
+
*/
|
|
6
12
|
var model_service_1 = require("./model-service/model.service");
|
|
7
13
|
Object.defineProperty(exports, "ModelService", { enumerable: true, get: function () { return model_service_1.ModelService; } });
|
|
14
|
+
/*
|
|
15
|
+
* Populate Service
|
|
16
|
+
*/
|
|
8
17
|
var populate_service_1 = require("./populate-service/populate.service");
|
|
9
18
|
Object.defineProperty(exports, "PopulateService", { enumerable: true, get: function () { return populate_service_1.PopulateService; } });
|
|
19
|
+
/*
|
|
20
|
+
* ServiceMapper Service
|
|
21
|
+
*/
|
|
10
22
|
var service_mapper_service_1 = require("./service-mapper-service/service-mapper.service");
|
|
11
23
|
Object.defineProperty(exports, "ServiceMapperService", { enumerable: true, get: function () { return service_mapper_service_1.ServiceMapperService; } });
|