sim-node-lib 0.0.28 → 0.0.31

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,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.d.ts CHANGED
@@ -1,3 +1,2 @@
1
- export { PubSubHandlerAction } from "./Handlers/PubSubHandlerAction";
2
- export { GooglePubSubSubscription } from "./Class/GooglePubSubSubscription";
3
- export { GooglePubSubPublish } from "./Class/GooglePubSubPublish";
1
+ export { sayHello, sayGoodbye } from "./hello-world";
2
+ export { GooglePubSubSubscription, GooglePubSubPublish } from "./google-pub-sub";
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
- var PubSubHandlerAction_1 = require("./Handlers/PubSubHandlerAction");
5
- Object.defineProperty(exports, "PubSubHandlerAction", { enumerable: true, get: function () { return PubSubHandlerAction_1.PubSubHandlerAction; } });
6
- var GooglePubSubSubscription_1 = require("./Class/GooglePubSubSubscription");
7
- Object.defineProperty(exports, "GooglePubSubSubscription", { enumerable: true, get: function () { return GooglePubSubSubscription_1.GooglePubSubSubscription; } });
8
- var GooglePubSubPublish_1 = require("./Class/GooglePubSubPublish");
9
- Object.defineProperty(exports, "GooglePubSubPublish", { enumerable: true, get: function () { return GooglePubSubPublish_1.GooglePubSubPublish; } });
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;
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.31",
4
4
  "description": "Library from SIMLabs",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",
@@ -10,7 +10,9 @@
10
10
  "license": "ISC",
11
11
  "dependencies": {
12
12
  "@google-cloud/pubsub": "^3.0.1",
13
- "dotenv": "^16.0.1"
13
+ "crypto": "^1.0.1",
14
+ "dotenv": "^16.0.1",
15
+ "keygenerator": "^1.0.4"
14
16
  },
15
17
  "devDependencies": {
16
18
  "@types/node": "^17.0.41",
@@ -1,7 +0,0 @@
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
- }
@@ -1,30 +0,0 @@
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
- exports.GooglePubSubPublish = void 0;
13
- const pubsub_1 = require("@google-cloud/pubsub");
14
- const PubSubModel_1 = require("../Models/PubSubModel");
15
- class GooglePubSubPublish {
16
- constructor(topicName) {
17
- this._topicName = topicName;
18
- }
19
- createMessages(message, action, table) {
20
- return __awaiter(this, void 0, void 0, function* () {
21
- const pubSubClient = new pubsub_1.PubSub();
22
- const send = new PubSubModel_1.PubSubModel(message, action, table);
23
- const topic = pubSubClient.topic(this._topicName);
24
- const dataSend = JSON.stringify(send);
25
- const data = Buffer.from(dataSend);
26
- yield topic.publishMessage({ data });
27
- });
28
- }
29
- }
30
- exports.GooglePubSubPublish = GooglePubSubPublish;
@@ -1,7 +0,0 @@
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
- }
@@ -1,33 +0,0 @@
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
- exports.GooglePubSubSubscription = void 0;
13
- const pubsub_1 = require("@google-cloud/pubsub");
14
- const PubSubModel_1 = require("../Models/PubSubModel");
15
- class GooglePubSubSubscription {
16
- constructor(subscriptionName) {
17
- this._subscription = new pubsub_1.PubSub().subscription(subscriptionName);
18
- }
19
- listenMessages(eventEmitter) {
20
- return __awaiter(this, void 0, void 0, function* () {
21
- this._subscription.on("message", (message) => {
22
- const data = JSON.parse(message.data.toString());
23
- const pubSubModel = new PubSubModel_1.PubSubModel(data.value, data.action, data.table);
24
- eventEmitter.emit("event", [pubSubModel, message]);
25
- });
26
- this._subscription.on("error", (error) => {
27
- console.error("Received error:", error);
28
- eventEmitter.emit("error", error);
29
- });
30
- });
31
- }
32
- }
33
- exports.GooglePubSubSubscription = GooglePubSubSubscription;
@@ -1,7 +0,0 @@
1
- export declare enum PubSubActionEnum {
2
- insert = "insert",
3
- insertMany = "insert_many",
4
- update = "update",
5
- updateMany = "update_many",
6
- delete = "delete"
7
- }
@@ -1,11 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.PubSubActionEnum = void 0;
4
- var PubSubActionEnum;
5
- (function (PubSubActionEnum) {
6
- PubSubActionEnum["insert"] = "insert";
7
- PubSubActionEnum["insertMany"] = "insert_many";
8
- PubSubActionEnum["update"] = "update";
9
- PubSubActionEnum["updateMany"] = "update_many";
10
- PubSubActionEnum["delete"] = "delete";
11
- })(PubSubActionEnum = exports.PubSubActionEnum || (exports.PubSubActionEnum = {}));
@@ -1,28 +0,0 @@
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
- servico = "servico",
23
- tag = "tag",
24
- voucherDesconto = "voucher_desconto",
25
- voucherDescontoLote = "voucher_desconto_lote",
26
- voucherMigracao = "voucher_migracao",
27
- voucherMigracaoLote = "voucher_migracao_lote"
28
- }
@@ -1,32 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.PubSubTableEnum = void 0;
4
- var PubSubTableEnum;
5
- (function (PubSubTableEnum) {
6
- PubSubTableEnum["bandeira"] = "bandeira";
7
- PubSubTableEnum["cliente"] = "cliente";
8
- PubSubTableEnum["clienteEndereco"] = "cliente_endereco";
9
- PubSubTableEnum["clientePendente"] = "cliente_pendente";
10
- PubSubTableEnum["configuracao"] = "configuracao";
11
- PubSubTableEnum["empresa"] = "empresa";
12
- PubSubTableEnum["empresaHorario"] = "empresa_horario";
13
- PubSubTableEnum["empresaServico"] = "empresa_servico";
14
- PubSubTableEnum["grupoDesconto"] = "grupo_desconto";
15
- PubSubTableEnum["grupoDescontoLimite"] = "grupo_desconto_limite";
16
- PubSubTableEnum["grupoPromocao"] = "grupo_promocao";
17
- PubSubTableEnum["grupoEmpresa"] = "grupo_empresa";
18
- PubSubTableEnum["item"] = "item";
19
- PubSubTableEnum["itemTag"] = "item_tag";
20
- PubSubTableEnum["promocao"] = "promocao";
21
- PubSubTableEnum["promocaoEmpresa"] = "promocao_empresa";
22
- PubSubTableEnum["promocaoGrupoDesconto"] = "promocao_grupo_desconto";
23
- PubSubTableEnum["promocaoItem"] = "promocao_item";
24
- PubSubTableEnum["promocaoRecorrencia"] = "promocao_recorrencia";
25
- PubSubTableEnum["promocaoTag"] = "promocao_tag";
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 = {}));
@@ -1,12 +0,0 @@
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
- }
@@ -1,54 +0,0 @@
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
- exports.PubSubHandlerAction = void 0;
13
- class PubSubHandlerAction {
14
- constructor(pubsubModel) {
15
- this._pubsubValueModel = pubsubModel;
16
- }
17
- handlerAction() {
18
- return __awaiter(this, void 0, void 0, function* () {
19
- switch (this._pubsubValueModel.action) {
20
- case "insert":
21
- return yield this.insert();
22
- case "insert_many":
23
- return yield this.insertMany();
24
- case "update":
25
- return yield this.update();
26
- case "update_many":
27
- return yield this.updateMany();
28
- case "delete":
29
- return yield this.delete();
30
- default:
31
- return true;
32
- }
33
- });
34
- }
35
- insert() {
36
- throw new Error("Method insert PubSub handler action not implemented.");
37
- }
38
- insertMany() {
39
- throw new Error("Method insert PubSub handler action not implemented.");
40
- }
41
- update() {
42
- throw new Error("Method update PubSub handler action not implemented.");
43
- }
44
- updateMany() {
45
- throw new Error("Method update PubSub handler action not implemented.");
46
- }
47
- delete() {
48
- throw new Error("Method delete PubSub handler action not implemented.");
49
- }
50
- buildData() {
51
- throw new Error("Method buildData PubSub handler action not implemented.");
52
- }
53
- }
54
- exports.PubSubHandlerAction = PubSubHandlerAction;
@@ -1,8 +0,0 @@
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
- }
@@ -1,11 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.PubSubModel = void 0;
4
- class PubSubModel {
5
- constructor(value, action, table) {
6
- this.value = value;
7
- this.action = action;
8
- this.table = table;
9
- }
10
- }
11
- exports.PubSubModel = PubSubModel;