sim-node-lib 0.0.29 → 0.0.32

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.
@@ -9,7 +9,6 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
9
9
  });
10
10
  };
11
11
  Object.defineProperty(exports, "__esModule", { value: true });
12
- exports.GooglePubSubPublish = void 0;
13
12
  const pubsub_1 = require("@google-cloud/pubsub");
14
13
  const PubSubModel_1 = require("../Models/PubSubModel");
15
14
  class GooglePubSubPublish {
@@ -9,7 +9,6 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
9
9
  });
10
10
  };
11
11
  Object.defineProperty(exports, "__esModule", { value: true });
12
- exports.GooglePubSubSubscription = void 0;
13
12
  const pubsub_1 = require("@google-cloud/pubsub");
14
13
  const PubSubModel_1 = require("../Models/PubSubModel");
15
14
  class GooglePubSubSubscription {
@@ -1,6 +1,5 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.PubSubActionEnum = void 0;
4
3
  var PubSubActionEnum;
5
4
  (function (PubSubActionEnum) {
6
5
  PubSubActionEnum["insert"] = "insert";
@@ -19,6 +19,7 @@ export declare enum PubSubTableEnum {
19
19
  promocaoItem = "promocao_item",
20
20
  promocaoRecorrencia = "promocao_recorrencia",
21
21
  promocaoTag = "promocao_tag",
22
+ rede = "rede",
22
23
  servico = "servico",
23
24
  tag = "tag",
24
25
  voucherDesconto = "voucher_desconto",
@@ -1,6 +1,5 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.PubSubTableEnum = void 0;
4
3
  var PubSubTableEnum;
5
4
  (function (PubSubTableEnum) {
6
5
  PubSubTableEnum["bandeira"] = "bandeira";
@@ -23,6 +22,7 @@ var PubSubTableEnum;
23
22
  PubSubTableEnum["promocaoItem"] = "promocao_item";
24
23
  PubSubTableEnum["promocaoRecorrencia"] = "promocao_recorrencia";
25
24
  PubSubTableEnum["promocaoTag"] = "promocao_tag";
25
+ PubSubTableEnum["rede"] = "rede";
26
26
  PubSubTableEnum["servico"] = "servico";
27
27
  PubSubTableEnum["tag"] = "tag";
28
28
  PubSubTableEnum["voucherDesconto"] = "voucher_desconto";
@@ -9,7 +9,6 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
9
9
  });
10
10
  };
11
11
  Object.defineProperty(exports, "__esModule", { value: true });
12
- exports.PubSubHandlerAction = void 0;
13
12
  class PubSubHandlerAction {
14
13
  constructor(pubsubModel) {
15
14
  this._pubsubValueModel = pubsubModel;
@@ -1,6 +1,5 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.CryptHelper = void 0;
4
3
  const crypto = require('crypto');
5
4
  const alg = 'aes-256-ctr';
6
5
  const pwd = 'Macaco';
@@ -1,3 +1,3 @@
1
- export declare class HashUtil {
1
+ export declare class HashHelper {
2
2
  static criarHash(forceUppercase: boolean, length: number): string;
3
3
  }
@@ -1,10 +1,9 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.HashUtil = void 0;
4
- class HashUtil {
3
+ class HashHelper {
5
4
  static criarHash(forceUppercase, length) {
6
5
  const keygen = require('keygenerator');
7
6
  return keygen._({ forceUppercase: forceUppercase, length: length });
8
7
  }
9
8
  }
10
- exports.HashUtil = HashUtil;
9
+ exports.HashHelper = HashHelper;
@@ -1,6 +1,5 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.NumberHelper = void 0;
4
3
  class NumberHelper {
5
4
  static convertBase(num, baseFrom, baseTo) {
6
5
  return parseInt(num.toString(), baseFrom).toString(baseTo).toUpperCase();
@@ -1,6 +1,5 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.PromiseUtil = void 0;
4
3
  class PromiseUtil {
5
4
  static PromiseHelper(ms = Number(process.env.REQUEST_TIMEOUT)) {
6
5
  return new Promise((reject) => {
@@ -1,6 +1,5 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.StringHelper = void 0;
4
3
  class StringHelper {
5
4
  static removeSpecialCharactersFromString(str) {
6
5
  return str.normalize('NFD').replace(/[\u0300-\u036f]/g, '');
@@ -1,6 +1,5 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.PubSubModel = void 0;
4
3
  class PubSubModel {
5
4
  constructor(value, action, table) {
6
5
  this.value = value;
@@ -0,0 +1,32 @@
1
+ /// <reference types="node" />
2
+ import { EventEmitter } from 'events';
3
+ export declare class PubSubModel {
4
+ readonly value: object;
5
+ readonly action: string;
6
+ readonly table: string;
7
+ constructor(value: object, action: PubSubActionEnum, table: string);
8
+ }
9
+ export declare class GooglePubSubSubscription {
10
+ constructor(subscriptionName: string);
11
+ private _subscription;
12
+ listenMessages(eventEmitter: EventEmitter): Promise<void>;
13
+ }
14
+ export declare class GooglePubSubPublish {
15
+ constructor(topicName: string);
16
+ private _topicName;
17
+ createMessages(message: object, action: PubSubActionEnum, table: string): Promise<void>;
18
+ }
19
+ export declare abstract class PubSubHandelerAction {
20
+ constructor(pubsubModel: PubSubModel);
21
+ protected _pubsubValueModel: any;
22
+ protected handlerAction(action: string): void;
23
+ protected insert(): void;
24
+ protected update(): void;
25
+ protected remove(): void;
26
+ protected buildData(): Object;
27
+ }
28
+ export declare enum PubSubActionEnum {
29
+ insert = "insert",
30
+ update = "update",
31
+ remove = "remove"
32
+ }
@@ -0,0 +1,107 @@
1
+ "use strict";
2
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
+ return new (P || (P = Promise))(function (resolve, reject) {
5
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
9
+ });
10
+ };
11
+ Object.defineProperty(exports, "__esModule", { value: true });
12
+ const pubsub_1 = require("@google-cloud/pubsub");
13
+ class PubSubModel {
14
+ constructor(value, action, table) {
15
+ this.value = value;
16
+ this.action = action.toString();
17
+ this.table = table;
18
+ }
19
+ }
20
+ exports.PubSubModel = PubSubModel;
21
+ class GooglePubSubSubscription {
22
+ constructor(subscriptionName) {
23
+ this._subscription = new pubsub_1.PubSub().subscription(subscriptionName);
24
+ }
25
+ listenMessages(eventEmitter) {
26
+ return __awaiter(this, void 0, void 0, function* () {
27
+ this._subscription.on('message', (message) => {
28
+ try {
29
+ const data = JSON.parse(message.data.toString());
30
+ const pubSubModel = new PubSubModel(data.value, data.action, data.table);
31
+ eventEmitter.emit('event', [pubSubModel, message]);
32
+ }
33
+ catch (error) {
34
+ console.error(error);
35
+ throw Error(error);
36
+ }
37
+ });
38
+ // Receive callbacks for errors on the subscription
39
+ this._subscription.on('error', (error) => {
40
+ console.error('Received error:', error);
41
+ throw Error(error);
42
+ });
43
+ });
44
+ }
45
+ }
46
+ exports.GooglePubSubSubscription = GooglePubSubSubscription;
47
+ class GooglePubSubPublish {
48
+ constructor(topicName) {
49
+ this._topicName = topicName;
50
+ }
51
+ createMessages(message, action, table) {
52
+ return __awaiter(this, void 0, void 0, function* () {
53
+ const pubSubClient = new pubsub_1.PubSub();
54
+ const send = new PubSubModel(message, action, table);
55
+ // Creates a new topic
56
+ const topic = pubSubClient.topic(this._topicName);
57
+ console.log(`Topic ${topic.name} created.`);
58
+ const dataSend = JSON.stringify(send);
59
+ //Create message
60
+ const data = Buffer.from(dataSend);
61
+ // Send a message to the topic
62
+ yield topic.publishMessage({ data });
63
+ });
64
+ }
65
+ }
66
+ exports.GooglePubSubPublish = GooglePubSubPublish;
67
+ class PubSubHandelerAction {
68
+ constructor(pubsubModel) {
69
+ this._pubsubValueModel = pubsubModel.value;
70
+ this.handlerAction(pubsubModel.action);
71
+ }
72
+ handlerAction(action) {
73
+ switch (action) {
74
+ case 'insert':
75
+ this.insert();
76
+ break;
77
+ case 'update':
78
+ this.update();
79
+ break;
80
+ case 'delete':
81
+ this.remove();
82
+ break;
83
+ default:
84
+ this.insert();
85
+ //throw new Error('PubSub handler action not implemented.')
86
+ }
87
+ }
88
+ insert() {
89
+ throw new Error('Method insert PubSub handler action not implemented.');
90
+ }
91
+ update() {
92
+ throw new Error('Method update PubSub handler action not implemented.');
93
+ }
94
+ remove() {
95
+ throw new Error('Method remove PubSub handler action not implemented.');
96
+ }
97
+ buildData() {
98
+ throw new Error('Method buildData PubSub handler action not implemented.');
99
+ }
100
+ }
101
+ exports.PubSubHandelerAction = PubSubHandelerAction;
102
+ var PubSubActionEnum;
103
+ (function (PubSubActionEnum) {
104
+ PubSubActionEnum["insert"] = "insert";
105
+ PubSubActionEnum["update"] = "update";
106
+ PubSubActionEnum["remove"] = "remove";
107
+ })(PubSubActionEnum = exports.PubSubActionEnum || (exports.PubSubActionEnum = {}));
@@ -1,6 +1,5 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.sayGoodbye = exports.sayHello = void 0;
4
3
  require("dotenv").config();
5
4
  function sayHello() {
6
5
  console.log("hi my friend, the NODE PORT is: ", process.env.PORT);
package/dist/index.js CHANGED
@@ -1,9 +1,8 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.GooglePubSubPublish = exports.GooglePubSubSubscription = exports.PubSubHandlerAction = void 0;
4
3
  var PubSubHandlerAction_1 = require("./Handlers/PubSubHandlerAction");
5
- Object.defineProperty(exports, "PubSubHandlerAction", { enumerable: true, get: function () { return PubSubHandlerAction_1.PubSubHandlerAction; } });
4
+ exports.PubSubHandlerAction = PubSubHandlerAction_1.PubSubHandlerAction;
6
5
  var GooglePubSubSubscription_1 = require("./Class/GooglePubSubSubscription");
7
- Object.defineProperty(exports, "GooglePubSubSubscription", { enumerable: true, get: function () { return GooglePubSubSubscription_1.GooglePubSubSubscription; } });
6
+ exports.GooglePubSubSubscription = GooglePubSubSubscription_1.GooglePubSubSubscription;
8
7
  var GooglePubSubPublish_1 = require("./Class/GooglePubSubPublish");
9
- Object.defineProperty(exports, "GooglePubSubPublish", { enumerable: true, get: function () { return GooglePubSubPublish_1.GooglePubSubPublish; } });
8
+ exports.GooglePubSubPublish = GooglePubSubPublish_1.GooglePubSubPublish;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "sim-node-lib",
3
- "version": "0.0.29",
3
+ "version": "0.0.32",
4
4
  "description": "Library from SIMLabs",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",
@@ -10,6 +10,7 @@
10
10
  "license": "ISC",
11
11
  "dependencies": {
12
12
  "@google-cloud/pubsub": "^3.0.1",
13
+ "crypto": "^1.0.1",
13
14
  "dotenv": "^16.0.1",
14
15
  "keygenerator": "^1.0.4"
15
16
  },
@@ -1,5 +0,0 @@
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
- }
@@ -1,15 +0,0 @@
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;
@@ -1,4 +0,0 @@
1
- export declare class StringUtil {
2
- static removeSpecialCharactersFromString(str: string): string;
3
- static convertBooleanToString(string: string): boolean;
4
- }
@@ -1,24 +0,0 @@
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;