@liberstudio/cloudflare-list 2.0.8 → 2.0.9

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.
@@ -1,10 +1,10 @@
1
1
  import { HttpService } from "@nestjs/axios";
2
- import type { CloudflareAttacksOptions } from "./interfaces";
2
+ import type { CloudflareAttacksOptions, CloudflareResponse } from "./interfaces";
3
3
  export declare class AttacksService {
4
4
  private readonly httpService;
5
5
  private readonly options;
6
6
  private readonly logger;
7
7
  private readonly API_URL;
8
8
  constructor(httpService: HttpService, options: CloudflareAttacksOptions);
9
- updateIpList(ip: string): Promise<any>;
9
+ updateIpList(ip: string): Promise<CloudflareResponse>;
10
10
  }
@@ -20,6 +20,7 @@ exports.AttacksService = void 0;
20
20
  const common_1 = require("@nestjs/common");
21
21
  const axios_1 = require("@nestjs/axios");
22
22
  const axios_2 = __importDefault(require("axios"));
23
+ const rxjs_1 = require("rxjs");
23
24
  let AttacksService = class AttacksService {
24
25
  constructor(httpService, options) {
25
26
  this.httpService = httpService;
@@ -28,22 +29,18 @@ let AttacksService = class AttacksService {
28
29
  this.API_URL = `https://api.cloudflare.com/client/v4/accounts`;
29
30
  }
30
31
  async updateIpList(ip) {
31
- const apiToken = this.options.apiToken.trim();
32
- const accountId = this.options.accountId.trim();
33
- const listId = this.options.listId.trim();
34
- const comment = this.options.comment || "Auto-blocked";
32
+ const { accountId, listId, apiToken, comment } = this.options;
35
33
  const url = `${this.API_URL}/${accountId}/rules/lists/${listId}/items`;
36
34
  this.logger.error(`Aggiungo IP ${ip} alla lista Cloudflare`);
37
35
  const formattedIp = ip.includes("/") ? ip : `${ip}/32`;
38
36
  const body = [{ ip: formattedIp, comment }];
39
37
  try {
40
- const response = await axios_2.default.post(url, body, {
38
+ const response = await (0, rxjs_1.firstValueFrom)(this.httpService.post(url, body, {
41
39
  headers: {
42
40
  Authorization: `Bearer ${apiToken}`,
43
41
  "Content-Type": "application/json",
44
- Accept: "application/json", // Aggiungi questo esplicitamente
45
42
  },
46
- });
43
+ }));
47
44
  return response.data;
48
45
  }
49
46
  catch (error) {
@@ -57,7 +57,7 @@ let AttackLoggerMiddleware = class AttackLoggerMiddleware {
57
57
  if (res.statusCode === 404) {
58
58
  this.processSuspiciousRequest(req).catch((err) => {
59
59
  const msg = err instanceof Error ? err.message : "Unknown error";
60
- this.logger.error(`Errore nel processando attacco: ${msg}`);
60
+ this.logger.error(`Errore nel processando la richiesta verso Cloudflare: ${msg}`);
61
61
  });
62
62
  }
63
63
  });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@liberstudio/cloudflare-list",
3
- "version": "2.0.8",
3
+ "version": "2.0.9",
4
4
  "description": "Modulo NestJS per gestione IP List Cloudflare",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",