itlab-internal-services 2.2.2 → 2.4.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/axios.d.ts +16 -0
- package/dist/{modules/services/services.module-utils.js → axios.js} +6 -1
- package/dist/env.d.ts +14 -0
- package/dist/env.js +14 -0
- package/dist/exceptions/bad-body.exception.d.ts +22 -1
- package/dist/exceptions/bad-body.exception.js +42 -1
- package/dist/exceptions/duplicate.exception.d.ts +22 -1
- package/dist/exceptions/duplicate.exception.js +42 -1
- package/dist/exceptions/index.d.ts +18 -0
- package/dist/exceptions/index.js +11 -0
- package/dist/exceptions/not-found.exception.d.ts +22 -1
- package/dist/exceptions/not-found.exception.js +42 -1
- 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 +4 -1
- package/dist/index.js +4 -1
- package/dist/interceptors/errors.interceptor.d.ts +33 -1
- package/dist/interceptors/errors.interceptor.js +41 -3
- package/dist/liveness.probe.d.ts +11 -0
- package/dist/liveness.probe.js +11 -0
- 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/account/account.module.d.ts +12 -0
- package/dist/modules/account/account.module.js +34 -0
- package/dist/modules/account/account.service.d.ts +23 -0
- package/dist/modules/{services/account-service → account}/account.service.js +18 -3
- package/dist/modules/account/index.d.ts +2 -0
- package/dist/modules/account/index.js +7 -0
- package/dist/modules/authentication/authentication.module.d.ts +9 -4
- package/dist/modules/authentication/authentication.module.js +10 -2
- package/dist/modules/authentication/index.d.ts +1 -1
- 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/comment/comment.controller.d.ts +24 -0
- package/dist/modules/comment/comment.controller.js +78 -0
- package/dist/modules/comment/comment.module-options.d.ts +18 -0
- package/dist/modules/{services/comment-service/comment-service.definitions.js → comment/comment.module-options.js} +10 -0
- package/dist/modules/comment/comment.module.d.ts +19 -0
- package/dist/modules/comment/comment.module.js +57 -0
- package/dist/modules/comment/comment.service.d.ts +42 -0
- package/dist/modules/comment/comment.service.js +113 -0
- package/dist/modules/comment/index.d.ts +3 -0
- package/dist/modules/comment/index.js +12 -0
- package/dist/modules/content/content.module.d.ts +18 -0
- package/dist/modules/content/content.module.js +46 -0
- package/dist/modules/content/content.service.d.ts +43 -0
- package/dist/modules/{services/content-service → content}/content.service.js +53 -17
- package/dist/modules/content/index.d.ts +2 -0
- package/dist/modules/content/index.js +7 -0
- 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 +6 -1
- package/dist/modules/index.js +6 -1
- 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/mail/index.d.ts +3 -0
- package/dist/modules/mail/index.js +10 -0
- package/dist/modules/mail/mail.models.d.ts +28 -0
- package/dist/modules/{services/mail-service/mail-service.definitions.js → mail/mail.models.js} +6 -0
- package/dist/modules/mail/mail.module.d.ts +12 -0
- package/dist/modules/mail/mail.module.js +34 -0
- package/dist/modules/mail/mail.service.d.ts +42 -0
- package/dist/modules/{services/mail-service → mail}/mail.service.js +34 -3
- package/dist/modules/search/index.d.ts +3 -0
- package/dist/modules/search/index.js +9 -0
- package/dist/modules/search/search.models.d.ts +19 -0
- package/dist/modules/{services/search-service/search-service.definitions.js → search/search.models.js} +9 -0
- package/dist/modules/search/search.module.d.ts +18 -0
- package/dist/modules/search/search.module.js +46 -0
- package/dist/modules/search/search.service.d.ts +35 -0
- package/dist/modules/{services/search-service → search}/search.service.js +44 -15
- 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/schema.transformer.d.ts +2 -0
- package/dist/schema.transformer.js +10 -0
- 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.factory.d.ts +57 -0
- package/dist/virtuals.factory.js +117 -0
- package/package.json +3 -1
- package/dist/modules/services/account-service/account.service.d.ts +0 -8
- package/dist/modules/services/comment-service/comment-service.definitions.d.ts +0 -5
- package/dist/modules/services/comment-service/comment.service.d.ts +0 -12
- package/dist/modules/services/comment-service/comment.service.js +0 -75
- package/dist/modules/services/content-service/content.service.d.ts +0 -12
- package/dist/modules/services/index.d.ts +0 -9
- package/dist/modules/services/index.js +0 -22
- package/dist/modules/services/mail-service/mail-service.definitions.d.ts +0 -13
- package/dist/modules/services/mail-service/mail.service.d.ts +0 -11
- package/dist/modules/services/search-service/search-service.definitions.d.ts +0 -6
- package/dist/modules/services/search-service/search.service.d.ts +0 -11
- package/dist/modules/services/services.module-utils.d.ts +0 -7
- package/dist/modules/services/services.module.d.ts +0 -7
- package/dist/modules/services/services.module.js +0 -30
- package/dist/virtuals.d.ts +0 -8
- package/dist/virtuals.js +0 -77
package/dist/axios.d.ts
ADDED
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { AxiosInstance } from 'axios';
|
|
2
|
+
/**
|
|
3
|
+
* Options for creating an axios instance
|
|
4
|
+
* @interface CreateAxiosOptions
|
|
5
|
+
*/
|
|
6
|
+
interface CreateAxiosOptions {
|
|
7
|
+
baseUrl: string;
|
|
8
|
+
k8sToken: string;
|
|
9
|
+
}
|
|
10
|
+
/**
|
|
11
|
+
* Create an axios instance
|
|
12
|
+
* @param options - the options for the axios instance
|
|
13
|
+
* @returns {AxiosInstance} the created axios instance
|
|
14
|
+
*/
|
|
15
|
+
export declare const createAxios: (options: CreateAxiosOptions) => AxiosInstance;
|
|
16
|
+
export {};
|
|
@@ -5,7 +5,12 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
6
|
exports.createAxios = void 0;
|
|
7
7
|
const axios_1 = __importDefault(require("axios"));
|
|
8
|
-
const internal_constants_1 = require("
|
|
8
|
+
const internal_constants_1 = require("./modules/authentication/internal/internal.constants");
|
|
9
|
+
/**
|
|
10
|
+
* Create an axios instance
|
|
11
|
+
* @param options - the options for the axios instance
|
|
12
|
+
* @returns {AxiosInstance} the created axios instance
|
|
13
|
+
*/
|
|
9
14
|
const createAxios = (options) => {
|
|
10
15
|
return axios_1.default.create({
|
|
11
16
|
baseURL: options.baseUrl,
|
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,26 @@
|
|
|
1
|
-
import { ErrorException } from '.';
|
|
1
|
+
import { ErrorException, UseException } 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;
|
|
20
|
+
/**
|
|
21
|
+
* Creates a bad body exception with the given description and returns an array containing the Exception class and the ApiDecorator function.
|
|
22
|
+
*
|
|
23
|
+
* @param {string} description - The description for the bad body exception
|
|
24
|
+
* @return {UseException<typeof BadBodyException>} An array containing the Exception class and the ApiDecorator function
|
|
25
|
+
*/
|
|
26
|
+
export declare function useBadBodyException(description?: string): UseException<typeof BadBodyException>;
|
|
@@ -1,16 +1,57 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.ApiBadBody = exports.BadBodyException = void 0;
|
|
3
|
+
exports.useBadBodyException = 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;
|
|
33
|
+
/**
|
|
34
|
+
* Creates a bad body exception with the given description and returns an array containing the Exception class and the ApiDecorator function.
|
|
35
|
+
*
|
|
36
|
+
* @param {string} description - The description for the bad body exception
|
|
37
|
+
* @return {UseException<typeof BadBodyException>} An array containing the Exception class and the ApiDecorator function
|
|
38
|
+
*/
|
|
39
|
+
function useBadBodyException(description = error) {
|
|
40
|
+
/**
|
|
41
|
+
* Creates a bad body exception with the given description
|
|
42
|
+
* @class Exception
|
|
43
|
+
* @extends {BadBodyException}
|
|
44
|
+
*/
|
|
45
|
+
class Exception extends BadBodyException {
|
|
46
|
+
/**
|
|
47
|
+
* Constructor for BadBodyException.
|
|
48
|
+
* @param desc - Description of the error.
|
|
49
|
+
*/
|
|
50
|
+
constructor(desc = description) {
|
|
51
|
+
super(desc);
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
// Return an array containing the Exception class and the ApiDecorator function
|
|
55
|
+
return [Exception, () => (0, exports.ApiBadBody)(description)];
|
|
56
|
+
}
|
|
57
|
+
exports.useBadBodyException = useBadBodyException;
|
|
@@ -1,5 +1,26 @@
|
|
|
1
|
-
import { ErrorException } from '.';
|
|
1
|
+
import { ErrorException, UseException } 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;
|
|
20
|
+
/**
|
|
21
|
+
* Creates a duplicate exception with the given description and returns an array containing the Exception class and the ApiDecorator function.
|
|
22
|
+
*
|
|
23
|
+
* @param {string} description - The description for the duplicate exception
|
|
24
|
+
* @return {UseException<typeof DuplicateException>} An array containing the Exception class and the ApiDecorator function
|
|
25
|
+
*/
|
|
26
|
+
export declare function useDuplicateException(description?: string): UseException<typeof DuplicateException>;
|
|
@@ -1,16 +1,57 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.ApiDuplicate = exports.DuplicateException = void 0;
|
|
3
|
+
exports.useDuplicateException = 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;
|
|
33
|
+
/**
|
|
34
|
+
* Creates a duplicate exception with the given description and returns an array containing the Exception class and the ApiDecorator function.
|
|
35
|
+
*
|
|
36
|
+
* @param {string} description - The description for the duplicate exception
|
|
37
|
+
* @return {UseException<typeof DuplicateException>} An array containing the Exception class and the ApiDecorator function
|
|
38
|
+
*/
|
|
39
|
+
function useDuplicateException(description = error) {
|
|
40
|
+
/**
|
|
41
|
+
* Creates a duplicate exception with the given description
|
|
42
|
+
* @class Exception
|
|
43
|
+
* @extends {DuplicateException}
|
|
44
|
+
*/
|
|
45
|
+
class Exception extends DuplicateException {
|
|
46
|
+
/**
|
|
47
|
+
* Constructor for DuplicateException.
|
|
48
|
+
* @param desc - Description of the error.
|
|
49
|
+
*/
|
|
50
|
+
constructor(desc = description) {
|
|
51
|
+
super(desc);
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
// Return an array containing the Exception class and the ApiDecorator function
|
|
55
|
+
return [Exception, () => (0, exports.ApiDuplicate)(description)];
|
|
56
|
+
}
|
|
57
|
+
exports.useDuplicateException = useDuplicateException;
|
|
@@ -1,7 +1,25 @@
|
|
|
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
|
}
|
|
16
|
+
/**
|
|
17
|
+
* Type representing the use of an exception
|
|
18
|
+
* @typedef {Array} UseException
|
|
19
|
+
* @property {typeof ErrorException} 0 - The type of error exception
|
|
20
|
+
* @property {Function} 1 - The method and class decorator
|
|
21
|
+
*/
|
|
22
|
+
export declare type UseException<T> = [T, () => MethodDecorator & ClassDecorator];
|
|
5
23
|
export * from './bad-body.exception';
|
|
6
24
|
export * from './duplicate.exception';
|
|
7
25
|
export * from './not-found.exception';
|
package/dist/exceptions/index.js
CHANGED
|
@@ -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,26 @@
|
|
|
1
|
-
import { ErrorException } from '.';
|
|
1
|
+
import { ErrorException, UseException } 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;
|
|
20
|
+
/**
|
|
21
|
+
* Creates a not found exception with the given description and returns an array containing the Exception class and the ApiDecorator function.
|
|
22
|
+
*
|
|
23
|
+
* @param {string} description - The description for the not found exception
|
|
24
|
+
* @return {UseException<typeof NotFoundException>} An array containing the Exception class and the ApiDecorator function
|
|
25
|
+
*/
|
|
26
|
+
export declare function useNotFoundException(description?: string): UseException<typeof NotFoundException>;
|
|
@@ -1,16 +1,57 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.ApiNotFound = exports.NotFoundException = void 0;
|
|
3
|
+
exports.useNotFoundException = 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;
|
|
33
|
+
/**
|
|
34
|
+
* Creates a not found exception with the given description and returns an array containing the Exception class and the ApiDecorator function.
|
|
35
|
+
*
|
|
36
|
+
* @param {string} description - The description for the not found exception
|
|
37
|
+
* @return {UseException<typeof NotFoundException>} An array containing the Exception class and the ApiDecorator function
|
|
38
|
+
*/
|
|
39
|
+
function useNotFoundException(description = error) {
|
|
40
|
+
/**
|
|
41
|
+
* Creates a not found exception with the given description
|
|
42
|
+
* @class Exception
|
|
43
|
+
* @extends {NotFoundException}
|
|
44
|
+
*/
|
|
45
|
+
class Exception extends NotFoundException {
|
|
46
|
+
/**
|
|
47
|
+
* Constructor for NotFoundException.
|
|
48
|
+
* @param desc - Description of the error.
|
|
49
|
+
*/
|
|
50
|
+
constructor(desc = description) {
|
|
51
|
+
super(desc);
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
// Return an array containing the Exception class and the ApiDecorator function
|
|
55
|
+
return [Exception, () => (0, exports.ApiNotFound)(description)];
|
|
56
|
+
}
|
|
57
|
+
exports.useNotFoundException = useNotFoundException;
|
|
@@ -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
|
-
|
|
31
|
-
|
|
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;
|
package/dist/http.logger.d.ts
CHANGED
|
@@ -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;
|
package/dist/http.logger.js
CHANGED
|
@@ -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,10 @@ 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';
|
|
10
|
+
export * from './schema.transformer';
|
|
9
11
|
export * from './swagger.config';
|
|
10
|
-
export * from './
|
|
12
|
+
export * from './transform';
|
|
13
|
+
export * from './virtuals.factory';
|
package/dist/index.js
CHANGED
|
@@ -20,7 +20,10 @@ __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);
|
|
26
|
+
__exportStar(require("./schema.transformer"), exports);
|
|
25
27
|
__exportStar(require("./swagger.config"), exports);
|
|
26
|
-
__exportStar(require("./
|
|
28
|
+
__exportStar(require("./transform"), exports);
|
|
29
|
+
__exportStar(require("./virtuals.factory"), exports);
|