@apipass/event-notification 0.0.41 → 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.
@@ -2,10 +2,12 @@ import { AWSEventNotificationOptions } from "./event-notification-options";
2
2
  import { EventNotificationServiceFactory } from './event-notification-service-factory';
3
3
  export declare class AWSEventNotificationService implements EventNotificationServiceFactory {
4
4
  private readonly logger;
5
- private region;
6
- private accountId;
7
- private environment;
5
+ private readonly region;
6
+ private readonly accountId;
7
+ private readonly environment;
8
8
  constructor(options: AWSEventNotificationOptions);
9
- notifyEvent(eventName: string, content?: any): void;
9
+ notifyEvent(eventName: string, content?: any): Promise<void>;
10
+ private createTopic;
11
+ private sendMessage;
10
12
  static getTopicArn(eventName: string, region: string, accountId: string, environment: string): string;
11
13
  }
@@ -11,13 +11,22 @@ var __metadata = (this && this.__metadata) || function (k, v) {
11
11
  var __param = (this && this.__param) || function (paramIndex, decorator) {
12
12
  return function (target, key) { decorator(target, key, paramIndex); }
13
13
  };
14
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
15
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
16
+ return new (P || (P = Promise))(function (resolve, reject) {
17
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
18
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
19
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
20
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
21
+ });
22
+ };
14
23
  var AWSEventNotificationService_1;
15
24
  Object.defineProperty(exports, "__esModule", { value: true });
16
25
  exports.AWSEventNotificationService = void 0;
17
- const sns = require("@aws-sdk/client-sns");
18
26
  const common_1 = require("@nestjs/common");
19
27
  const event_notification_constants_1 = require("./event-notification-constants");
20
28
  const event_notification_options_1 = require("./event-notification-options");
29
+ const client_sns_1 = require("@aws-sdk/client-sns");
21
30
  let AWSEventNotificationService = AWSEventNotificationService_1 = class AWSEventNotificationService {
22
31
  constructor(options) {
23
32
  this.logger = new common_1.Logger(AWSEventNotificationService_1.name);
@@ -26,9 +35,39 @@ let AWSEventNotificationService = AWSEventNotificationService_1 = class AWSEvent
26
35
  this.environment = options.environment;
27
36
  }
28
37
  notifyEvent(eventName, content) {
29
- const TopicArn = AWSEventNotificationService_1.getTopicArn(eventName, this.region, this.accountId, this.environment);
30
- new sns.SNSClient({ region: this.region }).send(new sns.PublishCommand({ TopicArn: TopicArn, Message: JSON.stringify(content) }));
31
- this.logger.warn(`Message send to topic: ${TopicArn}`);
38
+ return __awaiter(this, void 0, void 0, function* () {
39
+ try {
40
+ yield this.sendMessage(eventName, content);
41
+ }
42
+ catch (e) {
43
+ if (e.Error.Code === 'NotFound') {
44
+ yield this.createTopic(eventName);
45
+ yield this.sendMessage(eventName, content);
46
+ }
47
+ else {
48
+ throw e;
49
+ }
50
+ }
51
+ });
52
+ }
53
+ createTopic(eventName) {
54
+ return __awaiter(this, void 0, void 0, function* () {
55
+ const params = {
56
+ Name: `${eventName}-${this.environment}`,
57
+ };
58
+ const snsClient = new client_sns_1.SNSClient({ region: this.region });
59
+ yield snsClient.send(new client_sns_1.CreateTopicCommand(params));
60
+ });
61
+ }
62
+ sendMessage(eventName, content) {
63
+ return __awaiter(this, void 0, void 0, function* () {
64
+ const TopicArn = AWSEventNotificationService_1.getTopicArn(eventName, this.region, this.accountId, this.environment);
65
+ yield new client_sns_1.SNSClient({ region: this.region }).send(new client_sns_1.PublishCommand({
66
+ TopicArn: TopicArn,
67
+ Message: JSON.stringify(content)
68
+ }));
69
+ this.logger.warn(`Message send to topic: ${TopicArn}`);
70
+ });
32
71
  }
33
72
  static getTopicArn(eventName, region, accountId, environment) {
34
73
  return `arn:aws:sns:${region}:${accountId}:${eventName}-${environment}`;
@@ -1 +1 @@
1
- {"version":3,"file":"aws-event-notification.service.js","sourceRoot":"","sources":["../src/aws-event-notification.service.ts"],"names":[],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;QACxD,CAAC;KAAA;IAEa,WAAW,CAAC,SAAiB,EAAE,OAAY;;YACrD,MAAM,QAAQ,GAAG,6BAA2B,CAAC,WAAW,CAAC,SAAS,EAAE,IAAI,CAAC,MAAM,EAAE,IAAI,CAAC,SAAS,EAAE,IAAI,CAAC,WAAW,CAAC,CAAA;YAClH,MAAM,IAAI,sBAAS,CAAC,EAAC,MAAM,EAAE,IAAI,CAAC,MAAM,EAAC,CAAC,CAAC,IAAI,CAAC,IAAI,2BAAc,CAAC;gBAC/D,QAAQ,EAAE,QAAQ;gBAClB,OAAO,EAAE,IAAI,CAAC,SAAS,CAAC,OAAO,CAAC;aACnC,CAAC,CAAC,CAAA;YACH,IAAI,CAAC,MAAM,CAAC,IAAI,CAAC,0BAA0B,QAAQ,EAAE,CAAC,CAAC;QAC3D,CAAC;KAAA;IAED,MAAM,CAAC,WAAW,CAAC,SAAiB,EAAE,MAAc,EAAE,SAAiB,EAAE,WAAmB;QACxF,OAAO,eAAe,MAAM,IAAI,SAAS,IAAI,SAAS,IAAI,WAAW,EAAE,CAAA;IAC3E,CAAC;CAEJ,CAAA;AAjDY,kEAA2B;sCAA3B,2BAA2B;IADvC,IAAA,mBAAU,GAAE;IAQI,WAAA,IAAA,eAAM,EAAC,wDAAyB,CAAC,CAAA;qCAAU,wDAA2B;GAP1E,2BAA2B,CAiDvC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@apipass/event-notification",
3
- "version": "0.0.41",
3
+ "version": "0.0.43",
4
4
  "description": "> TODO: description",
5
5
  "author": "Nathan Lemos <nathan@apipass.com.br>",
6
6
  "license": "ISC",
@@ -25,5 +25,5 @@
25
25
  "scripts": {
26
26
  "tsc": "tsc"
27
27
  },
28
- "gitHead": "89f71a0e9ea46ce8a8eabdccde105f5011b0c37b"
28
+ "gitHead": "8ce59fd18775c40bda029846b1553d86c6345d63"
29
29
  }