notification-processor 4.11.0 → 4.12.0

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/lib/index.js CHANGED
@@ -8,7 +8,8 @@
8
8
  LoggerObserver: require("./observers/logger.observer"),
9
9
  DelayObserver: require("./observers/delay.observer"),
10
10
  DeadLetterSucceeded: require("./observers/deadLetterSucceeded.observer"),
11
- IncidentsApi: require("./observers/incidentsApi.observer")
11
+ IncidentsApi: require("./observers/incidentsApi.observer"),
12
+ MonitoringCenter: require("./observers/monitoringCenter.observer")
12
13
  },
13
14
  Processors: {
14
15
  DeadLetterProcessor: require("./processors/deadletter.processor"),
@@ -0,0 +1,147 @@
1
+ "use strict";
2
+
3
+ var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }();
4
+
5
+ function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
6
+
7
+ // Generated by CoffeeScript 2.7.0
8
+ (function () {
9
+ var AWS, MonitoringCenterObserver, Promise, _, debug, retry;
10
+
11
+ _ = require("lodash");
12
+
13
+ Promise = require("bluebird");
14
+
15
+ retry = require("bluebird-retry");
16
+
17
+ debug = require("debug")("notification-processor:observers:monitor-center");
18
+
19
+ AWS = require("aws-sdk");
20
+
21
+ module.exports = MonitoringCenterObserver = function () {
22
+ function MonitoringCenterObserver(_ref) {
23
+ var sender = _ref.sender,
24
+ clientId = _ref.clientId,
25
+ app = _ref.app,
26
+ job = _ref.job,
27
+ _ref$propertiesToOmit = _ref.propertiesToOmit,
28
+ propertiesToOmit = _ref$propertiesToOmit === undefined ? "auth" : _ref$propertiesToOmit,
29
+ _ref$connection = _ref.connection,
30
+ accessKeyId = _ref$connection.accessKeyId,
31
+ secretAccessKey = _ref$connection.secretAccessKey,
32
+ monitoringCenterBucket = _ref$connection.monitoringCenterBucket,
33
+ region = _ref$connection.region;
34
+
35
+ _classCallCheck(this, MonitoringCenterObserver);
36
+
37
+ this.uploadTrackingFile = this.uploadTrackingFile.bind(this);
38
+ this.sender = sender;
39
+ this.clientId = clientId;
40
+ this.app = app;
41
+ this.job = job;
42
+ this.propertiesToOmit = propertiesToOmit;
43
+ this.s3 = new AWS.S3({ accessKeyId: accessKeyId, secretAccessKey: secretAccessKey, region: region });
44
+ this.bucket = monitoringCenterBucket;
45
+ this.uploadToS3 = Promise.promisify(this.s3.upload).bind(this.s3);
46
+ }
47
+
48
+ _createClass(MonitoringCenterObserver, [{
49
+ key: "listenTo",
50
+ value: function listenTo(observable) {
51
+ var _this = this;
52
+
53
+ observable.on("unsuccessful_non_retryable", function (payload) {
54
+ return _this.uploadTrackingFile(payload, "unsuccessful_non_retryable");
55
+ });
56
+ observable.on("unsuccessful", function (payload) {
57
+ return _this.uploadTrackingFile(payload, "unsuccessful");
58
+ });
59
+ observable.on("started", function (payload) {
60
+ return _this.uploadTrackingFile(payload, "started");
61
+ });
62
+ observable.on("finished", function (payload) {
63
+ return _this.uploadTrackingFile(payload, "finished");
64
+ });
65
+ return observable.on("success", function (payload) {
66
+ return _this.uploadTrackingFile(payload, "success");
67
+ });
68
+ }
69
+ }, {
70
+ key: "uploadTrackingFile",
71
+ value: function uploadTrackingFile(_ref2, eventType) {
72
+ var _this2 = this;
73
+
74
+ var id = _ref2.id,
75
+ notification = _ref2.notification,
76
+ error = _ref2.error;
77
+
78
+ return this._mapper(id, notification, error, eventType).then(function (_ref3) {
79
+ var key = _ref3.key,
80
+ body = _ref3.body;
81
+
82
+ var __uploadToS3, uploadParams;
83
+ if (!key || !body) {
84
+ return;
85
+ }
86
+ uploadParams = {
87
+ Bucket: _this2.bucket,
88
+ Key: key,
89
+ Body: body
90
+ };
91
+ debug("Uploading file " + uploadParams.Key + " to bucket " + uploadParams.Bucket);
92
+ __uploadToS3 = function __uploadToS3() {
93
+ return _this2.uploadToS3(uploadParams);
94
+ };
95
+ return retry(__uploadToS3, {
96
+ throw_original: true
97
+ }).tap(function () {
98
+ return debug("Uploaded file " + uploadParams.Key + " to bucket " + uploadParams.Bucket);
99
+ }).catch(function (e) {
100
+ // We'll do nothing with this error
101
+ return debug("Error uploading file " + uploadParams.Key + " to bucket " + uploadParams.Bucket + " %o", e);
102
+ });
103
+ });
104
+ }
105
+ }, {
106
+ key: "_mapper",
107
+ value: function _mapper(id, notification, err, eventType) {
108
+ var _this3 = this;
109
+
110
+ var ref, theRequest;
111
+ if (!(notification != null ? (ref = notification.message) != null ? ref.EventId : void 0 : void 0)) {
112
+ return Promise.resolve({});
113
+ }
114
+ theRequest = _.get(err, "detail.request") || _.get(err, "cause.detail.request");
115
+ return Promise.props({
116
+ resource: Promise.method(this.sender.resource)(notification),
117
+ user: Promise.method(this.sender.user)(notification)
118
+ }).then(function (_ref4) {
119
+ var resource = _ref4.resource,
120
+ user = _ref4.user;
121
+
122
+ var ref1, ref2;
123
+ return {
124
+ key: user + "/" + notification.message.EventId + "/" + _this3.app + "|" + _this3.job + "|" + eventType,
125
+ body: JSON.stringify({
126
+ eventId: notification != null ? (ref1 = notification.message) != null ? ref1.EventId : void 0 : void 0,
127
+ parentEventId: (notification != null ? (ref2 = notification.message) != null ? ref2.ParentEventId : void 0 : void 0) || null,
128
+ date: new Date().toISOString(),
129
+ resource: "" + resource,
130
+ notification: notification,
131
+ user: "" + user,
132
+ clientId: _this3.clientId,
133
+ job: _this3.job,
134
+ app: _this3.app,
135
+ error: _.omit(err, ["detail.request", "cause.detail.request"]),
136
+ request: _.omit(theRequest, _.castArray(_this3.propertiesToOmit).concat("auth")),
137
+ type: _.get(err, "type", "unknown_error"),
138
+ tags: _.get(err, "tags", [])
139
+ })
140
+ };
141
+ });
142
+ }
143
+ }]);
144
+
145
+ return MonitoringCenterObserver;
146
+ }();
147
+ }).call(undefined);