sim-node-lib 0.0.53 → 0.0.54

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,6 +1,6 @@
1
1
  export declare enum PubSubTableEnum {
2
2
  agrupador = "agrupador",
3
- autosystem_plate = "autosystema-pessoa_frota",
3
+ autosystem_plate = "autosystem-pessoa_frota",
4
4
  bandeira = "bandeira",
5
5
  cargo = "cargo",
6
6
  cliente = "cliente",
@@ -4,7 +4,7 @@ exports.PubSubTableEnum = void 0;
4
4
  var PubSubTableEnum;
5
5
  (function (PubSubTableEnum) {
6
6
  PubSubTableEnum["agrupador"] = "agrupador";
7
- PubSubTableEnum["autosystem_plate"] = "autosystema-pessoa_frota";
7
+ PubSubTableEnum["autosystem_plate"] = "autosystem-pessoa_frota";
8
8
  PubSubTableEnum["bandeira"] = "bandeira";
9
9
  PubSubTableEnum["cargo"] = "cargo";
10
10
  PubSubTableEnum["cliente"] = "cliente";
@@ -1,10 +1,10 @@
1
1
  /// <reference types="node" />
2
2
  import { EventEmitter } from 'events';
3
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);
4
+ readonly value: any;
5
+ readonly action: PubSubActionEnum;
6
+ readonly table: PubSubTableEnum;
7
+ constructor(value: object, action: PubSubActionEnum, table: PubSubTableEnum);
8
8
  }
9
9
  export declare class GooglePubSubSubscription {
10
10
  constructor(subscriptionName: string);
@@ -14,15 +14,15 @@ export declare class GooglePubSubSubscription {
14
14
  export declare class GooglePubSubPublish {
15
15
  constructor(topicName: string);
16
16
  private _topicName;
17
- createMessages(message: object, action: PubSubActionEnum, table: string): Promise<void>;
17
+ createMessages(message: object, action: PubSubActionEnum, table: PubSubTableEnum): Promise<void>;
18
18
  }
19
19
  export declare abstract class PubSubHandelerAction {
20
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;
21
+ protected _pubsubValueModel: PubSubModel;
22
+ handlerAction(): Promise<boolean>;
23
+ protected insert(): Promise<boolean>;
24
+ protected update(): Promise<boolean>;
25
+ protected remove(): Promise<boolean>;
26
26
  protected buildData(): Object;
27
27
  }
28
28
  export declare enum PubSubActionEnum {
@@ -30,3 +30,30 @@ export declare enum PubSubActionEnum {
30
30
  update = "update",
31
31
  remove = "remove"
32
32
  }
33
+ export declare enum PubSubTableEnum {
34
+ bandeira = 0,
35
+ cliente = 1,
36
+ clienteEndereco = 2,
37
+ clientePendente = 3,
38
+ configuracao = 4,
39
+ empresa = 5,
40
+ empresaHorario = 6,
41
+ empresaServico = 7,
42
+ grupoDesconto = 8,
43
+ grupoDescontoLimite = 9,
44
+ grupoEmpresa = 10,
45
+ item = 11,
46
+ itemTag = 12,
47
+ promocao = 13,
48
+ promocaoEmpresa = 14,
49
+ promocaoGrupoDesconto = 15,
50
+ promocaoItem = 16,
51
+ promocaoRecorrencia = 17,
52
+ promocaoTag = 18,
53
+ servico = 19,
54
+ tag = 20,
55
+ voucherDesconto = 21,
56
+ voucherDescontoLote = 22,
57
+ voucherMigracao = 23,
58
+ voucherMigracaoLote = 24
59
+ }
@@ -13,7 +13,7 @@ const pubsub_1 = require("@google-cloud/pubsub");
13
13
  class PubSubModel {
14
14
  constructor(value, action, table) {
15
15
  this.value = value;
16
- this.action = action.toString();
16
+ this.action = action;
17
17
  this.table = table;
18
18
  }
19
19
  }
@@ -25,20 +25,13 @@ class GooglePubSubSubscription {
25
25
  listenMessages(eventEmitter) {
26
26
  return __awaiter(this, void 0, void 0, function* () {
27
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
- }
28
+ const data = JSON.parse(message.data.toString());
29
+ const pubSubModel = new PubSubModel(data.value, data.action, data.table);
30
+ eventEmitter.emit('event', [pubSubModel, message]);
37
31
  });
38
- // Receive callbacks for errors on the subscription
39
32
  this._subscription.on('error', (error) => {
40
33
  console.error('Received error:', error);
41
- throw Error(error);
34
+ eventEmitter.emit('error', error);
42
35
  });
43
36
  });
44
37
  }
@@ -52,13 +45,9 @@ class GooglePubSubPublish {
52
45
  return __awaiter(this, void 0, void 0, function* () {
53
46
  const pubSubClient = new pubsub_1.PubSub();
54
47
  const send = new PubSubModel(message, action, table);
55
- // Creates a new topic
56
48
  const topic = pubSubClient.topic(this._topicName);
57
- console.log(`Topic ${topic.name} created.`);
58
49
  const dataSend = JSON.stringify(send);
59
- //Create message
60
50
  const data = Buffer.from(dataSend);
61
- // Send a message to the topic
62
51
  yield topic.publishMessage({ data });
63
52
  });
64
53
  }
@@ -66,24 +55,21 @@ class GooglePubSubPublish {
66
55
  exports.GooglePubSubPublish = GooglePubSubPublish;
67
56
  class PubSubHandelerAction {
68
57
  constructor(pubsubModel) {
69
- this._pubsubValueModel = pubsubModel.value;
70
- this.handlerAction(pubsubModel.action);
58
+ this._pubsubValueModel = pubsubModel;
71
59
  }
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
- }
60
+ handlerAction() {
61
+ return __awaiter(this, void 0, void 0, function* () {
62
+ switch (this._pubsubValueModel.action) {
63
+ case 'insert':
64
+ return yield this.insert();
65
+ case 'update':
66
+ return yield this.update();
67
+ case 'remove':
68
+ return yield this.remove();
69
+ default:
70
+ throw new Error('PubSub handler action not implemented.');
71
+ }
72
+ });
87
73
  }
88
74
  insert() {
89
75
  throw new Error('Method insert PubSub handler action not implemented.');
@@ -105,3 +91,31 @@ var PubSubActionEnum;
105
91
  PubSubActionEnum["update"] = "update";
106
92
  PubSubActionEnum["remove"] = "remove";
107
93
  })(PubSubActionEnum = exports.PubSubActionEnum || (exports.PubSubActionEnum = {}));
94
+ var PubSubTableEnum;
95
+ (function (PubSubTableEnum) {
96
+ PubSubTableEnum[PubSubTableEnum["bandeira"] = 0] = "bandeira";
97
+ PubSubTableEnum[PubSubTableEnum["cliente"] = 1] = "cliente";
98
+ PubSubTableEnum[PubSubTableEnum["clienteEndereco"] = 2] = "clienteEndereco";
99
+ PubSubTableEnum[PubSubTableEnum["clientePendente"] = 3] = "clientePendente";
100
+ PubSubTableEnum[PubSubTableEnum["configuracao"] = 4] = "configuracao";
101
+ PubSubTableEnum[PubSubTableEnum["empresa"] = 5] = "empresa";
102
+ PubSubTableEnum[PubSubTableEnum["empresaHorario"] = 6] = "empresaHorario";
103
+ PubSubTableEnum[PubSubTableEnum["empresaServico"] = 7] = "empresaServico";
104
+ PubSubTableEnum[PubSubTableEnum["grupoDesconto"] = 8] = "grupoDesconto";
105
+ PubSubTableEnum[PubSubTableEnum["grupoDescontoLimite"] = 9] = "grupoDescontoLimite";
106
+ PubSubTableEnum[PubSubTableEnum["grupoEmpresa"] = 10] = "grupoEmpresa";
107
+ PubSubTableEnum[PubSubTableEnum["item"] = 11] = "item";
108
+ PubSubTableEnum[PubSubTableEnum["itemTag"] = 12] = "itemTag";
109
+ PubSubTableEnum[PubSubTableEnum["promocao"] = 13] = "promocao";
110
+ PubSubTableEnum[PubSubTableEnum["promocaoEmpresa"] = 14] = "promocaoEmpresa";
111
+ PubSubTableEnum[PubSubTableEnum["promocaoGrupoDesconto"] = 15] = "promocaoGrupoDesconto";
112
+ PubSubTableEnum[PubSubTableEnum["promocaoItem"] = 16] = "promocaoItem";
113
+ PubSubTableEnum[PubSubTableEnum["promocaoRecorrencia"] = 17] = "promocaoRecorrencia";
114
+ PubSubTableEnum[PubSubTableEnum["promocaoTag"] = 18] = "promocaoTag";
115
+ PubSubTableEnum[PubSubTableEnum["servico"] = 19] = "servico";
116
+ PubSubTableEnum[PubSubTableEnum["tag"] = 20] = "tag";
117
+ PubSubTableEnum[PubSubTableEnum["voucherDesconto"] = 21] = "voucherDesconto";
118
+ PubSubTableEnum[PubSubTableEnum["voucherDescontoLote"] = 22] = "voucherDescontoLote";
119
+ PubSubTableEnum[PubSubTableEnum["voucherMigracao"] = 23] = "voucherMigracao";
120
+ PubSubTableEnum[PubSubTableEnum["voucherMigracaoLote"] = 24] = "voucherMigracaoLote";
121
+ })(PubSubTableEnum = exports.PubSubTableEnum || (exports.PubSubTableEnum = {}));
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "sim-node-lib",
3
- "version": "0.0.53",
3
+ "version": "0.0.54",
4
4
  "description": "Library from SIMLabs",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",