@seidor-cloud-produtos/orbit-backend-lib 2.0.6 → 2.0.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.
@@ -1,4 +1,9 @@
1
+ export interface CacheClientOptions {
2
+ timeout?: number;
3
+ }
1
4
  export declare abstract class CacheClient {
5
+ protected connection?: CacheClientOptions | undefined;
6
+ constructor(connection?: CacheClientOptions | undefined);
2
7
  abstract start(): Promise<void>;
3
8
  abstract close(): Promise<void>;
4
9
  abstract get(keyCache: string): Promise<any>;
@@ -3,9 +3,13 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.CacheClient = void 0;
4
4
  const unique_entity_id_1 = require("../../domain/entities/unique-entity-id");
5
5
  class CacheClient {
6
+ connection;
7
+ constructor(connection) {
8
+ this.connection = connection;
9
+ }
6
10
  async isRunning() {
7
11
  const key = new unique_entity_id_1.UniqueEntityId().toValue();
8
- await this.set(key, JSON.stringify({ ping: true }), 60);
12
+ await this.set(key, JSON.stringify({ ping: true }), this.connection?.timeout || 60);
9
13
  const cachedData = await this.get(key);
10
14
  return cachedData?.ping || false;
11
15
  }
@@ -1,7 +1,6 @@
1
1
  import { RedisOptions as LibRedisOptions } from 'ioredis';
2
- import { CacheClient } from '../../../application/cache/client';
3
- export interface RedisOptions extends LibRedisOptions {
4
- timeout?: number;
2
+ import { CacheClient, CacheClientOptions } from '../../../application/cache/client';
3
+ export interface RedisOptions extends LibRedisOptions, CacheClientOptions {
5
4
  }
6
5
  export declare class Redis extends CacheClient {
7
6
  protected connection: RedisOptions;
@@ -8,11 +8,15 @@ class Redis extends client_1.CacheClient {
8
8
  connection;
9
9
  client;
10
10
  constructor(connection) {
11
- super();
11
+ super(connection);
12
12
  this.connection = connection;
13
13
  }
14
14
  async delayOperation() {
15
- await new Promise(resolve => setTimeout(resolve, this.connection.timeout || 2500));
15
+ let timeout = 2500;
16
+ if (this.connection.timeout) {
17
+ timeout = this.connection.timeout * 1000;
18
+ }
19
+ await new Promise(resolve => setTimeout(resolve, timeout || 2500));
16
20
  return null;
17
21
  }
18
22
  async start() {
@@ -0,0 +1,5 @@
1
+ export declare class Net {
2
+ isCurrentIPInIPWhiteList(whiteList: string[], ignoreInvalidIP?: boolean): Promise<boolean>;
3
+ getCurrentIP(): Promise<any>;
4
+ isIP(value: string): number;
5
+ }
@@ -0,0 +1,29 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.Net = void 0;
4
+ const tslib_1 = require("tslib");
5
+ const axios_1 = tslib_1.__importDefault(require("axios"));
6
+ const net_1 = tslib_1.__importDefault(require("net"));
7
+ class Net {
8
+ async isCurrentIPInIPWhiteList(whiteList, ignoreInvalidIP = false) {
9
+ const currentIP = await this.getCurrentIP();
10
+ if (!this.isIP(currentIP) && ignoreInvalidIP) {
11
+ return true;
12
+ }
13
+ return whiteList.includes(currentIP);
14
+ }
15
+ async getCurrentIP() {
16
+ try {
17
+ const response = await axios_1.default.get('https://checkip.amazonaws.com/');
18
+ return response.data.trim();
19
+ }
20
+ catch (e) {
21
+ console.log(e);
22
+ return 'invalid';
23
+ }
24
+ }
25
+ isIP(value) {
26
+ return net_1.default.isIP(value);
27
+ }
28
+ }
29
+ exports.Net = Net;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@seidor-cloud-produtos/orbit-backend-lib",
3
- "version": "2.0.6",
3
+ "version": "2.0.7",
4
4
  "description": "Internal lib for backend components",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",