@maioradv/nestjs-core 1.0.9 → 1.1.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.
@@ -6,10 +6,6 @@ export declare class SortingDto implements DefaultSortingI {
6
6
  get orderBy(): {
7
7
  [x: string]: any;
8
8
  }[];
9
- get orderByRDB(): {
10
- column: string;
11
- order: any;
12
- }[];
13
9
  }
14
10
  export interface DefaultSortingI {
15
11
  id?: Sorting;
@@ -19,11 +19,6 @@ class SortingDto {
19
19
  return { [entry[0]]: entry[1] };
20
20
  });
21
21
  }
22
- get orderByRDB() {
23
- return Object.entries(this).map(entry => {
24
- return { column: entry[0], order: entry[1] };
25
- });
26
- }
27
22
  }
28
23
  exports.SortingDto = SortingDto;
29
24
  __decorate([
@@ -0,0 +1,8 @@
1
+ import { ExecutionContext } from "@nestjs/common";
2
+ import { ThrottlerGuard } from "@nestjs/throttler";
3
+ export declare class GqlThrottlerGuard extends ThrottlerGuard {
4
+ getRequestResponse(context: ExecutionContext): {
5
+ req: any;
6
+ res: any;
7
+ };
8
+ }
@@ -0,0 +1,29 @@
1
+ "use strict";
2
+ var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
3
+ var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
4
+ if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
5
+ else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
6
+ return c > 3 && r && Object.defineProperty(target, key, r), r;
7
+ };
8
+ Object.defineProperty(exports, "__esModule", { value: true });
9
+ exports.GqlThrottlerGuard = void 0;
10
+ const common_1 = require("@nestjs/common");
11
+ const graphql_1 = require("@nestjs/graphql");
12
+ const throttler_1 = require("@nestjs/throttler");
13
+ let GqlThrottlerGuard = class GqlThrottlerGuard extends throttler_1.ThrottlerGuard {
14
+ getRequestResponse(context) {
15
+ if (context.getType() === 'graphql') {
16
+ const gqlCtx = graphql_1.GqlExecutionContext.create(context);
17
+ const ctx = gqlCtx.getContext();
18
+ return { req: ctx.req, res: ctx.res };
19
+ }
20
+ return {
21
+ req: context.switchToHttp().getRequest(),
22
+ res: context.switchToHttp().getResponse()
23
+ };
24
+ }
25
+ };
26
+ exports.GqlThrottlerGuard = GqlThrottlerGuard;
27
+ exports.GqlThrottlerGuard = GqlThrottlerGuard = __decorate([
28
+ (0, common_1.Injectable)()
29
+ ], GqlThrottlerGuard);
@@ -0,0 +1 @@
1
+ export * from './gql-throttler.guard';
@@ -0,0 +1,17 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
+ };
16
+ Object.defineProperty(exports, "__esModule", { value: true });
17
+ __exportStar(require("./gql-throttler.guard"), exports);
package/dist/index.d.ts CHANGED
@@ -4,3 +4,6 @@ export * from './dto';
4
4
  export * from './errors';
5
5
  export * from './filters';
6
6
  export * from './logger';
7
+ export * from './guards';
8
+ export * from './model';
9
+ export * from './providers';
package/dist/index.js CHANGED
@@ -20,3 +20,6 @@ __exportStar(require("./dto"), exports);
20
20
  __exportStar(require("./errors"), exports);
21
21
  __exportStar(require("./filters"), exports);
22
22
  __exportStar(require("./logger"), exports);
23
+ __exportStar(require("./guards"), exports);
24
+ __exportStar(require("./model"), exports);
25
+ __exportStar(require("./providers"), exports);
@@ -0,0 +1,3 @@
1
+ import { CursorQueryDto } from "../dto/pagination";
2
+ export default abstract class CursorQueryA extends CursorQueryDto {
3
+ }
@@ -0,0 +1,16 @@
1
+ "use strict";
2
+ var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
3
+ var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
4
+ if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
5
+ else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
6
+ return c > 3 && r && Object.defineProperty(target, key, r), r;
7
+ };
8
+ Object.defineProperty(exports, "__esModule", { value: true });
9
+ const pagination_1 = require("../dto/pagination");
10
+ const graphql_1 = require("@nestjs/graphql");
11
+ let CursorQueryA = class CursorQueryA extends pagination_1.CursorQueryDto {
12
+ };
13
+ CursorQueryA = __decorate([
14
+ (0, graphql_1.ArgsType)()
15
+ ], CursorQueryA);
16
+ exports.default = CursorQueryA;
@@ -0,0 +1,3 @@
1
+ export * from './cursor-query.abstract';
2
+ export * from './paginated-query.abstract';
3
+ export * from './remove-gql.response';
@@ -0,0 +1,19 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
+ };
16
+ Object.defineProperty(exports, "__esModule", { value: true });
17
+ __exportStar(require("./cursor-query.abstract"), exports);
18
+ __exportStar(require("./paginated-query.abstract"), exports);
19
+ __exportStar(require("./remove-gql.response"), exports);
@@ -0,0 +1,11 @@
1
+ import { DefaultClausesI } from "../dto/clauses";
2
+ import { PaginatedQueryDto } from "../dto/pagination";
3
+ export default abstract class PaginatedQueryA extends PaginatedQueryDto implements DefaultClausesI {
4
+ id?: number[];
5
+ createdAt?: Date;
6
+ updatedAt?: Date;
7
+ minCreatedAt?: Date;
8
+ maxCreatedAt?: Date;
9
+ minUpdatedAt?: Date;
10
+ maxUpdatedAt?: Date;
11
+ }
@@ -0,0 +1,44 @@
1
+ "use strict";
2
+ var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
3
+ var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
4
+ if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
5
+ else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
6
+ return c > 3 && r && Object.defineProperty(target, key, r), r;
7
+ };
8
+ var __metadata = (this && this.__metadata) || function (k, v) {
9
+ if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
10
+ };
11
+ Object.defineProperty(exports, "__esModule", { value: true });
12
+ const clauses_1 = require("../dto/clauses");
13
+ const pagination_1 = require("../dto/pagination");
14
+ class PaginatedQueryA extends pagination_1.PaginatedQueryDto {
15
+ }
16
+ exports.default = PaginatedQueryA;
17
+ __decorate([
18
+ (0, clauses_1.IsNumberClause)(),
19
+ __metadata("design:type", Array)
20
+ ], PaginatedQueryA.prototype, "id", void 0);
21
+ __decorate([
22
+ (0, clauses_1.IsDateStringClause)(),
23
+ __metadata("design:type", Date)
24
+ ], PaginatedQueryA.prototype, "createdAt", void 0);
25
+ __decorate([
26
+ (0, clauses_1.IsDateStringClause)(),
27
+ __metadata("design:type", Date)
28
+ ], PaginatedQueryA.prototype, "updatedAt", void 0);
29
+ __decorate([
30
+ (0, clauses_1.IsDateStringClause)(),
31
+ __metadata("design:type", Date)
32
+ ], PaginatedQueryA.prototype, "minCreatedAt", void 0);
33
+ __decorate([
34
+ (0, clauses_1.IsDateStringClause)(),
35
+ __metadata("design:type", Date)
36
+ ], PaginatedQueryA.prototype, "maxCreatedAt", void 0);
37
+ __decorate([
38
+ (0, clauses_1.IsDateStringClause)(),
39
+ __metadata("design:type", Date)
40
+ ], PaginatedQueryA.prototype, "minUpdatedAt", void 0);
41
+ __decorate([
42
+ (0, clauses_1.IsDateStringClause)(),
43
+ __metadata("design:type", Date)
44
+ ], PaginatedQueryA.prototype, "maxUpdatedAt", void 0);
@@ -0,0 +1,3 @@
1
+ export declare class RemoveGQL {
2
+ count: number;
3
+ }
@@ -0,0 +1,23 @@
1
+ "use strict";
2
+ var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
3
+ var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
4
+ if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
5
+ else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
6
+ return c > 3 && r && Object.defineProperty(target, key, r), r;
7
+ };
8
+ var __metadata = (this && this.__metadata) || function (k, v) {
9
+ if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
10
+ };
11
+ Object.defineProperty(exports, "__esModule", { value: true });
12
+ exports.RemoveGQL = void 0;
13
+ const graphql_1 = require("@nestjs/graphql");
14
+ let RemoveGQL = class RemoveGQL {
15
+ };
16
+ exports.RemoveGQL = RemoveGQL;
17
+ __decorate([
18
+ (0, graphql_1.Field)(() => graphql_1.Int),
19
+ __metadata("design:type", Number)
20
+ ], RemoveGQL.prototype, "count", void 0);
21
+ exports.RemoveGQL = RemoveGQL = __decorate([
22
+ (0, graphql_1.ObjectType)()
23
+ ], RemoveGQL);
@@ -0,0 +1,9 @@
1
+ import { ConfigService } from '@nestjs/config';
2
+ export declare class CryptService {
3
+ private readonly configService;
4
+ constructor(configService: ConfigService);
5
+ hash(word: string): Promise<string>;
6
+ hashCompare(word: string, hash: string): Promise<boolean>;
7
+ encrypt(word: string, salt?: string): Promise<string>;
8
+ decrypt(str: string, salt?: string): Promise<string>;
9
+ }
@@ -0,0 +1,83 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
15
+ }) : function(o, v) {
16
+ o["default"] = v;
17
+ });
18
+ var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
19
+ var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
20
+ if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
21
+ else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
22
+ return c > 3 && r && Object.defineProperty(target, key, r), r;
23
+ };
24
+ var __importStar = (this && this.__importStar) || function (mod) {
25
+ if (mod && mod.__esModule) return mod;
26
+ var result = {};
27
+ if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
28
+ __setModuleDefault(result, mod);
29
+ return result;
30
+ };
31
+ var __metadata = (this && this.__metadata) || function (k, v) {
32
+ if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
33
+ };
34
+ Object.defineProperty(exports, "__esModule", { value: true });
35
+ exports.CryptService = void 0;
36
+ const common_1 = require("@nestjs/common");
37
+ const config_1 = require("@nestjs/config");
38
+ const bcrypt = __importStar(require("bcrypt"));
39
+ const crypto_1 = require("crypto");
40
+ const util_1 = require("util");
41
+ const SALT_ROUNDS = 10;
42
+ const _S_ = '::';
43
+ const SALT = 'basicsaltgeneralpurpose';
44
+ let CryptService = class CryptService {
45
+ constructor(configService) {
46
+ this.configService = configService;
47
+ }
48
+ async hash(word) {
49
+ return bcrypt.hash(word, SALT_ROUNDS);
50
+ }
51
+ async hashCompare(word, hash) {
52
+ return bcrypt.compare(word, hash);
53
+ }
54
+ async encrypt(word, salt = SALT) {
55
+ const PASSPHRASE = this.configService.get('CRYPT_PASSPHRASE');
56
+ const iv = (0, crypto_1.randomBytes)(16);
57
+ const key = (await (0, util_1.promisify)(crypto_1.scrypt)(PASSPHRASE, salt, 32));
58
+ const cipher = (0, crypto_1.createCipheriv)('aes-256-ctr', key, iv);
59
+ const encryptedText = Buffer.concat([
60
+ cipher.update(word),
61
+ cipher.final(),
62
+ ]);
63
+ return encryptedText.toString('hex') + _S_ + iv.toString('hex');
64
+ }
65
+ async decrypt(str, salt = SALT) {
66
+ const PASSPHRASE = this.configService.get('CRYPT_PASSPHRASE');
67
+ const [encryptedText, ivs] = str.split(_S_);
68
+ const iv = Buffer.from(ivs, 'hex');
69
+ const buffer = Buffer.from(encryptedText, 'hex');
70
+ const key = (await (0, util_1.promisify)(crypto_1.scrypt)(PASSPHRASE, salt, 32));
71
+ const decipher = (0, crypto_1.createDecipheriv)('aes-256-ctr', key, iv);
72
+ const decryptedText = Buffer.concat([
73
+ decipher.update(buffer),
74
+ decipher.final(),
75
+ ]);
76
+ return decryptedText.toString('utf-8');
77
+ }
78
+ };
79
+ exports.CryptService = CryptService;
80
+ exports.CryptService = CryptService = __decorate([
81
+ (0, common_1.Injectable)(),
82
+ __metadata("design:paramtypes", [config_1.ConfigService])
83
+ ], CryptService);
@@ -0,0 +1 @@
1
+ export * from './crypt.service';
@@ -0,0 +1,17 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
+ };
16
+ Object.defineProperty(exports, "__esModule", { value: true });
17
+ __exportStar(require("./crypt.service"), exports);
@@ -2,6 +2,6 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.joinFromRoot = exports.ROOT_PATH = void 0;
4
4
  const path_1 = require("path");
5
- exports.ROOT_PATH = (0, path_1.join)(__dirname, '..', '../../', '../../');
5
+ exports.ROOT_PATH = (0, path_1.join)(process.cwd());
6
6
  const joinFromRoot = (...paths) => (0, path_1.join)(exports.ROOT_PATH, ...paths);
7
7
  exports.joinFromRoot = joinFromRoot;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@maioradv/nestjs-core",
3
- "version": "1.0.9",
3
+ "version": "1.1.0",
4
4
  "description": "NestJS helpers by MaiorADV",
5
5
  "repository": "https://github.com/maioradv/nestjs-core.git",
6
6
  "author": "Maior ADV Srl",
@@ -17,9 +17,12 @@
17
17
  },
18
18
  "dependencies": {
19
19
  "@nestjs/common": "^10.3.8",
20
+ "@nestjs/config": "^3.2.2",
20
21
  "@nestjs/graphql": "^12.1.1",
21
- "@nestjs/swagger": "^7.3.1",
22
22
  "@nestjs/platform-express": "^10.0.0",
23
+ "@nestjs/swagger": "^7.3.1",
24
+ "@nestjs/throttler": "^5.2.0",
25
+ "bcrypt": "^5.1.1",
23
26
  "class-transformer": "^0.5.1",
24
27
  "class-validator": "^0.14.1",
25
28
  "nest-winston": "^1.10.0",
@@ -33,9 +36,11 @@
33
36
  },
34
37
  "peerDependencies": {
35
38
  "@nestjs/common": "^10.3.8",
39
+ "@nestjs/config": "^3.2.2",
36
40
  "@nestjs/graphql": "^12.1.1",
37
- "@nestjs/swagger": "^7.3.1",
38
41
  "@nestjs/platform-express": "^10.0.0",
42
+ "@nestjs/swagger": "^7.3.1",
43
+ "bcrypt": "^5.1.1",
39
44
  "class-transformer": "^0.5.1",
40
45
  "class-validator": "^0.14.1",
41
46
  "nest-winston": "^1.10.0",