sim-node-lib 0.3.6 → 0.3.7

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,6 @@
1
+ export declare class GooglePubSubCreateSubscription {
2
+ createSubscription(): Promise<{
3
+ topic: string;
4
+ sub: string;
5
+ }>;
6
+ }
@@ -0,0 +1,35 @@
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.GooglePubSubCreateSubscription = void 0;
13
+ const pubsub_1 = require("@google-cloud/pubsub");
14
+ const uuid_1 = require("uuid");
15
+ const moment = require("moment");
16
+ class GooglePubSubCreateSubscription {
17
+ createSubscription() {
18
+ return __awaiter(this, void 0, void 0, function* () {
19
+ const apiName = process.env.NAME;
20
+ let hoje = moment(new Date()).format('yyyy-MM-DD');
21
+ let topicName = apiName.toLowerCase() + '-test-' + hoje + '-' + (0, uuid_1.v4)();
22
+ let subName = apiName.toLowerCase() + '-test-' + (0, uuid_1.v4)();
23
+ const pubSubClient = new pubsub_1.PubSub();
24
+ const [topic] = yield pubSubClient.createTopic(topicName);
25
+ const [sub] = yield topic.createSubscription(subName, {
26
+ expirationPolicy: { ttl: { seconds: 86400 } },
27
+ });
28
+ return {
29
+ topic: topic.name,
30
+ sub: sub.name
31
+ };
32
+ });
33
+ }
34
+ }
35
+ exports.GooglePubSubCreateSubscription = GooglePubSubCreateSubscription;
@@ -1,7 +1,8 @@
1
1
  import { PubSubActionEnum } from '../Enums/PubSubActionEnum';
2
+ import { PubSubApiEnum } from '../Enums/PubSubApiEnum';
2
3
  import { PubSubTableEnum } from '../Enums/PubSubTableEnum';
3
4
  export declare class GooglePubSubPublish {
4
5
  constructor(topicName: string);
5
6
  private _topicName;
6
- createMessages(message: object, action: PubSubActionEnum, table: PubSubTableEnum): Promise<void>;
7
+ createMessages(message: object, action: PubSubActionEnum, table: PubSubTableEnum, api?: PubSubApiEnum): Promise<void>;
7
8
  }
@@ -16,10 +16,10 @@ class GooglePubSubPublish {
16
16
  constructor(topicName) {
17
17
  this._topicName = topicName;
18
18
  }
19
- createMessages(message, action, table) {
19
+ createMessages(message, action, table, api) {
20
20
  return __awaiter(this, void 0, void 0, function* () {
21
21
  const pubSubClient = new pubsub_1.PubSub();
22
- const send = new PubSubModel_1.PubSubModel(message, action, table);
22
+ const send = new PubSubModel_1.PubSubModel(message, action, table, api);
23
23
  const topic = pubSubClient.topic(this._topicName);
24
24
  const dataSend = JSON.stringify(send);
25
25
  const data = Buffer.from(dataSend);
@@ -1,7 +1,10 @@
1
1
  /// <reference types="node" />
2
2
  import { EventEmitter } from 'events';
3
+ import { PubSubApiEnum } from '../Enums/PubSubApiEnum';
4
+ import { PubSubModel } from '../Models/PubSubModel';
3
5
  export declare class GooglePubSubSubscription {
4
6
  constructor(subscriptionName: string);
5
7
  private _subscription;
6
8
  listenMessages(eventEmitter: EventEmitter): Promise<void>;
9
+ listenMessagesV2(fn: (obj: PubSubModel) => Promise<boolean>, api: PubSubApiEnum, logger?: any): Promise<void>;
7
10
  }
@@ -20,7 +20,7 @@ class GooglePubSubSubscription {
20
20
  return __awaiter(this, void 0, void 0, function* () {
21
21
  this._subscription.on('message', (message) => {
22
22
  const data = JSON.parse(message.data.toString());
23
- const pubSubModel = new PubSubModel_1.PubSubModel(data.value, data.action, data.table);
23
+ const pubSubModel = new PubSubModel_1.PubSubModel(data.value, data.action, data.table, data.api);
24
24
  eventEmitter.emit('event', [pubSubModel, message]);
25
25
  });
26
26
  this._subscription.on('error', (error) => {
@@ -29,5 +29,34 @@ class GooglePubSubSubscription {
29
29
  });
30
30
  });
31
31
  }
32
+ listenMessagesV2(fn, api, logger) {
33
+ return __awaiter(this, void 0, void 0, function* () {
34
+ this._subscription.on('message', (message) => __awaiter(this, void 0, void 0, function* () {
35
+ const data = JSON.parse(message.data.toString());
36
+ const pubSubModel = new PubSubModel_1.PubSubModel(data.value, data.action, data.table, data.api);
37
+ if (api !== pubSubModel.api) {
38
+ yield fn(pubSubModel).then(() => {
39
+ message.ack();
40
+ }).catch((err) => {
41
+ if (err.routine === '_bt_check_unique') {
42
+ message.ack();
43
+ }
44
+ else {
45
+ if (logger) {
46
+ logger.warn('___________________________________________________');
47
+ logger.warn('Erro no PubSub (handle):' + JSON.stringify(data[0]));
48
+ logger.warn('Routine:' + err.routine);
49
+ logger.warn('Message:' + err.message);
50
+ logger.warn('Error:' + err);
51
+ }
52
+ }
53
+ });
54
+ }
55
+ else {
56
+ message.ack();
57
+ }
58
+ }));
59
+ });
60
+ }
32
61
  }
33
62
  exports.GooglePubSubSubscription = GooglePubSubSubscription;
@@ -0,0 +1,4 @@
1
+ export declare enum PubSubApiEnum {
2
+ retaguarda = "retaguarda",
3
+ app = "app"
4
+ }
@@ -0,0 +1,8 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.PubSubApiEnum = void 0;
4
+ var PubSubApiEnum;
5
+ (function (PubSubApiEnum) {
6
+ PubSubApiEnum["retaguarda"] = "retaguarda";
7
+ PubSubApiEnum["app"] = "app";
8
+ })(PubSubApiEnum = exports.PubSubApiEnum || (exports.PubSubApiEnum = {}));
@@ -1,8 +1,10 @@
1
1
  import { PubSubActionEnum } from '../Enums/PubSubActionEnum';
2
+ import { PubSubApiEnum } from '../Enums/PubSubApiEnum';
2
3
  import { PubSubTableEnum } from '../Enums/PubSubTableEnum';
3
4
  export declare class PubSubModel {
4
5
  readonly value: any;
5
6
  readonly action: PubSubActionEnum;
6
7
  readonly table: PubSubTableEnum;
7
- constructor(value: object, action: PubSubActionEnum, table: PubSubTableEnum);
8
+ readonly api: PubSubApiEnum | undefined;
9
+ constructor(value: object, action: PubSubActionEnum, table: PubSubTableEnum, api?: PubSubApiEnum);
8
10
  }
@@ -2,10 +2,11 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.PubSubModel = void 0;
4
4
  class PubSubModel {
5
- constructor(value, action, table) {
5
+ constructor(value, action, table, api) {
6
6
  this.value = value;
7
7
  this.action = action;
8
8
  this.table = table;
9
+ this.api = api;
9
10
  }
10
11
  }
11
12
  exports.PubSubModel = PubSubModel;
package/dist/index.d.ts CHANGED
@@ -1,3 +1,4 @@
1
+ export { GooglePubSubCreateSubscription } from './Class/GooglePubSubCreateSubscription';
1
2
  export { GooglePubSubPublish } from './Class/GooglePubSubPublish';
2
3
  export { GooglePubSubSubscription } from './Class/GooglePubSubSubscription';
3
4
  export { PubSubHandlerAction } from './Handlers/PubSubHandlerAction';
package/dist/index.js CHANGED
@@ -1,6 +1,8 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.CombustivelService = exports.AxiosService = exports.PriceToSale = exports.PriceToConsult = exports.AxiosModel = exports.UpdateUtil = exports.StringHelper = exports.PromiseHelper = exports.NumberHelper = exports.HashHelper = exports.DateHelper = exports.CryptHelper = exports.PubSubHandlerAction = exports.GooglePubSubSubscription = exports.GooglePubSubPublish = void 0;
3
+ exports.CombustivelService = exports.AxiosService = exports.PriceToSale = exports.PriceToConsult = exports.AxiosModel = exports.UpdateUtil = exports.StringHelper = exports.PromiseHelper = exports.NumberHelper = exports.HashHelper = exports.DateHelper = exports.CryptHelper = exports.PubSubHandlerAction = exports.GooglePubSubSubscription = exports.GooglePubSubPublish = exports.GooglePubSubCreateSubscription = void 0;
4
+ var GooglePubSubCreateSubscription_1 = require("./Class/GooglePubSubCreateSubscription");
5
+ Object.defineProperty(exports, "GooglePubSubCreateSubscription", { enumerable: true, get: function () { return GooglePubSubCreateSubscription_1.GooglePubSubCreateSubscription; } });
4
6
  var GooglePubSubPublish_1 = require("./Class/GooglePubSubPublish");
5
7
  Object.defineProperty(exports, "GooglePubSubPublish", { enumerable: true, get: function () { return GooglePubSubPublish_1.GooglePubSubPublish; } });
6
8
  var GooglePubSubSubscription_1 = require("./Class/GooglePubSubSubscription");
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "sim-node-lib",
3
- "version": "0.3.6",
3
+ "version": "0.3.7",
4
4
  "description": "Library from SIMLabs",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",
@@ -9,7 +9,8 @@
9
9
  ],
10
10
  "scripts": {
11
11
  "tsc": "tsc",
12
- "pub": "tsc && yarn publish"
12
+ "pub": "tsc && yarn publish",
13
+ "tgz": "tsc && yarn pack"
13
14
  },
14
15
  "license": "ISC",
15
16
  "dependencies": {
@@ -19,10 +20,12 @@
19
20
  "crypto-js": "^4.1.1",
20
21
  "dotenv": "^16.0.1",
21
22
  "keygenerator": "^1.0.4",
22
- "moment": "^2.29.4"
23
+ "moment": "^2.29.4",
24
+ "uuid": "^9.0.0"
23
25
  },
24
26
  "devDependencies": {
25
27
  "@types/node": "^17.0.41",
28
+ "@types/uuid": "^9.0.2",
26
29
  "typescript": "^4.7.3"
27
30
  }
28
31
  }