sim-node-lib 0.0.28 → 0.0.29

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,5 +1,5 @@
1
- import { PubSubActionEnum } from "../Enums/PubSubActionEnum";
2
- import { PubSubTableEnum } from "../Enums/PubSubTableEnum";
1
+ import { PubSubActionEnum } from '../Enums/PubSubActionEnum';
2
+ import { PubSubTableEnum } from '../Enums/PubSubTableEnum';
3
3
  export declare class GooglePubSubPublish {
4
4
  constructor(topicName: string);
5
5
  private _topicName;
@@ -1,5 +1,5 @@
1
1
  /// <reference types="node" />
2
- import { EventEmitter } from "events";
2
+ import { EventEmitter } from 'events';
3
3
  export declare class GooglePubSubSubscription {
4
4
  constructor(subscriptionName: string);
5
5
  private _subscription;
@@ -18,14 +18,14 @@ class GooglePubSubSubscription {
18
18
  }
19
19
  listenMessages(eventEmitter) {
20
20
  return __awaiter(this, void 0, void 0, function* () {
21
- this._subscription.on("message", (message) => {
21
+ this._subscription.on('message', (message) => {
22
22
  const data = JSON.parse(message.data.toString());
23
23
  const pubSubModel = new PubSubModel_1.PubSubModel(data.value, data.action, data.table);
24
- eventEmitter.emit("event", [pubSubModel, message]);
24
+ eventEmitter.emit('event', [pubSubModel, message]);
25
25
  });
26
- this._subscription.on("error", (error) => {
27
- console.error("Received error:", error);
28
- eventEmitter.emit("error", error);
26
+ this._subscription.on('error', (error) => {
27
+ console.error('Received error:', error);
28
+ eventEmitter.emit('error', error);
29
29
  });
30
30
  });
31
31
  }
@@ -1,4 +1,4 @@
1
- import { PubSubModel } from "./../Models/PubSubModel";
1
+ import { PubSubModel } from './../Models/PubSubModel';
2
2
  export declare abstract class PubSubHandlerAction {
3
3
  constructor(pubsubModel: PubSubModel);
4
4
  protected _pubsubValueModel: PubSubModel;
@@ -17,15 +17,15 @@ class PubSubHandlerAction {
17
17
  handlerAction() {
18
18
  return __awaiter(this, void 0, void 0, function* () {
19
19
  switch (this._pubsubValueModel.action) {
20
- case "insert":
20
+ case 'insert':
21
21
  return yield this.insert();
22
- case "insert_many":
22
+ case 'insert_many':
23
23
  return yield this.insertMany();
24
- case "update":
24
+ case 'update':
25
25
  return yield this.update();
26
- case "update_many":
26
+ case 'update_many':
27
27
  return yield this.updateMany();
28
- case "delete":
28
+ case 'delete':
29
29
  return yield this.delete();
30
30
  default:
31
31
  return true;
@@ -33,22 +33,22 @@ class PubSubHandlerAction {
33
33
  });
34
34
  }
35
35
  insert() {
36
- throw new Error("Method insert PubSub handler action not implemented.");
36
+ throw new Error('Method insert PubSub handler action not implemented.');
37
37
  }
38
38
  insertMany() {
39
- throw new Error("Method insert PubSub handler action not implemented.");
39
+ throw new Error('Method insert PubSub handler action not implemented.');
40
40
  }
41
41
  update() {
42
- throw new Error("Method update PubSub handler action not implemented.");
42
+ throw new Error('Method update PubSub handler action not implemented.');
43
43
  }
44
44
  updateMany() {
45
- throw new Error("Method update PubSub handler action not implemented.");
45
+ throw new Error('Method update PubSub handler action not implemented.');
46
46
  }
47
47
  delete() {
48
- throw new Error("Method delete PubSub handler action not implemented.");
48
+ throw new Error('Method delete PubSub handler action not implemented.');
49
49
  }
50
50
  buildData() {
51
- throw new Error("Method buildData PubSub handler action not implemented.");
51
+ throw new Error('Method buildData PubSub handler action not implemented.');
52
52
  }
53
53
  }
54
54
  exports.PubSubHandlerAction = PubSubHandlerAction;
@@ -0,0 +1,4 @@
1
+ export declare class CryptHelper {
2
+ static encrypt(mensagem: string): string;
3
+ static decrypt(mensagem: string): string;
4
+ }
@@ -0,0 +1,19 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.CryptHelper = void 0;
4
+ const crypto = require('crypto');
5
+ const alg = 'aes-256-ctr';
6
+ const pwd = 'Macaco';
7
+ class CryptHelper {
8
+ static encrypt(mensagem) {
9
+ const cipher = crypto.createCipher(alg, pwd);
10
+ const crypted = cipher.update(mensagem, 'utf8', 'hex');
11
+ return crypted;
12
+ }
13
+ static decrypt(mensagem) {
14
+ const decipher = crypto.createDecipher(alg, pwd);
15
+ const plain = decipher.update(mensagem, 'hex', 'utf8');
16
+ return plain;
17
+ }
18
+ }
19
+ exports.CryptHelper = CryptHelper;
@@ -0,0 +1,3 @@
1
+ export declare class HashUtil {
2
+ static criarHash(forceUppercase: boolean, length: number): string;
3
+ }
@@ -0,0 +1,10 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.HashUtil = void 0;
4
+ class HashUtil {
5
+ static criarHash(forceUppercase, length) {
6
+ const keygen = require('keygenerator');
7
+ return keygen._({ forceUppercase: forceUppercase, length: length });
8
+ }
9
+ }
10
+ exports.HashUtil = HashUtil;
@@ -0,0 +1,5 @@
1
+ export declare class NumberHelper {
2
+ static convertBase(num: number, baseFrom: number, baseTo: number): string;
3
+ static convertBase10to36(num: number): string;
4
+ static convertBase10to36WithZeroFill(num: number, size: number): string;
5
+ }
@@ -0,0 +1,15 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.NumberHelper = void 0;
4
+ class NumberHelper {
5
+ static convertBase(num, baseFrom, baseTo) {
6
+ return parseInt(num.toString(), baseFrom).toString(baseTo).toUpperCase();
7
+ }
8
+ static convertBase10to36(num) {
9
+ return parseInt(num.toString(), 10).toString(36).toUpperCase();
10
+ }
11
+ static convertBase10to36WithZeroFill(num, size) {
12
+ return this.convertBase10to36(num).padStart(size, '0');
13
+ }
14
+ }
15
+ exports.NumberHelper = NumberHelper;
@@ -0,0 +1,3 @@
1
+ export declare class PromiseUtil {
2
+ static PromiseHelper(ms?: number): Promise<unknown>;
3
+ }
@@ -0,0 +1,14 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.PromiseUtil = void 0;
4
+ class PromiseUtil {
5
+ static PromiseHelper(ms = Number(process.env.REQUEST_TIMEOUT)) {
6
+ return new Promise((reject) => {
7
+ const id = setTimeout(() => {
8
+ clearTimeout(id);
9
+ reject('Timeout in ' + ms + ' ms');
10
+ }, ms);
11
+ });
12
+ }
13
+ }
14
+ exports.PromiseUtil = PromiseUtil;
@@ -0,0 +1,5 @@
1
+ export declare class StringHelper {
2
+ static removeSpecialCharactersFromString(str: string): string;
3
+ static convertBooleanToString(string: string): Boolean;
4
+ static camelToSnakeCase(string: string): string;
5
+ }
@@ -0,0 +1,27 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.StringHelper = void 0;
4
+ class StringHelper {
5
+ static removeSpecialCharactersFromString(str) {
6
+ return str.normalize('NFD').replace(/[\u0300-\u036f]/g, '');
7
+ }
8
+ static convertBooleanToString(string) {
9
+ switch (string.toLowerCase().trim()) {
10
+ case 'true':
11
+ case 'yes':
12
+ case '1':
13
+ return true;
14
+ case 'false':
15
+ case 'no':
16
+ case '0':
17
+ case null:
18
+ return false;
19
+ default:
20
+ return Boolean(string);
21
+ }
22
+ }
23
+ static camelToSnakeCase(string) {
24
+ return string.replace(/([A-Z])/g, (char) => `_${char.toLowerCase()}`);
25
+ }
26
+ }
27
+ exports.StringHelper = StringHelper;
@@ -1,5 +1,5 @@
1
- import { PubSubActionEnum } from "../Enums/PubSubActionEnum";
2
- import { PubSubTableEnum } from "../Enums/PubSubTableEnum";
1
+ import { PubSubActionEnum } from '../Enums/PubSubActionEnum';
2
+ import { PubSubTableEnum } from '../Enums/PubSubTableEnum';
3
3
  export declare class PubSubModel {
4
4
  readonly value: any;
5
5
  readonly action: PubSubActionEnum;
@@ -0,0 +1,5 @@
1
+ export declare class NumberUtil {
2
+ static convertBase(num: number, baseFrom: number, baseTo: number): string;
3
+ static convertBase10to36(num: number): string;
4
+ static convertBase10to36WithZeroFill(num: number, size: number): string;
5
+ }
@@ -0,0 +1,15 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.NumberUtil = void 0;
4
+ class NumberUtil {
5
+ static convertBase(num, baseFrom, baseTo) {
6
+ return parseInt(num.toString(), baseFrom).toString(baseTo).toUpperCase();
7
+ }
8
+ static convertBase10to36(num) {
9
+ return parseInt(num.toString(), 10).toString(36).toUpperCase();
10
+ }
11
+ static convertBase10to36WithZeroFill(num, size) {
12
+ return this.convertBase10to36(num).padStart(size, "0");
13
+ }
14
+ }
15
+ exports.NumberUtil = NumberUtil;
@@ -0,0 +1,4 @@
1
+ export declare class StringUtil {
2
+ static removeSpecialCharactersFromString(str: string): string;
3
+ static convertBooleanToString(string: string): boolean;
4
+ }
@@ -0,0 +1,24 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.StringUtil = void 0;
4
+ class StringUtil {
5
+ static removeSpecialCharactersFromString(str) {
6
+ return str.normalize("NFD").replace(/[\u0300-\u036f]/g, "");
7
+ }
8
+ static convertBooleanToString(string) {
9
+ switch (string.toLowerCase().trim()) {
10
+ case "true":
11
+ case "yes":
12
+ case "1":
13
+ return true;
14
+ case "false":
15
+ case "no":
16
+ case "0":
17
+ case null:
18
+ return false;
19
+ default:
20
+ return Boolean(string);
21
+ }
22
+ }
23
+ }
24
+ exports.StringUtil = StringUtil;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "sim-node-lib",
3
- "version": "0.0.28",
3
+ "version": "0.0.29",
4
4
  "description": "Library from SIMLabs",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",
@@ -10,7 +10,8 @@
10
10
  "license": "ISC",
11
11
  "dependencies": {
12
12
  "@google-cloud/pubsub": "^3.0.1",
13
- "dotenv": "^16.0.1"
13
+ "dotenv": "^16.0.1",
14
+ "keygenerator": "^1.0.4"
14
15
  },
15
16
  "devDependencies": {
16
17
  "@types/node": "^17.0.41",