itlab-internal-services 2.2.2 → 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.
Files changed (144) hide show
  1. package/dist/env.d.ts +14 -0
  2. package/dist/env.js +14 -0
  3. package/dist/exceptions/bad-body.exception.d.ts +14 -0
  4. package/dist/exceptions/bad-body.exception.js +16 -0
  5. package/dist/exceptions/duplicate.exception.d.ts +14 -0
  6. package/dist/exceptions/duplicate.exception.js +16 -0
  7. package/dist/exceptions/index.d.ts +11 -0
  8. package/dist/exceptions/index.js +11 -0
  9. package/dist/exceptions/not-found.exception.d.ts +14 -0
  10. package/dist/exceptions/not-found.exception.js +16 -0
  11. package/dist/favicon.controller.d.ts +12 -0
  12. package/dist/favicon.controller.js +13 -0
  13. package/dist/guards/perms.guard.d.ts +28 -0
  14. package/dist/guards/perms.guard.js +40 -2
  15. package/dist/guards/puplic.guard.d.ts +5 -0
  16. package/dist/guards/puplic.guard.js +5 -0
  17. package/dist/http.logger.d.ts +6 -0
  18. package/dist/http.logger.js +9 -1
  19. package/dist/index.d.ts +2 -0
  20. package/dist/index.js +2 -0
  21. package/dist/interceptors/errors.interceptor.d.ts +33 -1
  22. package/dist/interceptors/errors.interceptor.js +41 -3
  23. package/dist/liveness.probe.d.ts +11 -0
  24. package/dist/liveness.probe.js +11 -0
  25. package/dist/models/content.d.ts +8 -0
  26. package/dist/models/content.js +21 -0
  27. package/dist/models/filter/index.d.ts +49 -0
  28. package/dist/models/filter/index.js +88 -0
  29. package/dist/models/filter/limit.property.d.ts +4 -0
  30. package/dist/models/filter/limit.property.js +11 -0
  31. package/dist/models/filter/skip.property.d.ts +4 -0
  32. package/dist/models/filter/skip.property.js +16 -0
  33. package/dist/models/filter/sort-direction.property.d.ts +4 -0
  34. package/dist/models/filter/sort-direction.property.js +16 -0
  35. package/dist/models/filter/sort-field.property.d.ts +4 -0
  36. package/dist/models/filter/sort-field.property.js +17 -0
  37. package/dist/models/index.d.ts +4 -0
  38. package/dist/models/index.js +20 -0
  39. package/dist/models/search-result.d.ts +14 -0
  40. package/dist/models/search-result.js +32 -0
  41. package/dist/models/thumbnail/alt.property.d.ts +8 -0
  42. package/dist/models/thumbnail/alt.property.js +18 -0
  43. package/dist/models/thumbnail/background.property.d.ts +8 -0
  44. package/dist/models/thumbnail/background.property.js +27 -0
  45. package/dist/models/thumbnail/contain.property.d.ts +8 -0
  46. package/dist/models/thumbnail/contain.property.js +18 -0
  47. package/dist/models/thumbnail/index.d.ts +30 -0
  48. package/dist/models/thumbnail/index.js +68 -0
  49. package/dist/models/thumbnail/max-height.property.d.ts +8 -0
  50. package/dist/models/thumbnail/max-height.property.js +20 -0
  51. package/dist/models/thumbnail/src.property.d.ts +8 -0
  52. package/dist/models/thumbnail/src.property.js +21 -0
  53. package/dist/modules/authentication/authentication.module.d.ts +14 -0
  54. package/dist/modules/authentication/authentication.module.js +10 -0
  55. package/dist/modules/authentication/internal/internal.constants.d.ts +4 -0
  56. package/dist/modules/authentication/internal/internal.constants.js +4 -0
  57. package/dist/modules/authentication/internal/internal.decorators.d.ts +4 -0
  58. package/dist/modules/authentication/internal/internal.decorators.js +4 -0
  59. package/dist/modules/authentication/internal/internal.guard.d.ts +5 -0
  60. package/dist/modules/authentication/internal/internal.guard.js +5 -0
  61. package/dist/modules/authentication/internal/internal.strategy.d.ts +17 -0
  62. package/dist/modules/authentication/internal/internal.strategy.js +17 -0
  63. package/dist/modules/authentication/jwt/jwt.constants.d.ts +20 -0
  64. package/dist/modules/authentication/jwt/jwt.constants.js +12 -0
  65. package/dist/modules/authentication/jwt/jwt.decorators.d.ts +15 -3
  66. package/dist/modules/authentication/jwt/jwt.decorators.js +16 -7
  67. package/dist/modules/authentication/jwt/jwt.guard.d.ts +15 -0
  68. package/dist/modules/authentication/jwt/jwt.guard.js +17 -0
  69. package/dist/modules/authentication/jwt/jwt.strategy.d.ts +16 -1
  70. package/dist/modules/authentication/jwt/jwt.strategy.js +16 -1
  71. package/dist/modules/database/database.module-options.d.ts +6 -0
  72. package/dist/modules/database/database.module.d.ts +19 -0
  73. package/dist/modules/database/database.module.js +41 -0
  74. package/dist/modules/database/index.js +12 -0
  75. package/dist/modules/database/model-service/model.service.d.ts +29 -0
  76. package/dist/modules/database/model-service/model.service.js +31 -0
  77. package/dist/modules/database/model-service/schemas/hub-account.schemas.d.ts +10 -0
  78. package/dist/modules/database/model-service/schemas/hub-account.schemas.js +7 -0
  79. package/dist/modules/database/model-service/schemas/hub-hackschool.schemas.js +3 -0
  80. package/dist/modules/database/model-service/schemas/hub-tech-radar.schemas.js +2 -0
  81. package/dist/modules/database/populate-service/populate.service.d.ts +35 -0
  82. package/dist/modules/database/populate-service/populate.service.js +35 -0
  83. package/dist/modules/database/service-mapper-service/service-mapper.service.d.ts +23 -0
  84. package/dist/modules/database/service-mapper-service/service-mapper.service.js +23 -0
  85. package/dist/modules/index.d.ts +1 -0
  86. package/dist/modules/index.js +1 -0
  87. package/dist/modules/like/index.d.ts +1 -0
  88. package/dist/modules/like/index.js +8 -0
  89. package/dist/modules/like/like.controller.d.ts +38 -0
  90. package/dist/modules/like/like.controller.js +119 -0
  91. package/dist/modules/like/like.module-options.d.ts +17 -0
  92. package/dist/modules/like/like.module-options.js +17 -0
  93. package/dist/modules/like/like.module.d.ts +18 -0
  94. package/dist/modules/like/like.module.js +45 -0
  95. package/dist/modules/like/like.service.d.ts +48 -0
  96. package/dist/modules/like/like.service.js +107 -0
  97. package/dist/modules/services/account-service/account.service.d.ts +15 -0
  98. package/dist/modules/services/account-service/account.service.js +15 -0
  99. package/dist/modules/services/comment-service/comment-service.definitions.d.ts +11 -0
  100. package/dist/modules/services/comment-service/comment-service.definitions.js +8 -0
  101. package/dist/modules/services/comment-service/comment.service.d.ts +26 -0
  102. package/dist/modules/services/comment-service/comment.service.js +26 -0
  103. package/dist/modules/services/content-service/content.service.d.ts +33 -1
  104. package/dist/modules/services/content-service/content.service.js +34 -2
  105. package/dist/modules/services/index.js +18 -0
  106. package/dist/modules/services/mail-service/mail-service.definitions.d.ts +15 -0
  107. package/dist/modules/services/mail-service/mail-service.definitions.js +6 -0
  108. package/dist/modules/services/mail-service/mail.service.d.ts +31 -0
  109. package/dist/modules/services/mail-service/mail.service.js +31 -0
  110. package/dist/modules/services/search-service/search-service.definitions.d.ts +13 -0
  111. package/dist/modules/services/search-service/search-service.definitions.js +9 -0
  112. package/dist/modules/services/search-service/search.service.d.ts +25 -0
  113. package/dist/modules/services/search-service/search.service.js +25 -0
  114. package/dist/modules/services/services.module-utils.d.ts +9 -0
  115. package/dist/modules/services/services.module-utils.js +5 -0
  116. package/dist/modules/services/services.module.d.ts +17 -0
  117. package/dist/modules/services/services.module.js +9 -0
  118. package/dist/pipes/hid.pipe.d.ts +30 -0
  119. package/dist/pipes/hid.pipe.js +49 -5
  120. package/dist/pipes/id.pipe.d.ts +20 -0
  121. package/dist/pipes/id.pipe.js +40 -4
  122. package/dist/pipes/target.pipe.d.ts +23 -0
  123. package/dist/pipes/target.pipe.js +48 -6
  124. package/dist/swagger.config.d.ts +36 -2
  125. package/dist/swagger.config.js +40 -3
  126. package/dist/transform/_trim.d.ts +7 -0
  127. package/dist/transform/_trim.js +16 -0
  128. package/dist/transform/index.d.ts +6 -0
  129. package/dist/transform/index.js +17 -0
  130. package/dist/transform/transformImage.d.ts +4 -0
  131. package/dist/transform/transformImage.js +16 -0
  132. package/dist/transform/transformString.d.ts +5 -0
  133. package/dist/transform/transformString.js +16 -0
  134. package/dist/transform/transformStringArray.d.ts +6 -0
  135. package/dist/transform/transformStringArray.js +24 -0
  136. package/dist/transform/transformStringLike.d.ts +20 -0
  137. package/dist/transform/transformStringLike.js +37 -0
  138. package/dist/transform/transformStringLowerCase.d.ts +5 -0
  139. package/dist/transform/transformStringLowerCase.js +16 -0
  140. package/dist/transform/transformStringSet.d.ts +6 -0
  141. package/dist/transform/transformStringSet.js +25 -0
  142. package/dist/virtuals.d.ts +43 -0
  143. package/dist/virtuals.js +44 -0
  144. package/package.json +3 -1
package/dist/env.d.ts CHANGED
@@ -1,3 +1,17 @@
1
+ /**
2
+ * Environment variables
3
+ *
4
+ * @exports
5
+ * ENV_K8S_TOKEN
6
+ * ENV_JWT_SECRET
7
+ * ENV_MONGO_SRV
8
+ * ENV_MONGO_USERNAME
9
+ * ENV_MONGO_PASSWORD
10
+ * ENV_MONGO_CERT_DIR
11
+ * ENV_MONGO_TLS_CA_CRT
12
+ * ENV_MONGO_TLS_TLS_CRT
13
+ * ENV_MONGO_TLS_TLS_KEY
14
+ */
1
15
  export declare const ENV_K8S_TOKEN = "K8S_TOKEN";
2
16
  export declare const ENV_JWT_SECRET = "JWT_SECRET";
3
17
  export declare const ENV_MONGO_SRV = "MONGO_SRV";
package/dist/env.js CHANGED
@@ -1,4 +1,18 @@
1
1
  "use strict";
2
+ /**
3
+ * Environment variables
4
+ *
5
+ * @exports
6
+ * ENV_K8S_TOKEN
7
+ * ENV_JWT_SECRET
8
+ * ENV_MONGO_SRV
9
+ * ENV_MONGO_USERNAME
10
+ * ENV_MONGO_PASSWORD
11
+ * ENV_MONGO_CERT_DIR
12
+ * ENV_MONGO_TLS_CA_CRT
13
+ * ENV_MONGO_TLS_TLS_CRT
14
+ * ENV_MONGO_TLS_TLS_KEY
15
+ */
2
16
  Object.defineProperty(exports, "__esModule", { value: true });
3
17
  exports.ENV_MONGO_TLS_TLS_KEY = exports.ENV_MONGO_TLS_TLS_CRT = exports.ENV_MONGO_TLS_CA_CRT = exports.ENV_MONGO_CERT_DIR = exports.ENV_MONGO_PASSWORD = exports.ENV_MONGO_USERNAME = exports.ENV_MONGO_SRV = exports.ENV_JWT_SECRET = exports.ENV_K8S_TOKEN = void 0;
4
18
  exports.ENV_K8S_TOKEN = 'K8S_TOKEN';
@@ -1,5 +1,19 @@
1
1
  import { ErrorException } from '.';
2
+ /**
3
+ * Custom exception for bad request body
4
+ * @class BadBodyException
5
+ * @extends {ErrorException}
6
+ */
2
7
  export declare class BadBodyException extends ErrorException {
8
+ /**
9
+ * Constructor for BadBodyException
10
+ * @param description - optional description for the exception
11
+ */
3
12
  constructor(description?: string);
4
13
  }
14
+ /**
15
+ * Creates an ApiBadBody decorator with the given description
16
+ * @param description - optional description for the exception
17
+ * @returns A decorator that creates an API bad body
18
+ */
5
19
  export declare const ApiBadBody: (description?: string) => MethodDecorator & ClassDecorator;
@@ -4,13 +4,29 @@ exports.ApiBadBody = exports.BadBodyException = void 0;
4
4
  const common_1 = require("@nestjs/common");
5
5
  const swagger_1 = require("@nestjs/swagger");
6
6
  const _1 = require(".");
7
+ /** Status code for bad bodies */
7
8
  const status = common_1.HttpStatus.METHOD_NOT_ALLOWED;
9
+ /** Description for bad bodies */
8
10
  const error = 'Bad Body';
11
+ /**
12
+ * Custom exception for bad request body
13
+ * @class BadBodyException
14
+ * @extends {ErrorException}
15
+ */
9
16
  class BadBodyException extends _1.ErrorException {
17
+ /**
18
+ * Constructor for BadBodyException
19
+ * @param description - optional description for the exception
20
+ */
10
21
  constructor(description) {
11
22
  super(error, status, description);
12
23
  }
13
24
  }
14
25
  exports.BadBodyException = BadBodyException;
26
+ /**
27
+ * Creates an ApiBadBody decorator with the given description
28
+ * @param description - optional description for the exception
29
+ * @returns A decorator that creates an API bad body
30
+ */
15
31
  const ApiBadBody = (description = error) => (0, swagger_1.ApiResponse)({ status, description });
16
32
  exports.ApiBadBody = ApiBadBody;
@@ -1,5 +1,19 @@
1
1
  import { ErrorException } from '.';
2
+ /**
3
+ * Represents an exception for duplicate errors.
4
+ * @class DuplicateException
5
+ * @extends {ErrorException}
6
+ */
2
7
  export declare class DuplicateException extends ErrorException {
8
+ /**
9
+ * Constructor for DuplicateException.
10
+ * @param description - Optional description for the exception.
11
+ */
3
12
  constructor(description?: string);
4
13
  }
14
+ /**
15
+ * Creates an ApiDuplicate decorator with the given description
16
+ * @param description - optional description for the exception
17
+ * @returns A decorator that creates an API duplicate
18
+ */
5
19
  export declare const ApiDuplicate: (description?: string) => MethodDecorator & ClassDecorator;
@@ -4,13 +4,29 @@ exports.ApiDuplicate = exports.DuplicateException = void 0;
4
4
  const common_1 = require("@nestjs/common");
5
5
  const swagger_1 = require("@nestjs/swagger");
6
6
  const _1 = require(".");
7
+ /** Status code for duplicates */
7
8
  const status = common_1.HttpStatus.CONFLICT;
9
+ /** Description for duplicates */
8
10
  const error = 'Duplicate';
11
+ /**
12
+ * Represents an exception for duplicate errors.
13
+ * @class DuplicateException
14
+ * @extends {ErrorException}
15
+ */
9
16
  class DuplicateException extends _1.ErrorException {
17
+ /**
18
+ * Constructor for DuplicateException.
19
+ * @param description - Optional description for the exception.
20
+ */
10
21
  constructor(description) {
11
22
  super(error, status, description);
12
23
  }
13
24
  }
14
25
  exports.DuplicateException = DuplicateException;
26
+ /**
27
+ * Creates an ApiDuplicate decorator with the given description
28
+ * @param description - optional description for the exception
29
+ * @returns A decorator that creates an API duplicate
30
+ */
15
31
  const ApiDuplicate = (description = error) => (0, swagger_1.ApiResponse)({ status, description });
16
32
  exports.ApiDuplicate = ApiDuplicate;
@@ -1,5 +1,16 @@
1
1
  import { HttpException } from '@nestjs/common';
2
+ /**
3
+ * Custom error exception class
4
+ * @class ErrorException
5
+ * @extends {HttpException}
6
+ */
2
7
  export declare class ErrorException extends HttpException {
8
+ /**
9
+ * Constructor for ErrorException
10
+ * @param error - The error message
11
+ * @param status - The status code
12
+ * @param description - The description of the error
13
+ */
3
14
  constructor(error: string, status: number, description?: string);
4
15
  }
5
16
  export * from './bad-body.exception';
@@ -16,7 +16,18 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
16
16
  Object.defineProperty(exports, "__esModule", { value: true });
17
17
  exports.ErrorException = void 0;
18
18
  const common_1 = require("@nestjs/common");
19
+ /**
20
+ * Custom error exception class
21
+ * @class ErrorException
22
+ * @extends {HttpException}
23
+ */
19
24
  class ErrorException extends common_1.HttpException {
25
+ /**
26
+ * Constructor for ErrorException
27
+ * @param error - The error message
28
+ * @param status - The status code
29
+ * @param description - The description of the error
30
+ */
20
31
  constructor(error, status, description) {
21
32
  super({ message: [description || error], status, error }, status);
22
33
  }
@@ -1,5 +1,19 @@
1
1
  import { ErrorException } from '.';
2
+ /**
3
+ * Custom exception for not found errors.
4
+ * @class NotFoundException
5
+ * @extends {ErrorException}
6
+ */
2
7
  export declare class NotFoundException extends ErrorException {
8
+ /**
9
+ * Constructor for NotFoundException.
10
+ * @param description - Description of the error.
11
+ */
3
12
  constructor(description?: string);
4
13
  }
14
+ /**
15
+ * Creates an ApiNotFound decorator with the given description
16
+ * @param description - Optional description for the exception
17
+ * @returns A decorator that creates an API not found
18
+ */
5
19
  export declare const ApiNotFound: (description?: string) => MethodDecorator & ClassDecorator;
@@ -4,13 +4,29 @@ exports.ApiNotFound = exports.NotFoundException = void 0;
4
4
  const common_1 = require("@nestjs/common");
5
5
  const swagger_1 = require("@nestjs/swagger");
6
6
  const _1 = require(".");
7
+ /** Status code for not found */
7
8
  const status = common_1.HttpStatus.NOT_FOUND;
9
+ /** Description for not found */
8
10
  const error = 'Not Found';
11
+ /**
12
+ * Custom exception for not found errors.
13
+ * @class NotFoundException
14
+ * @extends {ErrorException}
15
+ */
9
16
  class NotFoundException extends _1.ErrorException {
17
+ /**
18
+ * Constructor for NotFoundException.
19
+ * @param description - Description of the error.
20
+ */
10
21
  constructor(description) {
11
22
  super(error, status, description);
12
23
  }
13
24
  }
14
25
  exports.NotFoundException = NotFoundException;
26
+ /**
27
+ * Creates an ApiNotFound decorator with the given description
28
+ * @param description - Optional description for the exception
29
+ * @returns A decorator that creates an API not found
30
+ */
15
31
  const ApiNotFound = (description = error) => (0, swagger_1.ApiResponse)({ status, description });
16
32
  exports.ApiNotFound = ApiNotFound;
@@ -1,5 +1,17 @@
1
1
  import { Response } from 'express';
2
+ /**
3
+ * The FaviconController class
4
+ *
5
+ * @class FaviconController
6
+ */
2
7
  export declare class FaviconController {
8
+ /** The Axios instance to make requests */
3
9
  private axios;
10
+ /**
11
+ * A function to asynchronously get the favicon and pipe the data to the response.
12
+ *
13
+ * @param {type} res - The response object to pipe the data to
14
+ * @return {Promise<void>} Promise that resolves when the data has been piped to the response
15
+ */
4
16
  getFavicon(res: Response): Promise<void>;
5
17
  }
@@ -28,11 +28,24 @@ exports.FaviconController = void 0;
28
28
  const common_1 = require("@nestjs/common");
29
29
  const swagger_1 = require("@nestjs/swagger");
30
30
  const axios_1 = __importDefault(require("axios"));
31
+ /** The URL of the favicon image */
31
32
  const favicon = 'https://file.svi-itlab.com/650d514c58cbe60df3494bc0';
33
+ /**
34
+ * The FaviconController class
35
+ *
36
+ * @class FaviconController
37
+ */
32
38
  let FaviconController = class FaviconController {
33
39
  constructor() {
40
+ /** The Axios instance to make requests */
34
41
  this.axios = axios_1.default.create();
35
42
  }
43
+ /**
44
+ * A function to asynchronously get the favicon and pipe the data to the response.
45
+ *
46
+ * @param {type} res - The response object to pipe the data to
47
+ * @return {Promise<void>} Promise that resolves when the data has been piped to the response
48
+ */
36
49
  getFavicon(res) {
37
50
  return __awaiter(this, void 0, void 0, function* () {
38
51
  const { data } = yield this.axios.get(favicon, { responseType: 'stream' });
@@ -1,11 +1,39 @@
1
1
  import { CanActivate, ExecutionContext, HttpException } from '@nestjs/common';
2
2
  import { Reflector } from '@nestjs/core';
3
+ /**
4
+ * Permissions guard
5
+ * @class PermsGuard
6
+ * @implements {CanActivate}
7
+ */
3
8
  export declare class PermsGuard implements CanActivate {
4
9
  private readonly reflector;
10
+ /**
11
+ * Constructor for the PermsGuard
12
+ * @param reflector - the reflector
13
+ */
5
14
  constructor(reflector: Reflector);
15
+ /**
16
+ * Checks if the user has the required permissions to access the resource.
17
+ *
18
+ * @param {ExecutionContext} ctx - the execution context
19
+ * @return {boolean} whether the user has the required permissions
20
+ */
6
21
  canActivate(ctx: ExecutionContext): boolean;
7
22
  }
23
+ /**
24
+ * Insufficient permissions exception
25
+ * @class InsufficientPermissionsException
26
+ * @extends {HttpException}
27
+ */
8
28
  export declare class InsufficientPermissionsException extends HttpException {
29
+ /**
30
+ * Constructor for the InsufficientPermissionsException
31
+ */
9
32
  constructor();
10
33
  }
34
+ /**
35
+ * Create an ApiPerms decorator with the given permissions
36
+ * @param perms - the permissions required
37
+ * @returns An ApiPerms decorator
38
+ */
11
39
  export declare const Perms: (...perms: string[]) => <TFunction extends Function, Y>(target: object | TFunction, propertyKey?: string | symbol, descriptor?: TypedPropertyDescriptor<Y>) => void;
@@ -13,23 +13,48 @@ exports.Perms = exports.InsufficientPermissionsException = exports.PermsGuard =
13
13
  const common_1 = require("@nestjs/common");
14
14
  const core_1 = require("@nestjs/core");
15
15
  const swagger_1 = require("@nestjs/swagger");
16
+ const class_validator_1 = require("class-validator");
16
17
  const itlab_functions_1 = require("itlab-functions");
17
18
  const jwt_guard_1 = require("../modules/authentication/jwt/jwt.guard");
19
+ /** Metadata key for permissions */
18
20
  const META = 'itlab-internal-perms-guard';
21
+ /** Insufficient permissions */
19
22
  const description = 'Insufficient permissions';
23
+ /** Insufficient permissions status */
20
24
  const status = common_1.HttpStatus.FORBIDDEN;
25
+ /**
26
+ * Permissions guard
27
+ * @class PermsGuard
28
+ * @implements {CanActivate}
29
+ */
21
30
  let PermsGuard = class PermsGuard {
31
+ /**
32
+ * Constructor for the PermsGuard
33
+ * @param reflector - the reflector
34
+ */
22
35
  constructor(reflector) {
23
36
  this.reflector = reflector;
24
37
  }
38
+ /**
39
+ * Checks if the user has the required permissions to access the resource.
40
+ *
41
+ * @param {ExecutionContext} ctx - the execution context
42
+ * @return {boolean} whether the user has the required permissions
43
+ */
25
44
  canActivate(ctx) {
45
+ // Retrieve the permissions required for the handler from metadata
26
46
  let perms = this.reflector.get(META, ctx.getHandler());
47
+ // If no permissions are required, allow access
27
48
  if (!perms || !Array.isArray(perms) || perms.length === 0)
28
49
  return true;
50
+ // Retrieve the user from the request
29
51
  const { user } = ctx.switchToHttp().getRequest();
30
- const _ = user && user.perms && Array.isArray(user.perms) && user.perms.length > 0;
31
- if (_ && (0, itlab_functions_1.hasPermission)(perms, user.perms))
52
+ // Check if the user is valid and has at least one permission
53
+ const userValid = user && (0, class_validator_1.minLength)(user.perms, 1);
54
+ // If the user is valid and has the required permissions, allow access
55
+ if (userValid && (0, itlab_functions_1.hasPermission)(perms, user.perms))
32
56
  return true;
57
+ // If the user does not have the required permissions, throw an exception
33
58
  throw new InsufficientPermissionsException();
34
59
  }
35
60
  };
@@ -38,7 +63,15 @@ PermsGuard = __decorate([
38
63
  __metadata("design:paramtypes", [core_1.Reflector])
39
64
  ], PermsGuard);
40
65
  exports.PermsGuard = PermsGuard;
66
+ /**
67
+ * Insufficient permissions exception
68
+ * @class InsufficientPermissionsException
69
+ * @extends {HttpException}
70
+ */
41
71
  let InsufficientPermissionsException = class InsufficientPermissionsException extends common_1.HttpException {
72
+ /**
73
+ * Constructor for the InsufficientPermissionsException
74
+ */
42
75
  constructor() {
43
76
  super(description, status);
44
77
  }
@@ -48,5 +81,10 @@ InsufficientPermissionsException = __decorate([
48
81
  __metadata("design:paramtypes", [])
49
82
  ], InsufficientPermissionsException);
50
83
  exports.InsufficientPermissionsException = InsufficientPermissionsException;
84
+ /**
85
+ * Create an ApiPerms decorator with the given permissions
86
+ * @param perms - the permissions required
87
+ * @returns An ApiPerms decorator
88
+ */
51
89
  const Perms = (...perms) => (0, common_1.applyDecorators)((0, common_1.SetMetadata)(META, perms), (0, common_1.UseGuards)(jwt_guard_1.JwtGuard, PermsGuard), (0, swagger_1.ApiBearerAuth)(), (0, swagger_1.ApiResponse)({ description: `${description} (${perms.join(', ')})`, status }));
52
90
  exports.Perms = Perms;
@@ -1,2 +1,7 @@
1
+ /** Metadata key for public routes */
1
2
  export declare const IS_PUBLIC_META = "itlab-public-guard";
3
+ /**
4
+ * Marks a route as public and allows it to be accessed without authentication
5
+ * @returns An override of the ApiBearerAuth decorator
6
+ */
2
7
  export declare const Public: () => <TFunction extends Function, Y>(target: object | TFunction, propertyKey?: string | symbol, descriptor?: TypedPropertyDescriptor<Y>) => void;
@@ -3,6 +3,11 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.Public = exports.IS_PUBLIC_META = void 0;
4
4
  const common_1 = require("@nestjs/common");
5
5
  const swagger_1 = require("@nestjs/swagger");
6
+ /** Metadata key for public routes */
6
7
  exports.IS_PUBLIC_META = 'itlab-public-guard';
8
+ /**
9
+ * Marks a route as public and allows it to be accessed without authentication
10
+ * @returns An override of the ApiBearerAuth decorator
11
+ */
7
12
  const Public = () => (0, common_1.applyDecorators)((0, common_1.SetMetadata)(exports.IS_PUBLIC_META, true), (0, swagger_1.ApiBearerAuth)(), (0, swagger_1.ApiUnauthorizedResponse)({ description: "Public endpoint, won't be thrown" }));
8
13
  exports.Public = Public;
@@ -1,2 +1,8 @@
1
1
  import { INestApplication } from '@nestjs/common';
2
+ /**
3
+ * Middleware for logging HTTP requests and responses.
4
+ *
5
+ * @param {INestApplication} app - the Nest application instance
6
+ * @return {void}
7
+ */
2
8
  export declare function useHttpLogger(app: INestApplication): void;
@@ -2,14 +2,22 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.useHttpLogger = void 0;
4
4
  const common_1 = require("@nestjs/common");
5
+ /**
6
+ * Middleware for logging HTTP requests and responses.
7
+ *
8
+ * @param {INestApplication} app - the Nest application instance
9
+ * @return {void}
10
+ */
5
11
  function useHttpLogger(app) {
6
12
  app.use((req, res, next) => {
7
13
  const { method, url } = req;
14
+ // URLs to ignore from logging
8
15
  const ignore = ['/alive', '/favicon.ico'];
9
16
  if (url.includes('swagger') || url.startsWith('/api') || ignore.includes(url)) {
10
17
  next();
11
18
  return;
12
19
  }
20
+ // Log the response after it's finished
13
21
  res.on('finish', () => {
14
22
  const { statusCode, statusMessage } = res;
15
23
  const message = `${method} ${url} - ${statusCode} (${statusMessage})`;
@@ -17,7 +25,7 @@ function useHttpLogger(app) {
17
25
  if (!ignore.includes(url))
18
26
  new common_1.Logger('HTTP')[level](message);
19
27
  });
20
- next();
28
+ next(); // Continue to the next middleware
21
29
  });
22
30
  }
23
31
  exports.useHttpLogger = useHttpLogger;
package/dist/index.d.ts CHANGED
@@ -4,7 +4,9 @@ export * from './guards';
4
4
  export * from './http.logger';
5
5
  export * from './interceptors';
6
6
  export * from './liveness.probe';
7
+ export * from './models';
7
8
  export * from './modules';
8
9
  export * from './pipes';
9
10
  export * from './swagger.config';
11
+ export * from './transform';
10
12
  export * from './virtuals';
package/dist/index.js CHANGED
@@ -20,7 +20,9 @@ __exportStar(require("./guards"), exports);
20
20
  __exportStar(require("./http.logger"), exports);
21
21
  __exportStar(require("./interceptors"), exports);
22
22
  __exportStar(require("./liveness.probe"), exports);
23
+ __exportStar(require("./models"), exports);
23
24
  __exportStar(require("./modules"), exports);
24
25
  __exportStar(require("./pipes"), exports);
25
26
  __exportStar(require("./swagger.config"), exports);
27
+ __exportStar(require("./transform"), exports);
26
28
  __exportStar(require("./virtuals"), exports);
@@ -1,11 +1,43 @@
1
1
  import { CallHandler, ExecutionContext, INestApplication, NestInterceptor } from '@nestjs/common';
2
2
  import { Observable } from 'rxjs';
3
+ /**
4
+ * Error interceptor
5
+ * @class ErrorsInterceptor
6
+ * @implements {NestInterceptor}
7
+ */
3
8
  export declare class ErrorsInterceptor implements NestInterceptor {
4
9
  private readonly dictionary;
10
+ /**
11
+ * Constructor for the ErrorsInterceptor
12
+ * @param dictionary - The dictionary to use
13
+ */
5
14
  constructor(dictionary?: Record<string, string>);
6
- protected REGEX: RegExp;
15
+ /**
16
+ * A function that intercepts the execution context and the call handler, and returns an Observable of any type.
17
+ *
18
+ * @param {ExecutionContext} _context - the execution context parameter
19
+ * @param {CallHandler} next - the call handler parameter
20
+ * @return {Observable<any>} an Observable of any type
21
+ */
7
22
  intercept(_context: ExecutionContext, next: CallHandler): Observable<any>;
23
+ /**
24
+ * Transforms the message
25
+ *
26
+ * @param {string} message - the input message to be transformed
27
+ * @param {string[]} parent - the parent message array
28
+ * @return {string} the transformed message
29
+ */
8
30
  protected transform(message: string, parent: string[]): string;
9
31
  }
32
+ /**
33
+ * Create an UsesErrorsInterceptor decorator with the given dictionary
34
+ * @param dictionary - The dictionary to use
35
+ * @returns An UsesErrorsInterceptor decorator
36
+ */
10
37
  export declare const UsesErrorsInterceptor: (dictionary?: Record<string, string>) => <TFunction extends Function, Y>(target: object | TFunction, propertyKey?: string | symbol, descriptor?: TypedPropertyDescriptor<Y>) => void;
38
+ /**
39
+ * Use global errors interceptor
40
+ * @param app - The Nest application
41
+ * @param dictionary - A dictionary to use
42
+ */
11
43
  export declare const useGlobalErrrorsInterceptor: (app: INestApplication, dictionary?: Record<string, string>) => void;
@@ -12,25 +12,53 @@ Object.defineProperty(exports, "__esModule", { value: true });
12
12
  exports.useGlobalErrrorsInterceptor = exports.UsesErrorsInterceptor = exports.ErrorsInterceptor = void 0;
13
13
  const common_1 = require("@nestjs/common");
14
14
  const rxjs_1 = require("rxjs");
15
+ /**
16
+ * Error interceptor
17
+ * @class ErrorsInterceptor
18
+ * @implements {NestInterceptor}
19
+ */
15
20
  let ErrorsInterceptor = class ErrorsInterceptor {
21
+ /**
22
+ * Constructor for the ErrorsInterceptor
23
+ * @param dictionary - The dictionary to use
24
+ */
16
25
  constructor(dictionary = {}) {
17
26
  this.dictionary = dictionary;
18
- this.REGEX = /^\D+\.\d+\..+$/;
19
27
  }
28
+ /**
29
+ * A function that intercepts the execution context and the call handler, and returns an Observable of any type.
30
+ *
31
+ * @param {ExecutionContext} _context - the execution context parameter
32
+ * @param {CallHandler} next - the call handler parameter
33
+ * @return {Observable<any>} an Observable of any type
34
+ */
20
35
  intercept(_context, next) {
36
+ // Using pipe method to handle the observable
21
37
  return next.handle().pipe((0, rxjs_1.catchError)((err) => {
22
38
  let { message } = err.response;
39
+ // Checking if the message is present and converting it to an array if not
23
40
  if (!message)
24
41
  message = [];
25
42
  if (!Array.isArray(message))
26
43
  message = [message];
44
+ // Mapping over the message array and transforming the string messages if necessary
27
45
  err.response.message = message.map((m) => (typeof m === 'string' ? this.transform(m, []) : m));
46
+ // Removing duplicate messages
28
47
  err.response.message = [...new Set(err.response.message)];
48
+ // Throwing the error after processing
29
49
  throw err;
30
50
  }));
31
51
  }
52
+ /**
53
+ * Transforms the message
54
+ *
55
+ * @param {string} message - the input message to be transformed
56
+ * @param {string[]} parent - the parent message array
57
+ * @return {string} the transformed message
58
+ */
32
59
  transform(message, parent) {
33
- if (!this.REGEX.test(message)) {
60
+ const REGEX = /^\D+\.\d+\..+$/;
61
+ if (!REGEX.test(message)) {
34
62
  const split = message.split('.');
35
63
  if (split.length > 1) {
36
64
  const m = split.pop();
@@ -47,7 +75,7 @@ let ErrorsInterceptor = class ErrorsInterceptor {
47
75
  const prefix = this.dictionary[parent.join('.')] || parent[parent.length - 1];
48
76
  const index = _.shift();
49
77
  const error = _.join('.');
50
- const delimiter = this.REGEX.test(error) ? '⟩' : '•';
78
+ const delimiter = REGEX.test(error) ? '⟩' : '•';
51
79
  return `${prefix} #${+index + 1} ${delimiter} ${this.transform(error, parent)}`;
52
80
  }
53
81
  };
@@ -56,8 +84,18 @@ ErrorsInterceptor = __decorate([
56
84
  __metadata("design:paramtypes", [Object])
57
85
  ], ErrorsInterceptor);
58
86
  exports.ErrorsInterceptor = ErrorsInterceptor;
87
+ /**
88
+ * Create an UsesErrorsInterceptor decorator with the given dictionary
89
+ * @param dictionary - The dictionary to use
90
+ * @returns An UsesErrorsInterceptor decorator
91
+ */
59
92
  const UsesErrorsInterceptor = (dictionary) => (0, common_1.applyDecorators)((0, common_1.UseInterceptors)(new ErrorsInterceptor(dictionary)));
60
93
  exports.UsesErrorsInterceptor = UsesErrorsInterceptor;
94
+ /**
95
+ * Use global errors interceptor
96
+ * @param app - The Nest application
97
+ * @param dictionary - A dictionary to use
98
+ */
61
99
  const useGlobalErrrorsInterceptor = (app, dictionary) => {
62
100
  app.useGlobalInterceptors(new ErrorsInterceptor(dictionary));
63
101
  };
@@ -1,4 +1,15 @@
1
1
  import { Response } from 'express';
2
+ /**
3
+ * The LivenessProbe controller
4
+ *
5
+ * @class LivenessProbe
6
+ */
2
7
  export declare class LivenessProbe {
8
+ /**
9
+ * A function that handles getting alive status.
10
+ *
11
+ * @param {@Res()} response - the response object
12
+ * @return {Promise<void>} a Promise that resolves to void
13
+ */
3
14
  getAlive(response: Response): Promise<void>;
4
15
  }
@@ -24,7 +24,18 @@ Object.defineProperty(exports, "__esModule", { value: true });
24
24
  exports.LivenessProbe = void 0;
25
25
  const common_1 = require("@nestjs/common");
26
26
  const swagger_1 = require("@nestjs/swagger");
27
+ /**
28
+ * The LivenessProbe controller
29
+ *
30
+ * @class LivenessProbe
31
+ */
27
32
  let LivenessProbe = class LivenessProbe {
33
+ /**
34
+ * A function that handles getting alive status.
35
+ *
36
+ * @param {@Res()} response - the response object
37
+ * @return {Promise<void>} a Promise that resolves to void
38
+ */
28
39
  getAlive(response) {
29
40
  return __awaiter(this, void 0, void 0, function* () {
30
41
  response.status(200).send({ ok: 1 });
@@ -0,0 +1,8 @@
1
+ import { ApiPropertyOptions } from '@nestjs/swagger';
2
+ /**
3
+ * Creates a ContentDecorator with the given options.
4
+ *
5
+ * @param {ApiPropertyOptions} options - the options for the Content
6
+ * @return PropertyDecorator
7
+ */
8
+ export declare const PropertyContent: (options?: ApiPropertyOptions) => <TFunction extends Function, Y>(target: object | TFunction, propertyKey?: string | symbol, descriptor?: TypedPropertyDescriptor<Y>) => void;