sim-node-lib 0.0.26 → 0.0.29
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/dist/Class/GooglePubSubPublish.d.ts +2 -2
- package/dist/Class/GooglePubSubSubscription.d.ts +1 -1
- package/dist/Class/GooglePubSubSubscription.js +5 -5
- package/dist/Handlers/PubSubHandlerAction.d.ts +1 -1
- package/dist/Handlers/PubSubHandlerAction.js +12 -12
- package/dist/Helpers/CryptHelper.d.ts +4 -0
- package/dist/Helpers/CryptHelper.js +19 -0
- package/dist/Helpers/HashHelper.d.ts +3 -0
- package/dist/Helpers/HashHelper.js +10 -0
- package/dist/Helpers/NumberHelper.d.ts +5 -0
- package/dist/Helpers/NumberHelper.js +15 -0
- package/dist/Helpers/PromiseHelper.d.ts +3 -0
- package/dist/Helpers/PromiseHelper.js +14 -0
- package/dist/Helpers/StringHelper.d.ts +5 -0
- package/dist/Helpers/StringHelper.js +27 -0
- package/dist/Models/PubSubModel.d.ts +2 -2
- package/dist/Utils/NumberUtil.d.ts +5 -0
- package/dist/Utils/NumberUtil.js +15 -0
- package/dist/Utils/StringUtil.d.ts +4 -0
- package/dist/Utils/StringUtil.js +24 -0
- package/package.json +3 -2
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { PubSubActionEnum } from
|
|
2
|
-
import { PubSubTableEnum } from
|
|
1
|
+
import { PubSubActionEnum } from '../Enums/PubSubActionEnum';
|
|
2
|
+
import { PubSubTableEnum } from '../Enums/PubSubTableEnum';
|
|
3
3
|
export declare class GooglePubSubPublish {
|
|
4
4
|
constructor(topicName: string);
|
|
5
5
|
private _topicName;
|
|
@@ -18,14 +18,14 @@ class GooglePubSubSubscription {
|
|
|
18
18
|
}
|
|
19
19
|
listenMessages(eventEmitter) {
|
|
20
20
|
return __awaiter(this, void 0, void 0, function* () {
|
|
21
|
-
this._subscription.on(
|
|
21
|
+
this._subscription.on('message', (message) => {
|
|
22
22
|
const data = JSON.parse(message.data.toString());
|
|
23
23
|
const pubSubModel = new PubSubModel_1.PubSubModel(data.value, data.action, data.table);
|
|
24
|
-
eventEmitter.emit(
|
|
24
|
+
eventEmitter.emit('event', [pubSubModel, message]);
|
|
25
25
|
});
|
|
26
|
-
this._subscription.on(
|
|
27
|
-
console.error(
|
|
28
|
-
eventEmitter.emit(
|
|
26
|
+
this._subscription.on('error', (error) => {
|
|
27
|
+
console.error('Received error:', error);
|
|
28
|
+
eventEmitter.emit('error', error);
|
|
29
29
|
});
|
|
30
30
|
});
|
|
31
31
|
}
|
|
@@ -17,38 +17,38 @@ class PubSubHandlerAction {
|
|
|
17
17
|
handlerAction() {
|
|
18
18
|
return __awaiter(this, void 0, void 0, function* () {
|
|
19
19
|
switch (this._pubsubValueModel.action) {
|
|
20
|
-
case
|
|
20
|
+
case 'insert':
|
|
21
21
|
return yield this.insert();
|
|
22
|
-
case
|
|
22
|
+
case 'insert_many':
|
|
23
23
|
return yield this.insertMany();
|
|
24
|
-
case
|
|
24
|
+
case 'update':
|
|
25
25
|
return yield this.update();
|
|
26
|
-
case
|
|
26
|
+
case 'update_many':
|
|
27
27
|
return yield this.updateMany();
|
|
28
|
-
case
|
|
28
|
+
case 'delete':
|
|
29
29
|
return yield this.delete();
|
|
30
30
|
default:
|
|
31
|
-
|
|
31
|
+
return true;
|
|
32
32
|
}
|
|
33
33
|
});
|
|
34
34
|
}
|
|
35
35
|
insert() {
|
|
36
|
-
throw new Error(
|
|
36
|
+
throw new Error('Method insert PubSub handler action not implemented.');
|
|
37
37
|
}
|
|
38
38
|
insertMany() {
|
|
39
|
-
throw new Error(
|
|
39
|
+
throw new Error('Method insert PubSub handler action not implemented.');
|
|
40
40
|
}
|
|
41
41
|
update() {
|
|
42
|
-
throw new Error(
|
|
42
|
+
throw new Error('Method update PubSub handler action not implemented.');
|
|
43
43
|
}
|
|
44
44
|
updateMany() {
|
|
45
|
-
throw new Error(
|
|
45
|
+
throw new Error('Method update PubSub handler action not implemented.');
|
|
46
46
|
}
|
|
47
47
|
delete() {
|
|
48
|
-
throw new Error(
|
|
48
|
+
throw new Error('Method delete PubSub handler action not implemented.');
|
|
49
49
|
}
|
|
50
50
|
buildData() {
|
|
51
|
-
throw new Error(
|
|
51
|
+
throw new Error('Method buildData PubSub handler action not implemented.');
|
|
52
52
|
}
|
|
53
53
|
}
|
|
54
54
|
exports.PubSubHandlerAction = PubSubHandlerAction;
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.CryptHelper = void 0;
|
|
4
|
+
const crypto = require('crypto');
|
|
5
|
+
const alg = 'aes-256-ctr';
|
|
6
|
+
const pwd = 'Macaco';
|
|
7
|
+
class CryptHelper {
|
|
8
|
+
static encrypt(mensagem) {
|
|
9
|
+
const cipher = crypto.createCipher(alg, pwd);
|
|
10
|
+
const crypted = cipher.update(mensagem, 'utf8', 'hex');
|
|
11
|
+
return crypted;
|
|
12
|
+
}
|
|
13
|
+
static decrypt(mensagem) {
|
|
14
|
+
const decipher = crypto.createDecipher(alg, pwd);
|
|
15
|
+
const plain = decipher.update(mensagem, 'hex', 'utf8');
|
|
16
|
+
return plain;
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
exports.CryptHelper = CryptHelper;
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.HashUtil = void 0;
|
|
4
|
+
class HashUtil {
|
|
5
|
+
static criarHash(forceUppercase, length) {
|
|
6
|
+
const keygen = require('keygenerator');
|
|
7
|
+
return keygen._({ forceUppercase: forceUppercase, length: length });
|
|
8
|
+
}
|
|
9
|
+
}
|
|
10
|
+
exports.HashUtil = HashUtil;
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.NumberHelper = void 0;
|
|
4
|
+
class NumberHelper {
|
|
5
|
+
static convertBase(num, baseFrom, baseTo) {
|
|
6
|
+
return parseInt(num.toString(), baseFrom).toString(baseTo).toUpperCase();
|
|
7
|
+
}
|
|
8
|
+
static convertBase10to36(num) {
|
|
9
|
+
return parseInt(num.toString(), 10).toString(36).toUpperCase();
|
|
10
|
+
}
|
|
11
|
+
static convertBase10to36WithZeroFill(num, size) {
|
|
12
|
+
return this.convertBase10to36(num).padStart(size, '0');
|
|
13
|
+
}
|
|
14
|
+
}
|
|
15
|
+
exports.NumberHelper = NumberHelper;
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.PromiseUtil = void 0;
|
|
4
|
+
class PromiseUtil {
|
|
5
|
+
static PromiseHelper(ms = Number(process.env.REQUEST_TIMEOUT)) {
|
|
6
|
+
return new Promise((reject) => {
|
|
7
|
+
const id = setTimeout(() => {
|
|
8
|
+
clearTimeout(id);
|
|
9
|
+
reject('Timeout in ' + ms + ' ms');
|
|
10
|
+
}, ms);
|
|
11
|
+
});
|
|
12
|
+
}
|
|
13
|
+
}
|
|
14
|
+
exports.PromiseUtil = PromiseUtil;
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.StringHelper = void 0;
|
|
4
|
+
class StringHelper {
|
|
5
|
+
static removeSpecialCharactersFromString(str) {
|
|
6
|
+
return str.normalize('NFD').replace(/[\u0300-\u036f]/g, '');
|
|
7
|
+
}
|
|
8
|
+
static convertBooleanToString(string) {
|
|
9
|
+
switch (string.toLowerCase().trim()) {
|
|
10
|
+
case 'true':
|
|
11
|
+
case 'yes':
|
|
12
|
+
case '1':
|
|
13
|
+
return true;
|
|
14
|
+
case 'false':
|
|
15
|
+
case 'no':
|
|
16
|
+
case '0':
|
|
17
|
+
case null:
|
|
18
|
+
return false;
|
|
19
|
+
default:
|
|
20
|
+
return Boolean(string);
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
static camelToSnakeCase(string) {
|
|
24
|
+
return string.replace(/([A-Z])/g, (char) => `_${char.toLowerCase()}`);
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
exports.StringHelper = StringHelper;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { PubSubActionEnum } from
|
|
2
|
-
import { PubSubTableEnum } from
|
|
1
|
+
import { PubSubActionEnum } from '../Enums/PubSubActionEnum';
|
|
2
|
+
import { PubSubTableEnum } from '../Enums/PubSubTableEnum';
|
|
3
3
|
export declare class PubSubModel {
|
|
4
4
|
readonly value: any;
|
|
5
5
|
readonly action: PubSubActionEnum;
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.NumberUtil = void 0;
|
|
4
|
+
class NumberUtil {
|
|
5
|
+
static convertBase(num, baseFrom, baseTo) {
|
|
6
|
+
return parseInt(num.toString(), baseFrom).toString(baseTo).toUpperCase();
|
|
7
|
+
}
|
|
8
|
+
static convertBase10to36(num) {
|
|
9
|
+
return parseInt(num.toString(), 10).toString(36).toUpperCase();
|
|
10
|
+
}
|
|
11
|
+
static convertBase10to36WithZeroFill(num, size) {
|
|
12
|
+
return this.convertBase10to36(num).padStart(size, "0");
|
|
13
|
+
}
|
|
14
|
+
}
|
|
15
|
+
exports.NumberUtil = NumberUtil;
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.StringUtil = void 0;
|
|
4
|
+
class StringUtil {
|
|
5
|
+
static removeSpecialCharactersFromString(str) {
|
|
6
|
+
return str.normalize("NFD").replace(/[\u0300-\u036f]/g, "");
|
|
7
|
+
}
|
|
8
|
+
static convertBooleanToString(string) {
|
|
9
|
+
switch (string.toLowerCase().trim()) {
|
|
10
|
+
case "true":
|
|
11
|
+
case "yes":
|
|
12
|
+
case "1":
|
|
13
|
+
return true;
|
|
14
|
+
case "false":
|
|
15
|
+
case "no":
|
|
16
|
+
case "0":
|
|
17
|
+
case null:
|
|
18
|
+
return false;
|
|
19
|
+
default:
|
|
20
|
+
return Boolean(string);
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
exports.StringUtil = StringUtil;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "sim-node-lib",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.29",
|
|
4
4
|
"description": "Library from SIMLabs",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"types": "dist/index.d.ts",
|
|
@@ -10,7 +10,8 @@
|
|
|
10
10
|
"license": "ISC",
|
|
11
11
|
"dependencies": {
|
|
12
12
|
"@google-cloud/pubsub": "^3.0.1",
|
|
13
|
-
"dotenv": "^16.0.1"
|
|
13
|
+
"dotenv": "^16.0.1",
|
|
14
|
+
"keygenerator": "^1.0.4"
|
|
14
15
|
},
|
|
15
16
|
"devDependencies": {
|
|
16
17
|
"@types/node": "^17.0.41",
|