notification-processor 4.16.1 → 4.18.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.
@@ -24,8 +24,8 @@ function _classCallCheck(instance, Constructor) { if (!(instance instanceof Cons
24
24
  function MonitoringCenterObserver(_ref) {
25
25
  var sender = _ref.sender,
26
26
  clientId = _ref.clientId,
27
- app = _ref.app,
28
- job = _ref.job,
27
+ app1 = _ref.app,
28
+ job1 = _ref.job,
29
29
  _ref$propertiesToOmit = _ref.propertiesToOmit,
30
30
  propertiesToOmit = _ref$propertiesToOmit === undefined ? "auth" : _ref$propertiesToOmit,
31
31
  _ref$connection = _ref.connection,
@@ -39,8 +39,8 @@ function _classCallCheck(instance, Constructor) { if (!(instance instanceof Cons
39
39
  this.uploadTrackingFile = this.uploadTrackingFile.bind(this);
40
40
  this.sender = sender;
41
41
  this.clientId = clientId;
42
- this.app = app;
43
- this.job = job;
42
+ this.app = app1;
43
+ this.job = job1;
44
44
  this.propertiesToOmit = propertiesToOmit;
45
45
  this.deliveryStream = deliveryStream;
46
46
  this.firehose = new AWS.Firehose({ accessKeyId: accessKeyId, secretAccessKey: secretAccessKey, region: region });
@@ -85,17 +85,17 @@ function _classCallCheck(instance, Constructor) { if (!(instance instanceof Cons
85
85
  Data: JSON.stringify(record)
86
86
  }
87
87
  };
88
- debug("Uploading file " + record.event + " to firehose delivery stream " + uploadParams.DeliveryStreamName);
88
+ debug("Uploading file " + record.event + "/" + record.id + " to firehose delivery stream " + uploadParams.DeliveryStreamName);
89
89
  __uploadToFirehose = function __uploadToFirehose() {
90
90
  return _this2.uploadToFirehose(uploadParams);
91
91
  };
92
92
  return retry(__uploadToFirehose, {
93
93
  throw_original: true
94
94
  }).tap(function () {
95
- return debug("Uploaded file " + record.event + " to firehose delivery stream " + uploadParams.DeliveryStreamName);
95
+ return debug("Uploaded file " + record.event + "/" + record.id + " to firehose delivery stream " + uploadParams.DeliveryStreamName);
96
96
  }).catch(function (e) {
97
97
  // We'll do nothing with this error
98
- return debug("Error uploading file " + record.event + " to firehose delivery stream " + uploadParams.DeliveryStreamName + " %o", e);
98
+ return debug("Error uploading file " + record.event + "/" + record.id + " to firehose delivery stream " + uploadParams.DeliveryStreamName + " %o", e);
99
99
  });
100
100
  });
101
101
  }
@@ -104,30 +104,36 @@ function _classCallCheck(instance, Constructor) { if (!(instance instanceof Cons
104
104
  value: function _mapper(id, notification, err, eventType) {
105
105
  var _this3 = this;
106
106
 
107
- var ref, theRequest;
108
- if (!(notification != null ? (ref = notification.message) != null ? ref.EventId : void 0 : void 0)) {
109
- return Promise.resolve({});
110
- }
111
- theRequest = _.get(err, "detail.request") || _.get(err, "cause.detail.request");
112
- return Promise.props({
113
- resource: Promise.method(this.sender.resource)(notification),
114
- user: Promise.method(this.sender.user)(notification)
115
- }).then(function (_ref3) {
116
- var resource = _ref3.resource,
117
- user = _ref3.user;
118
-
119
- var now, ref1, ref2;
107
+ return Promise.method(this.sender.monitoringCenterFields.bind(this.sender))(notification).then(function (_ref3) {
108
+ var eventType = _ref3.eventType,
109
+ resource = _ref3.resource,
110
+ companyId = _ref3.companyId,
111
+ userId = _ref3.userId,
112
+ externalReference = _ref3.externalReference,
113
+ userExternalReference = _ref3.userExternalReference,
114
+ eventId = _ref3.eventId,
115
+ eventTimestamp = _ref3.eventTimestamp,
116
+ parentEventId = _ref3.parentEventId,
117
+ app = _ref3.app,
118
+ job = _ref3.job;
119
+
120
+ var now, theRequest;
121
+ if (!eventId) {
122
+ return Promise.resolve({});
123
+ }
124
+ theRequest = _.get(err, "detail.request") || _.get(err, "cause.detail.request");
120
125
  now = new Date();
121
126
  return {
122
127
  id: id,
123
128
  executionId: id,
124
- app: parseInt(_this3.clientId),
125
- type: "service-bus",
126
- company: "" + user,
127
- user: null, //TODO: Chequear si podemos completar esto
128
- event: notification != null ? (ref1 = notification.message) != null ? ref1.EventId : void 0 : void 0,
129
- parent: (notification != null ? (ref2 = notification.message) != null ? ref2.ParentEventId : void 0 : void 0) || null,
130
- externalreference: null,
129
+ app: app || parseInt(_this3.clientId) || null,
130
+ type: eventType,
131
+ company: companyId,
132
+ user: userId,
133
+ event: eventId,
134
+ parent: parentEventId,
135
+ externalreference: externalReference,
136
+ userexternalreference: userExternalReference,
131
137
  timestamp: now.getTime(),
132
138
  date: now.toISOString(),
133
139
  year: moment(now).format('YYYY'),
@@ -140,15 +146,15 @@ function _classCallCheck(instance, Constructor) { if (!(instance instanceof Cons
140
146
  app: _this3.app,
141
147
  error: _.omit(err, ["detail.request", "cause.detail.request"]),
142
148
  request: _.omit(theRequest, _.castArray(_this3.propertiesToOmit).concat("auth")),
143
- type: _.get(err, "type", "unknown_error"),
149
+ type: err && _.get(err, "type", "unknown"),
144
150
  tags: _.get(err, "tags", [])
145
151
  }),
146
152
  status: eventType,
147
153
  resource: resource,
148
- integration: _this3.app + "|" + _this3.job,
154
+ integration: _this3.app + "|" + (job || _this3.job),
149
155
  // Generic app fields
150
- event_timestamp: null, //TODO
151
- output_message: null, //TODO
156
+ event_timestamp: eventTimestamp || now.getTime(),
157
+ output_message: _.get(err, "type"),
152
158
  user_settings_version: null, //TODO
153
159
  env_version: null, //TODO
154
160
  code_version: null //TODO
@@ -2,13 +2,13 @@
2
2
 
3
3
  // Generated by CoffeeScript 2.7.0
4
4
  (function () {
5
- var JobProcessor, RequestProcessor, _;
5
+ var JobProcessor, RequestAsyncProcessor, _;
6
6
 
7
7
  _ = require("lodash");
8
8
 
9
9
  JobProcessor = require("./job.processor");
10
10
 
11
- RequestProcessor = require("../request.async.processor");
11
+ RequestAsyncProcessor = require("../request.async.processor");
12
12
 
13
13
  module.exports = function (_ref) {
14
14
  var apiUrl = _ref.apiUrl,
@@ -19,7 +19,7 @@
19
19
 
20
20
  var jobProcesor;
21
21
  jobProcesor = new JobProcessor({
22
- processor: RequestProcessor({
22
+ processor: RequestAsyncProcessor({
23
23
  apiUrl: apiUrl,
24
24
  fullResponse: true
25
25
  }),
@@ -6,7 +6,7 @@ function _classCallCheck(instance, Constructor) { if (!(instance instanceof Cons
6
6
 
7
7
  // Generated by CoffeeScript 2.7.0
8
8
  (function () {
9
- var DEFAULT_NOTIFICATIONS_API_ASYNC_URL, HOUR, NOTIFICATIONS_API_JOBS_CACHE_TTL, NOTIFICATIONS_API_MASTER_TOKEN, NOTIFICATIONS_API_STOPPED_JOB_CACHE_TTL, NodeCache, NotificationsApi, Promise, _, jobsCache, requestPromise, retry, stoppedJobsCache;
9
+ var DEFAULT_NOTIFICATIONS_API_ASYNC_URL, DEFAULT_NOTIFICATIONS_API_URL, HOUR, NOTIFICATIONS_API_JOBS_CACHE_TTL, NOTIFICATIONS_API_MASTER_TOKEN, NOTIFICATIONS_API_STOPPED_JOB_CACHE_TTL, NodeCache, NotificationsApi, Promise, _, jobsCache, requestPromise, retry, stoppedJobsCache;
10
10
 
11
11
  _ = require("lodash");
12
12
 
@@ -26,6 +26,8 @@ function _classCallCheck(instance, Constructor) { if (!(instance instanceof Cons
26
26
 
27
27
  DEFAULT_NOTIFICATIONS_API_ASYNC_URL = process.env.DEFAULT_NOTIFICATIONS_API_ASYNC_URL || "https://apps.producteca.com/aws/notifications-api-async";
28
28
 
29
+ DEFAULT_NOTIFICATIONS_API_URL = process.env.NOTIFICATIONS_API_URL || "https://apps.producteca.com/notifications-api/api";
30
+
29
31
  HOUR = 60 * 60;
30
32
 
31
33
  //Para minimizar las requests a notifications-api, cachea unos segundos el estado del job
@@ -40,9 +42,10 @@ function _classCallCheck(instance, Constructor) { if (!(instance instanceof Cons
40
42
 
41
43
  NotificationsApi = function () {
42
44
  function NotificationsApi(_ref) {
43
- var notificationApiUrl = _ref.notificationApiUrl,
44
- token = _ref.token,
45
- jobId = _ref.jobId,
45
+ var _ref$notificationApiU = _ref.notificationApiUrl,
46
+ notificationApiUrl = _ref$notificationApiU === undefined ? DEFAULT_NOTIFICATIONS_API_URL : _ref$notificationApiU,
47
+ token1 = _ref.token,
48
+ jobId1 = _ref.jobId,
46
49
  _ref$notificationApiA = _ref.notificationApiAsyncUrl,
47
50
  notificationApiAsyncUrl = _ref$notificationApiA === undefined ? DEFAULT_NOTIFICATIONS_API_ASYNC_URL : _ref$notificationApiA;
48
51
 
@@ -52,15 +55,17 @@ function _classCallCheck(instance, Constructor) { if (!(instance instanceof Cons
52
55
  this.success = this.success.bind(this);
53
56
  this.fail = this.fail.bind(this);
54
57
  this.jobIsStopped = this.jobIsStopped.bind(this);
58
+ this.jobName = this.jobName.bind(this);
55
59
  this._jobIsStopped = this._jobIsStopped.bind(this);
60
+ this.fetchJob = this.fetchJob.bind(this);
56
61
  this._fetchJob = this._fetchJob.bind(this);
57
62
  this._doFetchJob = this._doFetchJob.bind(this);
58
63
  this._retryViaAsyncOrIgnore = this._retryViaAsyncOrIgnore.bind(this);
59
64
  this._makeRequest = this._makeRequest.bind(this);
60
65
  this._shouldUseCachedValue = this._shouldUseCachedValue.bind(this);
61
66
  this.notificationApiUrl = notificationApiUrl;
62
- this.token = token;
63
- this.jobId = jobId;
67
+ this.token = token1;
68
+ this.jobId = jobId1;
64
69
  this.notificationApiAsyncUrl = notificationApiAsyncUrl;
65
70
  if (_.startsWith(this.token, 'Basic') && !_.isEmpty(NOTIFICATIONS_API_MASTER_TOKEN)) {
66
71
  companyId = _.first(Buffer.from(_.get(this.token.split(" "), "1"), 'base64').toString().split(":"));
@@ -133,39 +138,50 @@ function _classCallCheck(instance, Constructor) { if (!(instance instanceof Cons
133
138
  }
134
139
  });
135
140
  }
141
+ }, {
142
+ key: "jobName",
143
+ value: function jobName(jobId, token) {
144
+ return this._fetchJob(jobId, token).then(function (job) {
145
+ return job.name;
146
+ });
147
+ }
136
148
  }, {
137
149
  key: "_jobIsStopped",
138
- value: function _jobIsStopped() {
139
- return this._fetchJob().then(function (job) {
150
+ value: function _jobIsStopped(jobId, token) {
151
+ return this._fetchJob(jobId, token).then(function (job) {
140
152
  return job.stopped;
141
153
  });
142
154
  }
155
+ }, {
156
+ key: "fetchJob",
157
+ value: function fetchJob(aJobId, aToken) {
158
+ return this._fetchJob(aJobId, aToken);
159
+ }
143
160
  }, {
144
161
  key: "_fetchJob",
145
- value: function _fetchJob() {
146
- var _this4 = this;
147
-
148
- var cachedJob;
149
- cachedJob = jobsCache.get(this.jobId);
162
+ value: function _fetchJob(aJobId, aToken) {
163
+ var cachedJob, jobId;
164
+ jobId = aJobId || this.jobId;
165
+ cachedJob = jobsCache.get(jobId);
150
166
  if (this._shouldUseCachedValue(cachedJob)) {
151
167
  return Promise.resolve(cachedJob);
152
168
  }
153
- return this._doFetchJob().tap(function (job) {
154
- return jobsCache.set(_this4.jobId, job);
169
+ return this._doFetchJob(jobId, aToken).tap(function (job) {
170
+ return jobsCache.set(jobId, job);
155
171
  });
156
172
  }
157
173
  }, {
158
174
  key: "_doFetchJob",
159
- value: function _doFetchJob() {
160
- var _this5 = this;
175
+ value: function _doFetchJob(jobId, token) {
176
+ var _this4 = this;
161
177
 
162
178
  var __fetchJob;
163
179
  __fetchJob = function __fetchJob() {
164
180
  return requestPromise({
165
- url: _this5.notificationApiUrl + "/jobs/" + _this5.jobId,
181
+ url: _this4.notificationApiUrl + "/jobs/" + (jobId || _this4.jobId),
166
182
  method: "GET",
167
183
  headers: {
168
- authorization: _this5.token
184
+ authorization: token || _this4.token
169
185
  },
170
186
  json: true
171
187
  }).promise();
@@ -22,10 +22,10 @@ function _classCallCheck(instance, Constructor) { if (!(instance instanceof Cons
22
22
 
23
23
  _createClass(MaxRetriesProcessor, [{
24
24
  key: "process",
25
- value: function process(notification, context) {
25
+ value: function process(notification, context, executionId) {
26
26
  var _this = this;
27
27
 
28
- return this.processor(notification, context).tap(function (it) {
28
+ return this.processor(notification, context, executionId).tap(function (it) {
29
29
  return _this._onSuccess_(notification, it);
30
30
  }).catch(function (err) {
31
31
  if (_this._shouldRetry_(notification, err)) {
@@ -18,17 +18,21 @@
18
18
  };
19
19
 
20
20
  builderRequest = function builderRequest(apiUrl, fullResponse) {
21
- return function (_ref2) {
21
+ return function (_ref2, context, executionId) {
22
22
  var message = _ref2.message;
23
23
 
24
- var Body, HeadersForRequest, Method, Resource, headers, json, url;
24
+ var Body, HeadersForRequest, JobId, Method, Resource, headers, json, url;
25
25
  Resource = message.Resource;
26
26
  Method = message.Method;
27
27
  Body = message.Body;
28
28
  HeadersForRequest = message.HeadersForRequest;
29
+ JobId = message.JobId;
29
30
 
30
31
  json = (Body != null ? Body.length : void 0) > 0 ? JSON.parse(Body) : true;
31
32
  headers = _normalizeHeaders(HeadersForRequest);
33
+ if (JobId) {
34
+ headers['x-producteca-event-id'] = JobId + "/" + executionId;
35
+ }
32
36
  url = headers.Domain || apiUrl;
33
37
  return {
34
38
  url: "" + url + Resource,
@@ -4,38 +4,55 @@ var _slicedToArray = function () { function sliceIterator(arr, i) { var _arr = [
4
4
 
5
5
  // Generated by CoffeeScript 2.7.0
6
6
  (function () {
7
- var OAuthApi, Promise, _, _companyId;
7
+ var NotificationsApi, OAuthApi, Promise, _, _companyId, _companyIdFromBasicToken, _headerValue, notificationsApi, retry, uuid;
8
8
 
9
9
  _ = require("lodash");
10
10
 
11
11
  OAuthApi = require("../services/oAuthApi");
12
12
 
13
+ NotificationsApi = require("../processors/job/notification.api");
14
+
13
15
  Promise = require("bluebird");
14
16
 
15
- _companyId = function _companyId(method, token) {
17
+ retry = require("bluebird-retry");
18
+
19
+ uuid = require("uuid/v4");
20
+
21
+ notificationsApi = new NotificationsApi({});
22
+
23
+ _companyIdFromBasicToken = function _companyIdFromBasicToken(token) {
16
24
  var decoded;
17
- if (method !== "Basic") {
18
- return new OAuthApi(token).companyId();
19
- }
20
25
  decoded = Buffer.from(token, "base64").toString();
21
26
  return _.split(decoded, ":")[0];
22
27
  };
23
28
 
29
+ _companyId = function _companyId(method, token) {
30
+ if (method !== "Basic") {
31
+ return new OAuthApi(token).scopes().get("companyId");
32
+ }
33
+ return _companyIdFromBasicToken(token);
34
+ };
35
+
36
+ _headerValue = function _headerValue(headers, key, defaultValue) {
37
+ var header;
38
+ header = _.find(headers, {
39
+ Key: key
40
+ });
41
+ return _.get(header, "Value", defaultValue);
42
+ };
43
+
24
44
  module.exports = {
25
45
  user: function user(_ref) {
26
46
  var HeadersForRequest = _ref.message.HeadersForRequest;
27
47
 
28
- var auth, method, token;
29
- auth = _.find(HeadersForRequest, {
30
- Key: "Authorization"
31
- });
48
+ var method, token;
32
49
 
33
- var _$get$split = _.get(auth, "Value", "").split(" ");
50
+ var _headerValue$split = _headerValue(HeadersForRequest, "Authorization", "").split(" ");
34
51
 
35
- var _$get$split2 = _slicedToArray(_$get$split, 2);
52
+ var _headerValue$split2 = _slicedToArray(_headerValue$split, 2);
36
53
 
37
- method = _$get$split2[0];
38
- token = _$get$split2[1];
54
+ method = _headerValue$split2[0];
55
+ token = _headerValue$split2[1];
39
56
 
40
57
  return _companyId(method, token);
41
58
  },
@@ -47,6 +64,74 @@ var _slicedToArray = function () { function sliceIterator(arr, i) { var _arr = [
47
64
  } else {
48
65
  return _.get(message, "Resource");
49
66
  }
67
+ },
68
+ monitoringCenterFields: function monitoringCenterFields(notification) {
69
+ var _this = this;
70
+
71
+ var __job, __scopes, fullToken, method, token;
72
+ fullToken = _headerValue(notification.message.HeadersForRequest, "Authorization", "");
73
+
74
+ var _fullToken$split = fullToken.split(" ");
75
+
76
+ var _fullToken$split2 = _slicedToArray(_fullToken$split, 2);
77
+
78
+ method = _fullToken$split2[0];
79
+ token = _fullToken$split2[1];
80
+
81
+ __scopes = function __scopes() {
82
+ if (_(method.toLowerCase()).includes("bearer")) {
83
+ return retry(function () {
84
+ return new OAuthApi(token).scopes();
85
+ });
86
+ }
87
+ return Promise.resolve({
88
+ id: null,
89
+ appId: null,
90
+ companyId: _companyIdFromBasicToken(token)
91
+ });
92
+ };
93
+ __job = function __job() {
94
+ if (notification.message.JobId && fullToken) {
95
+ return notificationsApi.fetchJob(notification.message.JobId, fullToken).catchReturn().then(function (it) {
96
+ return it || {};
97
+ });
98
+ } else {
99
+ return Promise.resolve({});
100
+ }
101
+ };
102
+ return Promise.props({
103
+ scopes: __scopes(),
104
+ job: __job()
105
+ }).then(function (_ref3) {
106
+ var _ref3$scopes = _ref3.scopes,
107
+ id = _ref3$scopes.id,
108
+ companyId = _ref3$scopes.companyId,
109
+ appId = _ref3$scopes.appId,
110
+ _ref3$job = _ref3.job,
111
+ name = _ref3$job.name,
112
+ creationDate = _ref3$job.creationDate;
113
+
114
+ var eventId, jobCreationDate, messageInsertionTime, ref, ref1, ref2;
115
+ eventId = notification.message.JobId || _headerValue(notification.message.HeadersForRequest, "x-producteca-event-id", null) || _headerValue(notification.message.HeadersForRequest, "X-producteca-event-id", null) || (notification != null ? (ref = notification.meta) != null ? ref.messageId : void 0 : void 0) || uuid();
116
+ if (creationDate) {
117
+ jobCreationDate = new Date(creationDate).getTime();
118
+ }
119
+ if (notification != null ? (ref1 = notification.meta) != null ? ref1.insertionTime : void 0 : void 0) {
120
+ messageInsertionTime = new Date(notification != null ? (ref2 = notification.meta) != null ? ref2.insertionTime : void 0 : void 0).getTime();
121
+ }
122
+ return Promise.props({
123
+ eventType: 'http',
124
+ resource: _this.resource(notification),
125
+ companyId: companyId,
126
+ userId: id,
127
+ app: parseInt(appId),
128
+ job: name,
129
+ externalReference: null,
130
+ eventId: eventId,
131
+ eventTimestamp: jobCreationDate || messageInsertionTime,
132
+ parentEventId: null
133
+ });
134
+ });
50
135
  }
51
136
  };
52
137
  }).call(undefined);
@@ -2,6 +2,14 @@
2
2
 
3
3
  // Generated by CoffeeScript 2.7.0
4
4
  (function () {
5
+ var Promise, UserIdTranslator, uuid;
6
+
7
+ uuid = require("uuid/v4");
8
+
9
+ Promise = require("bluebird");
10
+
11
+ UserIdTranslator = require("../services/userIdTranslator");
12
+
5
13
  module.exports = {
6
14
  user: function user(_ref) {
7
15
  var user_id = _ref.message.user_id;
@@ -12,6 +20,27 @@
12
20
  var _resource = _ref2.message.resource;
13
21
 
14
22
  return _resource;
23
+ },
24
+ monitoringCenterFields: function monitoringCenterFields(notification) {
25
+ var _this = this;
26
+
27
+ return new UserIdTranslator().translate(this.user(notification)).then(function (_ref3) {
28
+ var app = _ref3.app,
29
+ companyId = _ref3.companyId;
30
+
31
+ var ref, ref1, ref2;
32
+ return Promise.props({
33
+ eventType: 'http',
34
+ resource: null,
35
+ app: app,
36
+ companyId: companyId,
37
+ userId: null,
38
+ externalReference: _this.resource(notification),
39
+ eventId: (notification != null ? (ref = notification.message) != null ? ref._id : void 0 : void 0) || uuid(),
40
+ eventTimestamp: (notification != null ? (ref1 = notification.meta) != null ? ref1.insertionTime : void 0 : void 0) ? new Date(notification != null ? (ref2 = notification.meta) != null ? ref2.insertionTime : void 0 : void 0).getTime() : void 0,
41
+ parentEventId: null
42
+ });
43
+ });
15
44
  }
16
45
  };
17
46
  }).call(undefined);
@@ -2,6 +2,10 @@
2
2
 
3
3
  // Generated by CoffeeScript 2.7.0
4
4
  (function () {
5
+ var Promise;
6
+
7
+ Promise = require("bluebird");
8
+
5
9
  module.exports = {
6
10
  user: function user(_ref) {
7
11
  var CompanyId = _ref.message.CompanyId;
@@ -12,6 +16,19 @@
12
16
  var ResourceId = _ref2.message.ResourceId;
13
17
 
14
18
  return ResourceId;
19
+ },
20
+ monitoringCenterFields: function monitoringCenterFields(notification) {
21
+ var ref, ref1, ref2, ref3, ref4, ref5, ref6, ref7;
22
+ return Promise.props({
23
+ eventType: 'service-bus',
24
+ resource: this.resource(notification),
25
+ companyId: this.user(notification),
26
+ userId: (notification != null ? (ref = notification.message) != null ? ref.UserId : void 0 : void 0) || (notification != null ? (ref1 = notification.message) != null ? ref1.User : void 0 : void 0),
27
+ externalReference: null,
28
+ eventId: notification != null ? (ref2 = notification.message) != null ? ref2.EventId : void 0 : void 0,
29
+ eventTimestamp: (notification != null ? (ref3 = notification.meta) != null ? ref3.insertionTime : void 0 : void 0) || (notification != null ? (ref4 = notification.message) != null ? ref4.Sent : void 0 : void 0) ? new Date((notification != null ? (ref5 = notification.meta) != null ? ref5.insertionTime : void 0 : void 0) || (notification != null ? (ref6 = notification.message) != null ? ref6.Sent : void 0 : void 0)).getTime() : void 0,
30
+ parentEventId: notification != null ? (ref7 = notification.message) != null ? ref7.ParentEventId : void 0 : void 0
31
+ });
15
32
  }
16
33
  };
17
34
  }).call(undefined);
@@ -6,32 +6,55 @@ function _classCallCheck(instance, Constructor) { if (!(instance instanceof Cons
6
6
 
7
7
  // Generated by CoffeeScript 2.7.0
8
8
  (function () {
9
- var AuthApi, OAUTH_API_URL, request;
9
+ var NodeCache, OAUTH_API_URL, OAuthApi, Promise, request, translatedCache;
10
10
 
11
11
  request = require("request-promise");
12
12
 
13
- OAUTH_API_URL = process.env.OAUTH_API_URL || "https://apps.producteca.com/oauth";
13
+ Promise = require("bluebird");
14
14
 
15
- module.exports = AuthApi = function () {
16
- function AuthApi(accessToken) {
17
- _classCallCheck(this, AuthApi);
15
+ NodeCache = require("node-cache");
18
16
 
19
- this.companyId = this.companyId.bind(this);
20
- this._me = this._me.bind(this);
17
+ translatedCache = new NodeCache({
18
+ stdTTL: 0,
19
+ checkperiod: 0
20
+ });
21
+
22
+ OAUTH_API_URL = process.env.OAUTH_API_URL || "https://apps.producteca.com/oauth"; //TODO: Revisar que esta variable este seteada en todos lados con la interna, seguramente no
23
+
24
+ module.exports = OAuthApi = function () {
25
+ function OAuthApi(accessToken) {
26
+ _classCallCheck(this, OAuthApi);
27
+
28
+ this.scopes = this.scopes.bind(this);
29
+ this._scopes = this._scopes.bind(this);
21
30
  this._doRequest = this._doRequest.bind(this);
22
31
  this.accessToken = accessToken;
23
32
  }
24
33
 
25
- _createClass(AuthApi, [{
26
- key: "companyId",
27
- value: function companyId() {
28
- return this._me().get("id");
34
+ _createClass(OAuthApi, [{
35
+ key: "scopes",
36
+ value: function scopes() {
37
+ var _this = this;
38
+
39
+ var cachedValue;
40
+ cachedValue = translatedCache.get(this.accessToken);
41
+ if (cachedValue) {
42
+ return Promise.resolve(cachedValue);
43
+ }
44
+ return this._scopes().tap(function (_ref) {
45
+ var id = _ref.id,
46
+ companyId = _ref.companyId,
47
+ appId = _ref.appId;
48
+
49
+ return translatedCache.set(_this.accessToken, { id: id, companyId: companyId, appId: appId });
50
+ });
29
51
  }
30
52
  }, {
31
- key: "_me",
32
- value: function _me() {
33
- return this._doRequest("get", "/users/me", {
34
- access_token: this.accessToken
53
+ key: "_scopes",
54
+ value: function _scopes() {
55
+ return this._doRequest("get", "/scopes", {
56
+ access_token: this.accessToken,
57
+ fromNotificationProcessor: true
35
58
  });
36
59
  }
37
60
  }, {
@@ -49,6 +72,6 @@ function _classCallCheck(instance, Constructor) { if (!(instance instanceof Cons
49
72
  }
50
73
  }]);
51
74
 
52
- return AuthApi;
75
+ return OAuthApi;
53
76
  }();
54
77
  }).call(undefined);