notification-processor 5.0.0 → 5.0.2
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/CHANGELOG.md +6 -0
- package/package.json +10 -3
- package/.github/ISSUE_TEMPLATE.md +0 -30
- package/.github/PULL_REQUEST_TEMPLATE.md +0 -3
- package/lib/exceptions/ignored.error.js +0 -27
- package/lib/exceptions/non.retryable.js +0 -27
- package/lib/index.js +0 -25
- package/lib/observers/delay.levels.js +0 -32
- package/lib/observers/incidentsApi.observer.js +0 -109
- package/lib/observers/logger.observer.js +0 -59
- package/lib/observers/monitoringCenter.observer.js +0 -234
- package/lib/observers/redis.observer.js +0 -90
- package/lib/processor.builder.js +0 -134
- package/lib/processor.js +0 -132
- package/lib/processors/deadletter.processor.js +0 -45
- package/lib/processors/job/index.js +0 -38
- package/lib/processors/job/job.processor.js +0 -150
- package/lib/processors/job/notification.api.js +0 -237
- package/lib/processors/maxRetries.processor.js +0 -88
- package/lib/processors/request.async.processor.js +0 -56
- package/lib/processors/request.processor.js +0 -114
- package/lib/processors/requestWithRetries.async.processor.js +0 -22
- package/lib/senders/async.producteca.sender.js +0 -145
- package/lib/senders/index.js +0 -10
- package/lib/senders/meli.sender.js +0 -46
- package/lib/senders/producteca.sender.js +0 -34
- package/lib/services/oAuthApi.js +0 -77
- package/lib/services/redis.js +0 -16
- package/lib/services/userIdTranslator.js +0 -111
- package/lib/sources/aws.sqs.source.js +0 -30
- package/lib/sources/index.js +0 -12
- package/lib/sources/queue.source.js +0 -26
- package/lib/sources/service.bus.source.js +0 -26
- package/lib/sources/table.source.js +0 -20
- package/lib/sources/unknown.source.js +0 -15
- package/lib/specHelpers/fixture.js +0 -29
- package/lib/specHelpers/redis.observer.mock.js +0 -65
- package/notification-processor.sublime-project +0 -14
|
@@ -1,237 +0,0 @@
|
|
|
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 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
|
-
|
|
11
|
-
_ = require("lodash");
|
|
12
|
-
|
|
13
|
-
requestPromise = require("request-promise");
|
|
14
|
-
|
|
15
|
-
retry = require("bluebird-retry");
|
|
16
|
-
|
|
17
|
-
Promise = require("bluebird");
|
|
18
|
-
|
|
19
|
-
NodeCache = require("node-cache");
|
|
20
|
-
|
|
21
|
-
NOTIFICATIONS_API_JOBS_CACHE_TTL = parseInt(process.env.NOTIFICATIONS_API_JOBS_CACHE_TTL) || 5;
|
|
22
|
-
|
|
23
|
-
NOTIFICATIONS_API_STOPPED_JOB_CACHE_TTL = parseInt(process.env.NOTIFICATIONS_API_STOPPED_JOB_CACHE_TTL) || 2;
|
|
24
|
-
|
|
25
|
-
NOTIFICATIONS_API_MASTER_TOKEN = process.env.NOTIFICATIONS_API_MASTER_TOKEN;
|
|
26
|
-
|
|
27
|
-
DEFAULT_NOTIFICATIONS_API_ASYNC_URL = process.env.DEFAULT_NOTIFICATIONS_API_ASYNC_URL || "https://apps.producteca.com/aws/notifications-api-async";
|
|
28
|
-
|
|
29
|
-
DEFAULT_NOTIFICATIONS_API_URL = process.env.NOTIFICATIONS_API_URL || "https://apps.producteca.com/notifications-api/api";
|
|
30
|
-
|
|
31
|
-
HOUR = 60 * 60;
|
|
32
|
-
|
|
33
|
-
//Para minimizar las requests a notifications-api, cachea unos segundos el estado del job
|
|
34
|
-
jobsCache = new NodeCache({
|
|
35
|
-
stdTTL: NOTIFICATIONS_API_JOBS_CACHE_TTL
|
|
36
|
-
});
|
|
37
|
-
|
|
38
|
-
//A nivel dominio, podria ser cache sin TTL porque un job stoppeado queda asi para siempre. Pero se pone TTL de 2h para que luego libere la memoria
|
|
39
|
-
stoppedJobsCache = new NodeCache({
|
|
40
|
-
stdTTL: NOTIFICATIONS_API_STOPPED_JOB_CACHE_TTL * HOUR
|
|
41
|
-
});
|
|
42
|
-
|
|
43
|
-
NotificationsApi = function () {
|
|
44
|
-
function NotificationsApi(_ref) {
|
|
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,
|
|
49
|
-
_ref$notificationApiA = _ref.notificationApiAsyncUrl,
|
|
50
|
-
notificationApiAsyncUrl = _ref$notificationApiA === undefined ? DEFAULT_NOTIFICATIONS_API_ASYNC_URL : _ref$notificationApiA;
|
|
51
|
-
|
|
52
|
-
_classCallCheck(this, NotificationsApi);
|
|
53
|
-
|
|
54
|
-
var companyId;
|
|
55
|
-
this.success = this.success.bind(this);
|
|
56
|
-
this.fail = this.fail.bind(this);
|
|
57
|
-
this.jobIsStopped = this.jobIsStopped.bind(this);
|
|
58
|
-
this.jobName = this.jobName.bind(this);
|
|
59
|
-
this._jobIsStopped = this._jobIsStopped.bind(this);
|
|
60
|
-
this.fetchJob = this.fetchJob.bind(this);
|
|
61
|
-
this._fetchJob = this._fetchJob.bind(this);
|
|
62
|
-
this._doFetchJob = this._doFetchJob.bind(this);
|
|
63
|
-
this._retryViaAsyncOrIgnore = this._retryViaAsyncOrIgnore.bind(this);
|
|
64
|
-
this._makeRequest = this._makeRequest.bind(this);
|
|
65
|
-
this._shouldUseCachedValue = this._shouldUseCachedValue.bind(this);
|
|
66
|
-
this.notificationApiUrl = notificationApiUrl;
|
|
67
|
-
this.token = token1;
|
|
68
|
-
this.jobId = jobId1;
|
|
69
|
-
this.notificationApiAsyncUrl = notificationApiAsyncUrl;
|
|
70
|
-
if (_.startsWith(this.token, 'Basic') && !_.isEmpty(NOTIFICATIONS_API_MASTER_TOKEN)) {
|
|
71
|
-
companyId = _.first(Buffer.from(_.get(this.token.split(" "), "1"), 'base64').toString().split(":"));
|
|
72
|
-
this.token = "Basic " + new Buffer(companyId + ":" + NOTIFICATIONS_API_MASTER_TOKEN).toString("base64");
|
|
73
|
-
}
|
|
74
|
-
}
|
|
75
|
-
|
|
76
|
-
_createClass(NotificationsApi, [{
|
|
77
|
-
key: "success",
|
|
78
|
-
value: function success(response, options) {
|
|
79
|
-
var _this = this;
|
|
80
|
-
|
|
81
|
-
var __makeRequest, __retryRequest, statusCode;
|
|
82
|
-
statusCode = response.statusCode;
|
|
83
|
-
|
|
84
|
-
__makeRequest = function __makeRequest() {
|
|
85
|
-
return _this._makeRequest({
|
|
86
|
-
statusCode: statusCode,
|
|
87
|
-
success: true
|
|
88
|
-
}, options);
|
|
89
|
-
};
|
|
90
|
-
__retryRequest = function __retryRequest() {
|
|
91
|
-
return _this.success(response, {
|
|
92
|
-
useAsyncApi: true
|
|
93
|
-
});
|
|
94
|
-
};
|
|
95
|
-
return this._retryViaAsyncOrIgnore(__makeRequest, __retryRequest, options);
|
|
96
|
-
}
|
|
97
|
-
}, {
|
|
98
|
-
key: "fail",
|
|
99
|
-
value: function fail(response, options) {
|
|
100
|
-
var _this2 = this;
|
|
101
|
-
|
|
102
|
-
var __makeRequest, __retryRequest, error, message, request, statusCode;
|
|
103
|
-
statusCode = response.statusCode;
|
|
104
|
-
error = response.error;
|
|
105
|
-
request = response.request;
|
|
106
|
-
|
|
107
|
-
message = _.get(error, "message");
|
|
108
|
-
error = _.get(error, "type");
|
|
109
|
-
__makeRequest = function __makeRequest() {
|
|
110
|
-
return _this2._makeRequest({
|
|
111
|
-
statusCode: statusCode,
|
|
112
|
-
success: false,
|
|
113
|
-
message: message,
|
|
114
|
-
error: error,
|
|
115
|
-
request: request
|
|
116
|
-
}, options);
|
|
117
|
-
};
|
|
118
|
-
__retryRequest = function __retryRequest() {
|
|
119
|
-
return _this2.fail(response, {
|
|
120
|
-
useAsyncApi: true
|
|
121
|
-
});
|
|
122
|
-
};
|
|
123
|
-
return this._retryViaAsyncOrIgnore(__makeRequest, __retryRequest, options);
|
|
124
|
-
}
|
|
125
|
-
}, {
|
|
126
|
-
key: "jobIsStopped",
|
|
127
|
-
value: function jobIsStopped() {
|
|
128
|
-
var _this3 = this;
|
|
129
|
-
|
|
130
|
-
var cachedStoppedJob;
|
|
131
|
-
cachedStoppedJob = stoppedJobsCache.get(this.jobId);
|
|
132
|
-
if (this._shouldUseCachedValue(cachedStoppedJob)) {
|
|
133
|
-
return Promise.resolve(cachedStoppedJob);
|
|
134
|
-
}
|
|
135
|
-
return this._jobIsStopped().tap(function (jobIsStopped) {
|
|
136
|
-
if (jobIsStopped) {
|
|
137
|
-
return stoppedJobsCache.set(_this3.jobId, jobIsStopped);
|
|
138
|
-
}
|
|
139
|
-
});
|
|
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
|
-
}
|
|
148
|
-
}, {
|
|
149
|
-
key: "_jobIsStopped",
|
|
150
|
-
value: function _jobIsStopped(jobId, token) {
|
|
151
|
-
return this._fetchJob(jobId, token).then(function (job) {
|
|
152
|
-
return job.stopped;
|
|
153
|
-
});
|
|
154
|
-
}
|
|
155
|
-
}, {
|
|
156
|
-
key: "fetchJob",
|
|
157
|
-
value: function fetchJob(aJobId, aToken) {
|
|
158
|
-
return this._fetchJob(aJobId, aToken);
|
|
159
|
-
}
|
|
160
|
-
}, {
|
|
161
|
-
key: "_fetchJob",
|
|
162
|
-
value: function _fetchJob(aJobId, aToken) {
|
|
163
|
-
var cachedJob, jobId;
|
|
164
|
-
jobId = aJobId || this.jobId;
|
|
165
|
-
cachedJob = jobsCache.get(jobId);
|
|
166
|
-
if (this._shouldUseCachedValue(cachedJob)) {
|
|
167
|
-
return Promise.resolve(cachedJob);
|
|
168
|
-
}
|
|
169
|
-
return this._doFetchJob(jobId, aToken).tap(function (job) {
|
|
170
|
-
return jobsCache.set(jobId, job);
|
|
171
|
-
});
|
|
172
|
-
}
|
|
173
|
-
}, {
|
|
174
|
-
key: "_doFetchJob",
|
|
175
|
-
value: function _doFetchJob(jobId, token) {
|
|
176
|
-
var _this4 = this;
|
|
177
|
-
|
|
178
|
-
var __fetchJob;
|
|
179
|
-
__fetchJob = function __fetchJob() {
|
|
180
|
-
return requestPromise({
|
|
181
|
-
url: _this4.notificationApiUrl + "/jobs/" + (jobId || _this4.jobId),
|
|
182
|
-
method: "GET",
|
|
183
|
-
headers: {
|
|
184
|
-
authorization: token || _this4.token
|
|
185
|
-
},
|
|
186
|
-
json: true
|
|
187
|
-
}).promise();
|
|
188
|
-
};
|
|
189
|
-
return retry(__fetchJob, {
|
|
190
|
-
throw_original: true
|
|
191
|
-
});
|
|
192
|
-
}
|
|
193
|
-
}, {
|
|
194
|
-
key: "_retryViaAsyncOrIgnore",
|
|
195
|
-
value: function _retryViaAsyncOrIgnore(makeRequest, retryRequest) {
|
|
196
|
-
var options = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
|
|
197
|
-
|
|
198
|
-
return retry(makeRequest, {
|
|
199
|
-
throw_original: true,
|
|
200
|
-
max_tries: 3
|
|
201
|
-
}).catch(function (e) {
|
|
202
|
-
if (options.useAsyncApi) {
|
|
203
|
-
throw e;
|
|
204
|
-
}
|
|
205
|
-
console.log("Error sending status to notifications-api. Retrying via notifications-api-async");
|
|
206
|
-
return retryRequest();
|
|
207
|
-
}).catchReturn();
|
|
208
|
-
}
|
|
209
|
-
}, {
|
|
210
|
-
key: "_makeRequest",
|
|
211
|
-
value: function _makeRequest(body) {
|
|
212
|
-
var _ref2 = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {},
|
|
213
|
-
useAsyncApi = _ref2.useAsyncApi;
|
|
214
|
-
|
|
215
|
-
var url;
|
|
216
|
-
url = useAsyncApi ? this.notificationApiAsyncUrl : this.notificationApiUrl;
|
|
217
|
-
return requestPromise({
|
|
218
|
-
url: url + "/jobs/" + this.jobId + "/operations",
|
|
219
|
-
method: "POST",
|
|
220
|
-
headers: {
|
|
221
|
-
authorization: this.token
|
|
222
|
-
},
|
|
223
|
-
json: body
|
|
224
|
-
});
|
|
225
|
-
}
|
|
226
|
-
}, {
|
|
227
|
-
key: "_shouldUseCachedValue",
|
|
228
|
-
value: function _shouldUseCachedValue(value) {
|
|
229
|
-
return process.env.NODE_ENV !== "test" && value != null;
|
|
230
|
-
}
|
|
231
|
-
}]);
|
|
232
|
-
|
|
233
|
-
return NotificationsApi;
|
|
234
|
-
}();
|
|
235
|
-
|
|
236
|
-
module.exports = NotificationsApi;
|
|
237
|
-
}).call(undefined);
|
|
@@ -1,88 +0,0 @@
|
|
|
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 IgnoredError, MaxRetriesProcessor, Promise;
|
|
10
|
-
|
|
11
|
-
Promise = require("bluebird");
|
|
12
|
-
|
|
13
|
-
IgnoredError = require("../exceptions/ignored.error");
|
|
14
|
-
|
|
15
|
-
module.exports = MaxRetriesProcessor = function () {
|
|
16
|
-
function MaxRetriesProcessor(_ref) {
|
|
17
|
-
var processor = _ref.processor,
|
|
18
|
-
_ref$maxRetries = _ref.maxRetries,
|
|
19
|
-
maxRetries = _ref$maxRetries === undefined ? 3 : _ref$maxRetries;
|
|
20
|
-
|
|
21
|
-
_classCallCheck(this, MaxRetriesProcessor);
|
|
22
|
-
|
|
23
|
-
this._onIgnoredError_ = this._onIgnoredError_.bind(this);
|
|
24
|
-
this.processor = processor;
|
|
25
|
-
this.maxRetries = maxRetries;
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
_createClass(MaxRetriesProcessor, [{
|
|
29
|
-
key: "process",
|
|
30
|
-
value: function process(notification, context, executionId) {
|
|
31
|
-
var _this = this;
|
|
32
|
-
|
|
33
|
-
return this.processor(notification, context, executionId).tap(function (it) {
|
|
34
|
-
return _this._onSuccess_(notification, it);
|
|
35
|
-
}).catch(function (err) {
|
|
36
|
-
if (_this._isIgnoredError_(err)) {
|
|
37
|
-
return _this._onIgnoredError_(notification, err);
|
|
38
|
-
}
|
|
39
|
-
if (_this._shouldRetry_(notification, err)) {
|
|
40
|
-
throw _this._sanitizeError_(err);
|
|
41
|
-
}
|
|
42
|
-
return _this._onMaxRetryExceeded_(notification, err);
|
|
43
|
-
});
|
|
44
|
-
}
|
|
45
|
-
}, {
|
|
46
|
-
key: "_shouldRetry_",
|
|
47
|
-
value: function _shouldRetry_(_ref2, err) {
|
|
48
|
-
var _ref2$meta$dequeueCou = _ref2.meta.dequeueCount,
|
|
49
|
-
dequeueCount = _ref2$meta$dequeueCou === undefined ? 0 : _ref2$meta$dequeueCou;
|
|
50
|
-
|
|
51
|
-
return dequeueCount < this.maxRetries;
|
|
52
|
-
}
|
|
53
|
-
}, {
|
|
54
|
-
key: "_onSuccess_",
|
|
55
|
-
value: function _onSuccess_(notification, result) {
|
|
56
|
-
throw new Error("subclass responsability");
|
|
57
|
-
}
|
|
58
|
-
}, {
|
|
59
|
-
key: "_sanitizeError_",
|
|
60
|
-
value: function _sanitizeError_(err) {
|
|
61
|
-
throw new Error("subclass responsability");
|
|
62
|
-
}
|
|
63
|
-
}, {
|
|
64
|
-
key: "_onMaxRetryExceeded_",
|
|
65
|
-
value: function _onMaxRetryExceeded_(notification, err) {
|
|
66
|
-
throw new Error("subclass responsability");
|
|
67
|
-
}
|
|
68
|
-
}, {
|
|
69
|
-
key: "_onIgnoredError_",
|
|
70
|
-
value: function _onIgnoredError_(notification, err) {
|
|
71
|
-
var _this2 = this;
|
|
72
|
-
|
|
73
|
-
return Promise.try(function () {
|
|
74
|
-
return _this2._onSuccess_(notification, err);
|
|
75
|
-
}).tap(function () {
|
|
76
|
-
throw err;
|
|
77
|
-
});
|
|
78
|
-
}
|
|
79
|
-
}, {
|
|
80
|
-
key: "_isIgnoredError_",
|
|
81
|
-
value: function _isIgnoredError_(err) {
|
|
82
|
-
return err instanceof IgnoredError;
|
|
83
|
-
}
|
|
84
|
-
}]);
|
|
85
|
-
|
|
86
|
-
return MaxRetriesProcessor;
|
|
87
|
-
}();
|
|
88
|
-
}).call(undefined);
|
|
@@ -1,56 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
// Generated by CoffeeScript 2.7.0
|
|
4
|
-
(function () {
|
|
5
|
-
var RequestProcessor, _, _normalizeHeaders, builderRequest;
|
|
6
|
-
|
|
7
|
-
_ = require("lodash");
|
|
8
|
-
|
|
9
|
-
RequestProcessor = require("./request.processor");
|
|
10
|
-
|
|
11
|
-
_normalizeHeaders = function _normalizeHeaders(headers) {
|
|
12
|
-
return _(headers).map(function (_ref) {
|
|
13
|
-
var Key = _ref.Key,
|
|
14
|
-
Value = _ref.Value;
|
|
15
|
-
|
|
16
|
-
return [Key, Value];
|
|
17
|
-
}).fromPairs().value();
|
|
18
|
-
};
|
|
19
|
-
|
|
20
|
-
builderRequest = function builderRequest(apiUrl, fullResponse) {
|
|
21
|
-
return function (_ref2, context, executionId) {
|
|
22
|
-
var message = _ref2.message;
|
|
23
|
-
|
|
24
|
-
var Body, HeadersForRequest, JobId, Method, Resource, headers, json, url;
|
|
25
|
-
Resource = message.Resource;
|
|
26
|
-
Method = message.Method;
|
|
27
|
-
Body = message.Body;
|
|
28
|
-
HeadersForRequest = message.HeadersForRequest;
|
|
29
|
-
JobId = message.JobId;
|
|
30
|
-
|
|
31
|
-
json = (Body != null ? Body.length : void 0) > 0 ? JSON.parse(Body) : true;
|
|
32
|
-
headers = _normalizeHeaders(HeadersForRequest);
|
|
33
|
-
if (JobId) {
|
|
34
|
-
headers['x-producteca-event-id'] = JobId + "/" + executionId;
|
|
35
|
-
}
|
|
36
|
-
url = headers.Domain || apiUrl;
|
|
37
|
-
return {
|
|
38
|
-
url: "" + url + Resource,
|
|
39
|
-
method: Method,
|
|
40
|
-
headers: headers,
|
|
41
|
-
json: json,
|
|
42
|
-
resolveWithFullResponse: fullResponse
|
|
43
|
-
};
|
|
44
|
-
};
|
|
45
|
-
};
|
|
46
|
-
|
|
47
|
-
module.exports = function (_ref3) {
|
|
48
|
-
var apiUrl = _ref3.apiUrl,
|
|
49
|
-
_ref3$fullResponse = _ref3.fullResponse,
|
|
50
|
-
fullResponse = _ref3$fullResponse === undefined ? false : _ref3$fullResponse,
|
|
51
|
-
silentErrors = _ref3.silentErrors,
|
|
52
|
-
nonRetryable = _ref3.nonRetryable;
|
|
53
|
-
|
|
54
|
-
return RequestProcessor(builderRequest(apiUrl, fullResponse), { silentErrors: silentErrors, nonRetryable: nonRetryable });
|
|
55
|
-
};
|
|
56
|
-
}).call(undefined);
|
|
@@ -1,114 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
// Generated by CoffeeScript 2.7.0
|
|
4
|
-
(function () {
|
|
5
|
-
var IgnoredError, MESSAGE_PROPERTIES, NonRetryableError, Promise, RequestError, StatusCodeError, _, __isIncludedInStatusesError, _safeParse, _type, errorConditions, httpStatus, request;
|
|
6
|
-
|
|
7
|
-
_ = require("lodash");
|
|
8
|
-
|
|
9
|
-
NonRetryableError = require("../exceptions/non.retryable");
|
|
10
|
-
|
|
11
|
-
IgnoredError = require("../exceptions/ignored.error");
|
|
12
|
-
|
|
13
|
-
Promise = require("bluebird");
|
|
14
|
-
|
|
15
|
-
request = require("request-promise");
|
|
16
|
-
|
|
17
|
-
var _require = require("request-promise/errors");
|
|
18
|
-
|
|
19
|
-
StatusCodeError = _require.StatusCodeError;
|
|
20
|
-
RequestError = _require.RequestError;
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
httpStatus = require("http").STATUS_CODES;
|
|
24
|
-
|
|
25
|
-
MESSAGE_PROPERTIES = ["reason", "error.error", "error.code", "code", "error"];
|
|
26
|
-
|
|
27
|
-
_safeParse = function _safeParse(raw) {
|
|
28
|
-
if (_.isObject(raw)) {
|
|
29
|
-
return raw;
|
|
30
|
-
} else {
|
|
31
|
-
try {
|
|
32
|
-
return JSON.parse(raw);
|
|
33
|
-
} catch (error1) {}
|
|
34
|
-
}
|
|
35
|
-
};
|
|
36
|
-
|
|
37
|
-
_type = function _type(statusCode, error) {
|
|
38
|
-
return _(MESSAGE_PROPERTIES).map(function (key) {
|
|
39
|
-
return _.get(error, key);
|
|
40
|
-
}).concat([_.toLower(httpStatus[statusCode])]).filter(_.isString).compact().head();
|
|
41
|
-
};
|
|
42
|
-
|
|
43
|
-
errorConditions = {
|
|
44
|
-
client: function client(it) {
|
|
45
|
-
return it >= 400 && it < 500;
|
|
46
|
-
},
|
|
47
|
-
server: function server(it) {
|
|
48
|
-
return it >= 500;
|
|
49
|
-
}
|
|
50
|
-
};
|
|
51
|
-
|
|
52
|
-
__isIncludedInStatusesError = function __isIncludedInStatusesError(conditions) {
|
|
53
|
-
return function (err) {
|
|
54
|
-
var statusCode;
|
|
55
|
-
statusCode = _.get(err, "detail.response.statusCode");
|
|
56
|
-
return _(conditions).map(function (it) {
|
|
57
|
-
return _.get(errorConditions, it, _.partial(_.isEqual, it));
|
|
58
|
-
}).some(function (condition) {
|
|
59
|
-
return condition(statusCode);
|
|
60
|
-
});
|
|
61
|
-
};
|
|
62
|
-
};
|
|
63
|
-
|
|
64
|
-
module.exports = function (requestGenerator) {
|
|
65
|
-
var _ref = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {},
|
|
66
|
-
_ref$silentErrors = _ref.silentErrors,
|
|
67
|
-
silentErrors = _ref$silentErrors === undefined ? [] : _ref$silentErrors,
|
|
68
|
-
_ref$nonRetryable = _ref.nonRetryable,
|
|
69
|
-
nonRetryable = _ref$nonRetryable === undefined ? [] : _ref$nonRetryable;
|
|
70
|
-
|
|
71
|
-
return function (notification, context, executionId) {
|
|
72
|
-
return Promise.method(requestGenerator)(notification, context, executionId).then(function (options) {
|
|
73
|
-
return request(options).promise().catch(RequestError, function (_ref2) {
|
|
74
|
-
var cause = _ref2.cause;
|
|
75
|
-
|
|
76
|
-
throw {
|
|
77
|
-
type: cause.code,
|
|
78
|
-
detail: cause
|
|
79
|
-
};
|
|
80
|
-
}).catch(StatusCodeError, function (_ref3) {
|
|
81
|
-
var statusCode = _ref3.statusCode,
|
|
82
|
-
error = _ref3.error;
|
|
83
|
-
|
|
84
|
-
var safeError, type;
|
|
85
|
-
safeError = _safeParse(error);
|
|
86
|
-
type = _type(statusCode, safeError);
|
|
87
|
-
throw {
|
|
88
|
-
type: type,
|
|
89
|
-
message: _.get(safeError, "error.message") || _.get(safeError, "message") || type,
|
|
90
|
-
detail: {
|
|
91
|
-
response: {
|
|
92
|
-
statusCode: statusCode,
|
|
93
|
-
body: safeError
|
|
94
|
-
}
|
|
95
|
-
},
|
|
96
|
-
tags: safeError != null ? safeError.tags : void 0
|
|
97
|
-
};
|
|
98
|
-
}).tapCatch(function (err) {
|
|
99
|
-
return _.defaultsDeep(err, {
|
|
100
|
-
type: "unknown",
|
|
101
|
-
message: "unknown",
|
|
102
|
-
detail: {
|
|
103
|
-
request: options
|
|
104
|
-
}
|
|
105
|
-
});
|
|
106
|
-
}).catch(__isIncludedInStatusesError(silentErrors), function (err) {
|
|
107
|
-
throw new IgnoredError("An error has ocurred in that request but should be ignored", _.omit(err, "response"));
|
|
108
|
-
}).catch(__isIncludedInStatusesError(nonRetryable), function (err) {
|
|
109
|
-
throw new NonRetryableError("An error has ocurred in that request", _.omit(err, "response"));
|
|
110
|
-
});
|
|
111
|
-
});
|
|
112
|
-
};
|
|
113
|
-
};
|
|
114
|
-
}).call(undefined);
|
|
@@ -1,22 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
// Generated by CoffeeScript 2.7.0
|
|
4
|
-
(function () {
|
|
5
|
-
var MaxRetriesProcessor, RequestAsyncProcessor, _;
|
|
6
|
-
|
|
7
|
-
_ = require("lodash");
|
|
8
|
-
|
|
9
|
-
RequestAsyncProcessor = require("./request.async.processor");
|
|
10
|
-
|
|
11
|
-
MaxRetriesProcessor = require("./deadletter.processor");
|
|
12
|
-
|
|
13
|
-
module.exports = function (args) {
|
|
14
|
-
var maxRetries, processor, withMaxRetries;
|
|
15
|
-
var _args$maxRetries = args.maxRetries;
|
|
16
|
-
maxRetries = _args$maxRetries === undefined ? 5 : _args$maxRetries;
|
|
17
|
-
|
|
18
|
-
processor = RequestAsyncProcessor(args);
|
|
19
|
-
withMaxRetries = new MaxRetriesProcessor({ processor: processor, maxRetries: maxRetries });
|
|
20
|
-
return withMaxRetries.process.bind(withMaxRetries);
|
|
21
|
-
};
|
|
22
|
-
}).call(undefined);
|
|
@@ -1,145 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
var _slicedToArray = function () { function sliceIterator(arr, i) { var _arr = []; var _n = true; var _d = false; var _e = undefined; try { for (var _i = arr[Symbol.iterator](), _s; !(_n = (_s = _i.next()).done); _n = true) { _arr.push(_s.value); if (i && _arr.length === i) break; } } catch (err) { _d = true; _e = err; } finally { try { if (!_n && _i["return"]) _i["return"](); } finally { if (_d) throw _e; } } return _arr; } return function (arr, i) { if (Array.isArray(arr)) { return arr; } else if (Symbol.iterator in Object(arr)) { return sliceIterator(arr, i); } else { throw new TypeError("Invalid attempt to destructure non-iterable instance"); } }; }();
|
|
4
|
-
|
|
5
|
-
// Generated by CoffeeScript 2.7.0
|
|
6
|
-
(function () {
|
|
7
|
-
var NotificationsApi, OAuthApi, Promise, _, _companyId, _companyIdFromBasicToken, _headerValue, notificationsApi, retry, uuid;
|
|
8
|
-
|
|
9
|
-
_ = require("lodash");
|
|
10
|
-
|
|
11
|
-
OAuthApi = require("../services/oAuthApi");
|
|
12
|
-
|
|
13
|
-
NotificationsApi = require("../processors/job/notification.api");
|
|
14
|
-
|
|
15
|
-
Promise = require("bluebird");
|
|
16
|
-
|
|
17
|
-
retry = require("bluebird-retry");
|
|
18
|
-
|
|
19
|
-
uuid = require("uuid/v4");
|
|
20
|
-
|
|
21
|
-
notificationsApi = new NotificationsApi({});
|
|
22
|
-
|
|
23
|
-
_companyIdFromBasicToken = function _companyIdFromBasicToken(token) {
|
|
24
|
-
var decoded;
|
|
25
|
-
decoded = Buffer.from(token, "base64").toString();
|
|
26
|
-
return _.split(decoded, ":")[0];
|
|
27
|
-
};
|
|
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
|
-
|
|
44
|
-
module.exports = {
|
|
45
|
-
user: function user(_ref) {
|
|
46
|
-
var HeadersForRequest = _ref.message.HeadersForRequest;
|
|
47
|
-
|
|
48
|
-
var method, token;
|
|
49
|
-
|
|
50
|
-
var _headerValue$split = _headerValue(HeadersForRequest, "Authorization", "").split(" ");
|
|
51
|
-
|
|
52
|
-
var _headerValue$split2 = _slicedToArray(_headerValue$split, 2);
|
|
53
|
-
|
|
54
|
-
method = _headerValue$split2[0];
|
|
55
|
-
token = _headerValue$split2[1];
|
|
56
|
-
|
|
57
|
-
return _companyId(method, token);
|
|
58
|
-
},
|
|
59
|
-
resource: function resource(_ref2, resourceGetter) {
|
|
60
|
-
var message = _ref2.message;
|
|
61
|
-
|
|
62
|
-
if (_.isFunction(resourceGetter)) {
|
|
63
|
-
return resourceGetter(message);
|
|
64
|
-
} else {
|
|
65
|
-
return _.get(message, "Resource");
|
|
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, headersWithoutAuth, 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
|
-
headersWithoutAuth = _.reject(notification.message.HeadersForRequest, function (_ref4) {
|
|
123
|
-
var Key = _ref4.Key;
|
|
124
|
-
|
|
125
|
-
return (Key != null ? Key.toLowerCase() : void 0) === 'authorization';
|
|
126
|
-
});
|
|
127
|
-
return Promise.props({
|
|
128
|
-
eventType: 'http',
|
|
129
|
-
resource: _this.resource(notification),
|
|
130
|
-
companyId: companyId,
|
|
131
|
-
userId: id,
|
|
132
|
-
app: parseInt(appId),
|
|
133
|
-
job: name,
|
|
134
|
-
externalReference: null,
|
|
135
|
-
eventId: eventId,
|
|
136
|
-
eventTimestamp: jobCreationDate || messageInsertionTime,
|
|
137
|
-
parentEventId: null,
|
|
138
|
-
partialMessage: _.assign({}, notification.message, {
|
|
139
|
-
HeadersForRequest: headersWithoutAuth
|
|
140
|
-
})
|
|
141
|
-
});
|
|
142
|
-
});
|
|
143
|
-
}
|
|
144
|
-
};
|
|
145
|
-
}).call(undefined);
|
package/lib/senders/index.js
DELETED
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
// Generated by CoffeeScript 2.7.0
|
|
4
|
-
(function () {
|
|
5
|
-
module.exports = {
|
|
6
|
-
MeliSender: require("./meli.sender"),
|
|
7
|
-
ProductecaSender: require("./producteca.sender"),
|
|
8
|
-
AsyncProductecaSender: require("./async.producteca.sender")
|
|
9
|
-
};
|
|
10
|
-
}).call(undefined);
|