sim-node-lib 0.0.31 → 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.
@@ -0,0 +1,7 @@
1
+ import { PubSubActionEnum } from '../Enums/PubSubActionEnum';
2
+ import { PubSubTableEnum } from '../Enums/PubSubTableEnum';
3
+ export declare class GooglePubSubPublish {
4
+ constructor(topicName: string);
5
+ private _topicName;
6
+ createMessages(message: object, action: PubSubActionEnum, table: PubSubTableEnum): Promise<void>;
7
+ }
@@ -0,0 +1,29 @@
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
+ const PubSubModel_1 = require("../Models/PubSubModel");
14
+ class GooglePubSubPublish {
15
+ constructor(topicName) {
16
+ this._topicName = topicName;
17
+ }
18
+ createMessages(message, action, table) {
19
+ return __awaiter(this, void 0, void 0, function* () {
20
+ const pubSubClient = new pubsub_1.PubSub();
21
+ const send = new PubSubModel_1.PubSubModel(message, action, table);
22
+ const topic = pubSubClient.topic(this._topicName);
23
+ const dataSend = JSON.stringify(send);
24
+ const data = Buffer.from(dataSend);
25
+ yield topic.publishMessage({ data });
26
+ });
27
+ }
28
+ }
29
+ exports.GooglePubSubPublish = GooglePubSubPublish;
@@ -0,0 +1,7 @@
1
+ /// <reference types="node" />
2
+ import { EventEmitter } from 'events';
3
+ export declare class GooglePubSubSubscription {
4
+ constructor(subscriptionName: string);
5
+ private _subscription;
6
+ listenMessages(eventEmitter: EventEmitter): Promise<void>;
7
+ }
@@ -0,0 +1,32 @@
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
+ const PubSubModel_1 = require("../Models/PubSubModel");
14
+ class GooglePubSubSubscription {
15
+ constructor(subscriptionName) {
16
+ this._subscription = new pubsub_1.PubSub().subscription(subscriptionName);
17
+ }
18
+ listenMessages(eventEmitter) {
19
+ return __awaiter(this, void 0, void 0, function* () {
20
+ this._subscription.on('message', (message) => {
21
+ const data = JSON.parse(message.data.toString());
22
+ const pubSubModel = new PubSubModel_1.PubSubModel(data.value, data.action, data.table);
23
+ eventEmitter.emit('event', [pubSubModel, message]);
24
+ });
25
+ this._subscription.on('error', (error) => {
26
+ console.error('Received error:', error);
27
+ eventEmitter.emit('error', error);
28
+ });
29
+ });
30
+ }
31
+ }
32
+ exports.GooglePubSubSubscription = GooglePubSubSubscription;
@@ -0,0 +1,7 @@
1
+ export declare enum PubSubActionEnum {
2
+ insert = "insert",
3
+ insertMany = "insert_many",
4
+ update = "update",
5
+ updateMany = "update_many",
6
+ delete = "delete"
7
+ }
@@ -0,0 +1,10 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ var PubSubActionEnum;
4
+ (function (PubSubActionEnum) {
5
+ PubSubActionEnum["insert"] = "insert";
6
+ PubSubActionEnum["insertMany"] = "insert_many";
7
+ PubSubActionEnum["update"] = "update";
8
+ PubSubActionEnum["updateMany"] = "update_many";
9
+ PubSubActionEnum["delete"] = "delete";
10
+ })(PubSubActionEnum = exports.PubSubActionEnum || (exports.PubSubActionEnum = {}));
@@ -0,0 +1,29 @@
1
+ export declare enum PubSubTableEnum {
2
+ bandeira = "bandeira",
3
+ cliente = "cliente",
4
+ clienteEndereco = "cliente_endereco",
5
+ clientePendente = "cliente_pendente",
6
+ configuracao = "configuracao",
7
+ empresa = "empresa",
8
+ empresaHorario = "empresa_horario",
9
+ empresaServico = "empresa_servico",
10
+ grupoDesconto = "grupo_desconto",
11
+ grupoDescontoLimite = "grupo_desconto_limite",
12
+ grupoPromocao = "grupo_promocao",
13
+ grupoEmpresa = "grupo_empresa",
14
+ item = "item",
15
+ itemTag = "item_tag",
16
+ promocao = "promocao",
17
+ promocaoEmpresa = "promocao_empresa",
18
+ promocaoGrupoDesconto = "promocao_grupo_desconto",
19
+ promocaoItem = "promocao_item",
20
+ promocaoRecorrencia = "promocao_recorrencia",
21
+ promocaoTag = "promocao_tag",
22
+ rede = "rede",
23
+ servico = "servico",
24
+ tag = "tag",
25
+ voucherDesconto = "voucher_desconto",
26
+ voucherDescontoLote = "voucher_desconto_lote",
27
+ voucherMigracao = "voucher_migracao",
28
+ voucherMigracaoLote = "voucher_migracao_lote"
29
+ }
@@ -0,0 +1,32 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ var PubSubTableEnum;
4
+ (function (PubSubTableEnum) {
5
+ PubSubTableEnum["bandeira"] = "bandeira";
6
+ PubSubTableEnum["cliente"] = "cliente";
7
+ PubSubTableEnum["clienteEndereco"] = "cliente_endereco";
8
+ PubSubTableEnum["clientePendente"] = "cliente_pendente";
9
+ PubSubTableEnum["configuracao"] = "configuracao";
10
+ PubSubTableEnum["empresa"] = "empresa";
11
+ PubSubTableEnum["empresaHorario"] = "empresa_horario";
12
+ PubSubTableEnum["empresaServico"] = "empresa_servico";
13
+ PubSubTableEnum["grupoDesconto"] = "grupo_desconto";
14
+ PubSubTableEnum["grupoDescontoLimite"] = "grupo_desconto_limite";
15
+ PubSubTableEnum["grupoPromocao"] = "grupo_promocao";
16
+ PubSubTableEnum["grupoEmpresa"] = "grupo_empresa";
17
+ PubSubTableEnum["item"] = "item";
18
+ PubSubTableEnum["itemTag"] = "item_tag";
19
+ PubSubTableEnum["promocao"] = "promocao";
20
+ PubSubTableEnum["promocaoEmpresa"] = "promocao_empresa";
21
+ PubSubTableEnum["promocaoGrupoDesconto"] = "promocao_grupo_desconto";
22
+ PubSubTableEnum["promocaoItem"] = "promocao_item";
23
+ PubSubTableEnum["promocaoRecorrencia"] = "promocao_recorrencia";
24
+ PubSubTableEnum["promocaoTag"] = "promocao_tag";
25
+ PubSubTableEnum["rede"] = "rede";
26
+ PubSubTableEnum["servico"] = "servico";
27
+ PubSubTableEnum["tag"] = "tag";
28
+ PubSubTableEnum["voucherDesconto"] = "voucher_desconto";
29
+ PubSubTableEnum["voucherDescontoLote"] = "voucher_desconto_lote";
30
+ PubSubTableEnum["voucherMigracao"] = "voucher_migracao";
31
+ PubSubTableEnum["voucherMigracaoLote"] = "voucher_migracao_lote";
32
+ })(PubSubTableEnum = exports.PubSubTableEnum || (exports.PubSubTableEnum = {}));
@@ -0,0 +1,12 @@
1
+ import { PubSubModel } from './../Models/PubSubModel';
2
+ export declare abstract class PubSubHandlerAction {
3
+ constructor(pubsubModel: PubSubModel);
4
+ protected _pubsubValueModel: PubSubModel;
5
+ handlerAction(): Promise<boolean>;
6
+ protected insert(): Promise<boolean>;
7
+ protected insertMany(): Promise<boolean>;
8
+ protected update(): Promise<boolean>;
9
+ protected updateMany(): Promise<boolean>;
10
+ protected delete(): Promise<boolean>;
11
+ protected buildData(): Object;
12
+ }
@@ -0,0 +1,53 @@
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
+ class PubSubHandlerAction {
13
+ constructor(pubsubModel) {
14
+ this._pubsubValueModel = pubsubModel;
15
+ }
16
+ handlerAction() {
17
+ return __awaiter(this, void 0, void 0, function* () {
18
+ switch (this._pubsubValueModel.action) {
19
+ case 'insert':
20
+ return yield this.insert();
21
+ case 'insert_many':
22
+ return yield this.insertMany();
23
+ case 'update':
24
+ return yield this.update();
25
+ case 'update_many':
26
+ return yield this.updateMany();
27
+ case 'delete':
28
+ return yield this.delete();
29
+ default:
30
+ return true;
31
+ }
32
+ });
33
+ }
34
+ insert() {
35
+ throw new Error('Method insert PubSub handler action not implemented.');
36
+ }
37
+ insertMany() {
38
+ throw new Error('Method insert PubSub handler action not implemented.');
39
+ }
40
+ update() {
41
+ throw new Error('Method update PubSub handler action not implemented.');
42
+ }
43
+ updateMany() {
44
+ throw new Error('Method update PubSub handler action not implemented.');
45
+ }
46
+ delete() {
47
+ throw new Error('Method delete PubSub handler action not implemented.');
48
+ }
49
+ buildData() {
50
+ throw new Error('Method buildData PubSub handler action not implemented.');
51
+ }
52
+ }
53
+ 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,18 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const crypto = require('crypto');
4
+ const alg = 'aes-256-ctr';
5
+ const pwd = 'Macaco';
6
+ class CryptHelper {
7
+ static encrypt(mensagem) {
8
+ const cipher = crypto.createCipher(alg, pwd);
9
+ const crypted = cipher.update(mensagem, 'utf8', 'hex');
10
+ return crypted;
11
+ }
12
+ static decrypt(mensagem) {
13
+ const decipher = crypto.createDecipher(alg, pwd);
14
+ const plain = decipher.update(mensagem, 'hex', 'utf8');
15
+ return plain;
16
+ }
17
+ }
18
+ exports.CryptHelper = CryptHelper;
@@ -0,0 +1,3 @@
1
+ export declare class HashHelper {
2
+ static criarHash(forceUppercase: boolean, length: number): string;
3
+ }
@@ -0,0 +1,9 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ class HashHelper {
4
+ static criarHash(forceUppercase, length) {
5
+ const keygen = require('keygenerator');
6
+ return keygen._({ forceUppercase: forceUppercase, length: length });
7
+ }
8
+ }
9
+ exports.HashHelper = HashHelper;
@@ -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,14 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ class NumberHelper {
4
+ static convertBase(num, baseFrom, baseTo) {
5
+ return parseInt(num.toString(), baseFrom).toString(baseTo).toUpperCase();
6
+ }
7
+ static convertBase10to36(num) {
8
+ return parseInt(num.toString(), 10).toString(36).toUpperCase();
9
+ }
10
+ static convertBase10to36WithZeroFill(num, size) {
11
+ return this.convertBase10to36(num).padStart(size, '0');
12
+ }
13
+ }
14
+ exports.NumberHelper = NumberHelper;
@@ -0,0 +1,3 @@
1
+ export declare class PromiseUtil {
2
+ static PromiseHelper(ms?: number): Promise<unknown>;
3
+ }
@@ -0,0 +1,13 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ class PromiseUtil {
4
+ static PromiseHelper(ms = Number(process.env.REQUEST_TIMEOUT)) {
5
+ return new Promise((reject) => {
6
+ const id = setTimeout(() => {
7
+ clearTimeout(id);
8
+ reject('Timeout in ' + ms + ' ms');
9
+ }, ms);
10
+ });
11
+ }
12
+ }
13
+ 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,26 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ class StringHelper {
4
+ static removeSpecialCharactersFromString(str) {
5
+ return str.normalize('NFD').replace(/[\u0300-\u036f]/g, '');
6
+ }
7
+ static convertBooleanToString(string) {
8
+ switch (string.toLowerCase().trim()) {
9
+ case 'true':
10
+ case 'yes':
11
+ case '1':
12
+ return true;
13
+ case 'false':
14
+ case 'no':
15
+ case '0':
16
+ case null:
17
+ return false;
18
+ default:
19
+ return Boolean(string);
20
+ }
21
+ }
22
+ static camelToSnakeCase(string) {
23
+ return string.replace(/([A-Z])/g, (char) => `_${char.toLowerCase()}`);
24
+ }
25
+ }
26
+ exports.StringHelper = StringHelper;
@@ -0,0 +1,8 @@
1
+ import { PubSubActionEnum } from '../Enums/PubSubActionEnum';
2
+ import { PubSubTableEnum } from '../Enums/PubSubTableEnum';
3
+ export declare class PubSubModel {
4
+ readonly value: any;
5
+ readonly action: PubSubActionEnum;
6
+ readonly table: PubSubTableEnum;
7
+ constructor(value: object, action: PubSubActionEnum, table: PubSubTableEnum);
8
+ }
@@ -0,0 +1,10 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ class PubSubModel {
4
+ constructor(value, action, table) {
5
+ this.value = value;
6
+ this.action = action;
7
+ this.table = table;
8
+ }
9
+ }
10
+ exports.PubSubModel = PubSubModel;
package/dist/index.d.ts CHANGED
@@ -1,2 +1,3 @@
1
- export { sayHello, sayGoodbye } from "./hello-world";
2
- export { GooglePubSubSubscription, GooglePubSubPublish } from "./google-pub-sub";
1
+ export { PubSubHandlerAction } from "./Handlers/PubSubHandlerAction";
2
+ export { GooglePubSubSubscription } from "./Class/GooglePubSubSubscription";
3
+ export { GooglePubSubPublish } from "./Class/GooglePubSubPublish";
package/dist/index.js CHANGED
@@ -1,8 +1,8 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- var hello_world_1 = require("./hello-world");
4
- exports.sayHello = hello_world_1.sayHello;
5
- exports.sayGoodbye = hello_world_1.sayGoodbye;
6
- var google_pub_sub_1 = require("./google-pub-sub");
7
- exports.GooglePubSubSubscription = google_pub_sub_1.GooglePubSubSubscription;
8
- exports.GooglePubSubPublish = google_pub_sub_1.GooglePubSubPublish;
3
+ var PubSubHandlerAction_1 = require("./Handlers/PubSubHandlerAction");
4
+ exports.PubSubHandlerAction = PubSubHandlerAction_1.PubSubHandlerAction;
5
+ var GooglePubSubSubscription_1 = require("./Class/GooglePubSubSubscription");
6
+ exports.GooglePubSubSubscription = GooglePubSubSubscription_1.GooglePubSubSubscription;
7
+ var GooglePubSubPublish_1 = require("./Class/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.31",
3
+ "version": "0.0.32",
4
4
  "description": "Library from SIMLabs",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",