@liberstudio/cloudflare-list 2.2.5 → 2.2.7

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/README.md CHANGED
@@ -36,6 +36,7 @@ import { CloudflareAttacksModule } from "@liberstudio/cloudflare-list";
36
36
  comment: "<comment>",
37
37
  logPath: "<logPath>",
38
38
  excludedPaths: "<excludedList>",
39
+ silentPaths: "<silentList>",
39
40
  }),
40
41
  ],
41
42
  })
@@ -59,6 +60,7 @@ import { CloudflareAttacksModule } from "@liberstudio/cloudflare-list";
59
60
  comment: config.get<string>("CLOUDFLARE_LIST_COMMENT") || "Blocked",
60
61
  logPath: config.get<string>("CLOUDFLARE_LIST_LOG_PATH") || "/var/log/nestjs-attacks.log",
61
62
  excludedPaths: ["/api/health", "/api/webhook", /^\/api\/public\/.*/],
63
+ silentPaths: ["/auth/me", "/auth/refresh"],
62
64
  }),
63
65
  }),
64
66
  ],
@@ -59,7 +59,8 @@ exports.CloudflareAttacksModule = CloudflareAttacksModule = CloudflareAttacksMod
59
59
  middleware_1.AttackLoggerMiddleware,
60
60
  {
61
61
  provide: core_1.APP_FILTER,
62
- useClass: filters_1.AllExceptionsFilter,
62
+ useFactory: (options) => new filters_1.AllExceptionsFilter(options),
63
+ inject: [{ token: utils_1.CLOUDFLARE_OPTIONS, optional: true }],
63
64
  },
64
65
  ],
65
66
  exports: [attacks_service_1.AttacksService, axios_1.HttpModule],
@@ -1,5 +1,8 @@
1
1
  import { ArgumentsHost, ExceptionFilter } from "@nestjs/common";
2
+ import type { CloudflareAttacksOptions } from "../interfaces";
2
3
  export declare class AllExceptionsFilter implements ExceptionFilter {
4
+ private readonly options?;
3
5
  private readonly logger;
6
+ constructor(options?: CloudflareAttacksOptions | undefined);
4
7
  catch(exception: unknown, host: ArgumentsHost): void;
5
8
  }
@@ -5,13 +5,21 @@ var __decorate = (this && this.__decorate) || function (decorators, target, key,
5
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
6
  return c > 3 && r && Object.defineProperty(target, key, r), r;
7
7
  };
8
+ var __metadata = (this && this.__metadata) || function (k, v) {
9
+ if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
10
+ };
11
+ var __param = (this && this.__param) || function (paramIndex, decorator) {
12
+ return function (target, key) { decorator(target, key, paramIndex); }
13
+ };
8
14
  var AllExceptionsFilter_1;
9
15
  Object.defineProperty(exports, "__esModule", { value: true });
10
16
  exports.AllExceptionsFilter = void 0;
11
17
  const common_1 = require("@nestjs/common");
12
18
  const get_client_ip_util_1 = require("../utils/get-client-ip.util");
19
+ const utils_1 = require("../utils");
13
20
  let AllExceptionsFilter = AllExceptionsFilter_1 = class AllExceptionsFilter {
14
- constructor() {
21
+ constructor(options) {
22
+ this.options = options;
15
23
  this.logger = new common_1.Logger(AllExceptionsFilter_1.name);
16
24
  }
17
25
  catch(exception, host) {
@@ -22,6 +30,7 @@ let AllExceptionsFilter = AllExceptionsFilter_1 = class AllExceptionsFilter {
22
30
  // if (request.url.startsWith("/auth")) {
23
31
  // return;
24
32
  // }
33
+ const isSilentPath = (this.options?.silentPaths ?? []).some((p) => p instanceof RegExp ? p.test(request.url) : request.url.startsWith(p));
25
34
  const status = exception instanceof common_1.HttpException ? exception.getStatus() : common_1.HttpStatus.INTERNAL_SERVER_ERROR;
26
35
  const message = exception instanceof common_1.HttpException ? exception.getResponse() : exception instanceof Error ? exception.message : "Internal server error";
27
36
  const ip = (0, get_client_ip_util_1.getClientIp)(request);
@@ -38,12 +47,14 @@ let AllExceptionsFilter = AllExceptionsFilter_1 = class AllExceptionsFilter {
38
47
  stack: exception instanceof Error ? exception.stack : undefined,
39
48
  };
40
49
  /* const isMissingToken = message === "Invalid or missing token"; */
41
- if (status >= 500) {
42
- this.logger.error(`[${ip}] [${request.method}] ${request.url} → ${status}`, JSON.stringify(errorLog, null, 2));
43
- }
44
- else {
45
- this.logger.error(`[${ip}] [${request.method}] ${request.url} → ${status}`);
46
- // this.logger.warn(`[${ip}] [${request.method}] ${request.url} → ${status}`, JSON.stringify(errorLog, null, 2));
50
+ if (!isSilentPath) {
51
+ if (status >= 500) {
52
+ this.logger.error(`[${ip}] [${request.method}] ${request.url} → ${status}`, JSON.stringify(errorLog, null, 2));
53
+ }
54
+ else {
55
+ // this.logger.error(`[${ip}] [${request.method}] ${request.url} → ${status}`);
56
+ this.logger.warn(`[${ip}] [${request.method}] ${request.url} → ${status}`, JSON.stringify(errorLog, null, 2));
57
+ }
47
58
  }
48
59
  response.status(status).json({
49
60
  statusCode: status,
@@ -55,5 +66,8 @@ let AllExceptionsFilter = AllExceptionsFilter_1 = class AllExceptionsFilter {
55
66
  };
56
67
  exports.AllExceptionsFilter = AllExceptionsFilter;
57
68
  exports.AllExceptionsFilter = AllExceptionsFilter = AllExceptionsFilter_1 = __decorate([
58
- (0, common_1.Catch)()
69
+ (0, common_1.Catch)(),
70
+ __param(0, (0, common_1.Optional)()),
71
+ __param(0, (0, common_1.Inject)(utils_1.CLOUDFLARE_OPTIONS)),
72
+ __metadata("design:paramtypes", [Object])
59
73
  ], AllExceptionsFilter);
@@ -5,6 +5,7 @@ export interface CloudflareAttacksOptions {
5
5
  comment: string;
6
6
  logPath: string;
7
7
  excludedPaths?: (string | RegExp)[];
8
+ silentPaths?: (string | RegExp)[];
8
9
  }
9
10
  export interface CloudflareAttacksAsyncOptions {
10
11
  imports?: any[];
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@liberstudio/cloudflare-list",
3
- "version": "2.2.5",
3
+ "version": "2.2.7",
4
4
  "description": "Modulo NestJS per gestione IP List Cloudflare",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",