sim-node-lib 0.0.40 → 0.0.43

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.
package/README.md CHANGED
@@ -11,3 +11,11 @@ Node commons library to use on SIMlabs projets
11
11
  ## Documentation
12
12
 
13
13
  All documentation about this library is on Confluence.
14
+
15
+ ## Publish
16
+
17
+ To publish the library, execute the command below:
18
+
19
+ ```
20
+ yarn pub
21
+ ```
@@ -0,0 +1,5 @@
1
+ export declare enum LogTypeEnum {
2
+ error = "ERROR",
3
+ warning = "WARN",
4
+ info = "INFO"
5
+ }
@@ -0,0 +1,9 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.LogTypeEnum = void 0;
4
+ var LogTypeEnum;
5
+ (function (LogTypeEnum) {
6
+ LogTypeEnum["error"] = "ERROR";
7
+ LogTypeEnum["warning"] = "WARN";
8
+ LogTypeEnum["info"] = "INFO";
9
+ })(LogTypeEnum = exports.LogTypeEnum || (exports.LogTypeEnum = {}));
@@ -1,6 +1,7 @@
1
1
  export declare enum PubSubTableEnum {
2
2
  agrupador = "agrupador",
3
3
  bandeira = "bandeira",
4
+ cargo = "cargo",
4
5
  cliente = "cliente",
5
6
  clienteEndereco = "cliente_endereco",
6
7
  clientePendente = "cliente_pendente",
@@ -5,6 +5,7 @@ var PubSubTableEnum;
5
5
  (function (PubSubTableEnum) {
6
6
  PubSubTableEnum["agrupador"] = "agrupador";
7
7
  PubSubTableEnum["bandeira"] = "bandeira";
8
+ PubSubTableEnum["cargo"] = "cargo";
8
9
  PubSubTableEnum["cliente"] = "cliente";
9
10
  PubSubTableEnum["clienteEndereco"] = "cliente_endereco";
10
11
  PubSubTableEnum["clientePendente"] = "cliente_pendente";
@@ -6,4 +6,8 @@ export declare class DateHelper {
6
6
  static dateToStringFormatBR(date: Date): string;
7
7
  static dateToStringFormat(date: Date, format: string): string;
8
8
  static getDifferenceInMinutes(startData: Date, endData: Date): number;
9
+ static isTodayFromString(date: string): boolean;
10
+ static isTodayFromDate(data: Date): boolean;
11
+ static isYesterdayString(date: string): boolean;
12
+ static isYesterdayDate(data: Date): boolean;
9
13
  }
@@ -24,5 +24,20 @@ class DateHelper {
24
24
  static getDifferenceInMinutes(startData, endData) {
25
25
  return Math.trunc((Math.abs(startData.getTime() - endData.getTime()) / 36e5) * 60);
26
26
  }
27
+ static isTodayFromString(date) {
28
+ return this.isTodayFromDate(new Date(date));
29
+ }
30
+ static isTodayFromDate(data) {
31
+ const today = new Date();
32
+ return today.toISOString().split('T')[0] === data.toISOString().split('T')[0];
33
+ }
34
+ static isYesterdayString(date) {
35
+ return this.isYesterdayDate(new Date(date));
36
+ }
37
+ static isYesterdayDate(data) {
38
+ const today = new Date();
39
+ return (new Date(today.setDate(today.getDate() - 1)).toISOString().split('T')[0] ===
40
+ data.toISOString().split('T')[0]);
41
+ }
27
42
  }
28
43
  exports.DateHelper = DateHelper;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "sim-node-lib",
3
- "version": "0.0.40",
3
+ "version": "0.0.43",
4
4
  "description": "Library from SIMLabs",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",
@@ -1,59 +0,0 @@
1
- /// <reference types="node" />
2
- import { EventEmitter } from 'events';
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
- }
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: PubSubTableEnum): Promise<void>;
18
- }
19
- export declare abstract class PubSubHandelerAction {
20
- constructor(pubsubModel: PubSubModel);
21
- protected _pubsubValueModel: PubSubModel;
22
- handlerAction(): Promise<boolean>;
23
- protected insert(): Promise<boolean>;
24
- protected update(): Promise<boolean>;
25
- protected remove(): Promise<boolean>;
26
- protected buildData(): Object;
27
- }
28
- export declare enum PubSubActionEnum {
29
- insert = "insert",
30
- update = "update",
31
- remove = "remove"
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
- }
@@ -1,121 +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
- const pubsub_1 = require("@google-cloud/pubsub");
13
- class PubSubModel {
14
- constructor(value, action, table) {
15
- this.value = value;
16
- this.action = action;
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
- const data = JSON.parse(message.data.toString());
29
- const pubSubModel = new PubSubModel(data.value, data.action, data.table);
30
- eventEmitter.emit('event', [pubSubModel, message]);
31
- });
32
- this._subscription.on('error', (error) => {
33
- console.error('Received error:', error);
34
- eventEmitter.emit('error', error);
35
- });
36
- });
37
- }
38
- }
39
- exports.GooglePubSubSubscription = GooglePubSubSubscription;
40
- class GooglePubSubPublish {
41
- constructor(topicName) {
42
- this._topicName = topicName;
43
- }
44
- createMessages(message, action, table) {
45
- return __awaiter(this, void 0, void 0, function* () {
46
- const pubSubClient = new pubsub_1.PubSub();
47
- const send = new PubSubModel(message, action, table);
48
- const topic = pubSubClient.topic(this._topicName);
49
- const dataSend = JSON.stringify(send);
50
- const data = Buffer.from(dataSend);
51
- yield topic.publishMessage({ data });
52
- });
53
- }
54
- }
55
- exports.GooglePubSubPublish = GooglePubSubPublish;
56
- class PubSubHandelerAction {
57
- constructor(pubsubModel) {
58
- this._pubsubValueModel = pubsubModel;
59
- }
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
- });
73
- }
74
- insert() {
75
- throw new Error('Method insert PubSub handler action not implemented.');
76
- }
77
- update() {
78
- throw new Error('Method update PubSub handler action not implemented.');
79
- }
80
- remove() {
81
- throw new Error('Method remove PubSub handler action not implemented.');
82
- }
83
- buildData() {
84
- throw new Error('Method buildData PubSub handler action not implemented.');
85
- }
86
- }
87
- exports.PubSubHandelerAction = PubSubHandelerAction;
88
- var PubSubActionEnum;
89
- (function (PubSubActionEnum) {
90
- PubSubActionEnum["insert"] = "insert";
91
- PubSubActionEnum["update"] = "update";
92
- PubSubActionEnum["remove"] = "remove";
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 = {}));
@@ -1,2 +0,0 @@
1
- export declare function sayHello(): void;
2
- export declare function sayGoodbye(): void;
@@ -1,11 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- require("dotenv").config();
4
- function sayHello() {
5
- console.log("hi my friend, the NODE PORT is: ", process.env.PORT);
6
- }
7
- exports.sayHello = sayHello;
8
- function sayGoodbye() {
9
- console.log("goodbye");
10
- }
11
- exports.sayGoodbye = sayGoodbye;