sim-node-lib 0.0.32 → 0.0.35

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,6 +9,7 @@ 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;
12
13
  const pubsub_1 = require("@google-cloud/pubsub");
13
14
  const PubSubModel_1 = require("../Models/PubSubModel");
14
15
  class GooglePubSubPublish {
@@ -9,6 +9,7 @@ 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;
12
13
  const pubsub_1 = require("@google-cloud/pubsub");
13
14
  const PubSubModel_1 = require("../Models/PubSubModel");
14
15
  class GooglePubSubSubscription {
@@ -1,5 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.PubSubActionEnum = void 0;
3
4
  var PubSubActionEnum;
4
5
  (function (PubSubActionEnum) {
5
6
  PubSubActionEnum["insert"] = "insert";
@@ -4,6 +4,7 @@ export declare enum PubSubTableEnum {
4
4
  clienteEndereco = "cliente_endereco",
5
5
  clientePendente = "cliente_pendente",
6
6
  configuracao = "configuracao",
7
+ concorrentes = "concorrentes",
7
8
  empresa = "empresa",
8
9
  empresaHorario = "empresa_horario",
9
10
  empresaServico = "empresa_servico",
@@ -14,11 +15,11 @@ export declare enum PubSubTableEnum {
14
15
  item = "item",
15
16
  itemTag = "item_tag",
16
17
  promocao = "promocao",
18
+ promocaoCombo = "promocao_combo",
19
+ promocaoComboItem = "promocao_combo_item",
17
20
  promocaoEmpresa = "promocao_empresa",
18
21
  promocaoGrupoDesconto = "promocao_grupo_desconto",
19
- promocaoItem = "promocao_item",
20
22
  promocaoRecorrencia = "promocao_recorrencia",
21
- promocaoTag = "promocao_tag",
22
23
  rede = "rede",
23
24
  servico = "servico",
24
25
  tag = "tag",
@@ -1,5 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.PubSubTableEnum = void 0;
3
4
  var PubSubTableEnum;
4
5
  (function (PubSubTableEnum) {
5
6
  PubSubTableEnum["bandeira"] = "bandeira";
@@ -7,6 +8,7 @@ var PubSubTableEnum;
7
8
  PubSubTableEnum["clienteEndereco"] = "cliente_endereco";
8
9
  PubSubTableEnum["clientePendente"] = "cliente_pendente";
9
10
  PubSubTableEnum["configuracao"] = "configuracao";
11
+ PubSubTableEnum["concorrentes"] = "concorrentes";
10
12
  PubSubTableEnum["empresa"] = "empresa";
11
13
  PubSubTableEnum["empresaHorario"] = "empresa_horario";
12
14
  PubSubTableEnum["empresaServico"] = "empresa_servico";
@@ -17,11 +19,11 @@ var PubSubTableEnum;
17
19
  PubSubTableEnum["item"] = "item";
18
20
  PubSubTableEnum["itemTag"] = "item_tag";
19
21
  PubSubTableEnum["promocao"] = "promocao";
22
+ PubSubTableEnum["promocaoCombo"] = "promocao_combo";
23
+ PubSubTableEnum["promocaoComboItem"] = "promocao_combo_item";
20
24
  PubSubTableEnum["promocaoEmpresa"] = "promocao_empresa";
21
25
  PubSubTableEnum["promocaoGrupoDesconto"] = "promocao_grupo_desconto";
22
- PubSubTableEnum["promocaoItem"] = "promocao_item";
23
26
  PubSubTableEnum["promocaoRecorrencia"] = "promocao_recorrencia";
24
- PubSubTableEnum["promocaoTag"] = "promocao_tag";
25
27
  PubSubTableEnum["rede"] = "rede";
26
28
  PubSubTableEnum["servico"] = "servico";
27
29
  PubSubTableEnum["tag"] = "tag";
@@ -9,6 +9,7 @@ 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;
12
13
  class PubSubHandlerAction {
13
14
  constructor(pubsubModel) {
14
15
  this._pubsubValueModel = pubsubModel;
@@ -1,5 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.CryptHelper = void 0;
3
4
  const crypto = require('crypto');
4
5
  const alg = 'aes-256-ctr';
5
6
  const pwd = 'Macaco';
@@ -0,0 +1,9 @@
1
+ export declare class DateUtils {
2
+ static normalizeDate(mixedDate: Date | string | undefined | Date): Date;
3
+ static validateDateBetweenTwoDatesWithDate(fromDate: Date, toDate: Date, givenDate: Date): boolean;
4
+ static validateDateBetweenTwoDatesWithString(fromDate: Date, toDate: Date, givenDate: Date): boolean;
5
+ static validateCurrentDateBetweenTwoDates(fromDate: Date, toDate: Date): boolean;
6
+ static dateToStringFormatBR(date: string): Date;
7
+ static dateToStringFormat(date: string, format: string): Date;
8
+ static getDifferenceInMinutes(startData: Date, endData: Date): number;
9
+ }
@@ -0,0 +1,29 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.DateUtils = void 0;
4
+ const moment = require("moment");
5
+ class DateUtils {
6
+ static normalizeDate(mixedDate) {
7
+ return typeof mixedDate === 'string' ? new Date() : mixedDate;
8
+ }
9
+ static validateDateBetweenTwoDatesWithDate(fromDate, toDate, givenDate) {
10
+ return (givenDate <= DateUtils.normalizeDate(toDate) && givenDate >= DateUtils.normalizeDate(fromDate));
11
+ }
12
+ static validateDateBetweenTwoDatesWithString(fromDate, toDate, givenDate) {
13
+ return DateUtils.validateDateBetweenTwoDatesWithDate(fromDate, toDate, DateUtils.normalizeDate(givenDate));
14
+ }
15
+ static validateCurrentDateBetweenTwoDates(fromDate, toDate) {
16
+ return DateUtils.validateDateBetweenTwoDatesWithDate(fromDate, toDate, new Date());
17
+ }
18
+ static dateToStringFormatBR(date) {
19
+ return this.dateToStringFormat(date, 'DD/MM/yyyy');
20
+ }
21
+ static dateToStringFormat(date, format) {
22
+ var data = moment(date, format).toDate();
23
+ return data;
24
+ }
25
+ static getDifferenceInMinutes(startData, endData) {
26
+ return Math.trunc((Math.abs(startData.getTime() - endData.getTime()) / 36e5) * 60);
27
+ }
28
+ }
29
+ exports.DateUtils = DateUtils;
@@ -1,5 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.HashHelper = void 0;
3
4
  class HashHelper {
4
5
  static criarHash(forceUppercase, length) {
5
6
  const keygen = require('keygenerator');
@@ -1,5 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.NumberHelper = void 0;
3
4
  class NumberHelper {
4
5
  static convertBase(num, baseFrom, baseTo) {
5
6
  return parseInt(num.toString(), baseFrom).toString(baseTo).toUpperCase();
@@ -1,5 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.PromiseUtil = void 0;
3
4
  class PromiseUtil {
4
5
  static PromiseHelper(ms = Number(process.env.REQUEST_TIMEOUT)) {
5
6
  return new Promise((reject) => {
@@ -1,5 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.StringHelper = void 0;
3
4
  class StringHelper {
4
5
  static removeSpecialCharactersFromString(str) {
5
6
  return str.normalize('NFD').replace(/[\u0300-\u036f]/g, '');
@@ -1,5 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.PubSubModel = void 0;
3
4
  class PubSubModel {
4
5
  constructor(value, action, table) {
5
6
  this.value = value;
package/dist/index.js CHANGED
@@ -1,8 +1,9 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.GooglePubSubPublish = exports.GooglePubSubSubscription = exports.PubSubHandlerAction = void 0;
3
4
  var PubSubHandlerAction_1 = require("./Handlers/PubSubHandlerAction");
4
- exports.PubSubHandlerAction = PubSubHandlerAction_1.PubSubHandlerAction;
5
+ Object.defineProperty(exports, "PubSubHandlerAction", { enumerable: true, get: function () { return PubSubHandlerAction_1.PubSubHandlerAction; } });
5
6
  var GooglePubSubSubscription_1 = require("./Class/GooglePubSubSubscription");
6
- exports.GooglePubSubSubscription = GooglePubSubSubscription_1.GooglePubSubSubscription;
7
+ Object.defineProperty(exports, "GooglePubSubSubscription", { enumerable: true, get: function () { return GooglePubSubSubscription_1.GooglePubSubSubscription; } });
7
8
  var GooglePubSubPublish_1 = require("./Class/GooglePubSubPublish");
8
- exports.GooglePubSubPublish = GooglePubSubPublish_1.GooglePubSubPublish;
9
+ Object.defineProperty(exports, "GooglePubSubPublish", { enumerable: true, get: function () { return GooglePubSubPublish_1.GooglePubSubPublish; } });
package/package.json CHANGED
@@ -1,18 +1,23 @@
1
1
  {
2
2
  "name": "sim-node-lib",
3
- "version": "0.0.32",
3
+ "version": "0.0.35",
4
4
  "description": "Library from SIMLabs",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",
7
7
  "files": [
8
8
  "/dist"
9
9
  ],
10
+ "scripts": {
11
+ "tsc": "tsc",
12
+ "pub": "tsc && yarn publish"
13
+ },
10
14
  "license": "ISC",
11
15
  "dependencies": {
12
16
  "@google-cloud/pubsub": "^3.0.1",
13
17
  "crypto": "^1.0.1",
14
18
  "dotenv": "^16.0.1",
15
- "keygenerator": "^1.0.4"
19
+ "keygenerator": "^1.0.4",
20
+ "moment": "^2.29.4"
16
21
  },
17
22
  "devDependencies": {
18
23
  "@types/node": "^17.0.41",
@@ -1,32 +0,0 @@
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
- }
@@ -1,107 +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.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,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;