heimdall-api-platform 1.0.5 → 1.0.6
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/dist/clients/http-client.js +1 -0
- package/dist/commons-cache.js +1 -0
- package/dist/commons-const.js +1 -0
- package/dist/commons-elasticsearch.js +1 -0
- package/dist/commons-errors.js +1 -0
- package/dist/commons-opensearch.js +1 -0
- package/dist/commons-splunk.js +1 -0
- package/dist/commons-util.js +1 -0
- package/dist/default-routes-docs.js +1 -0
- package/dist/default-routes-pos.js +1 -0
- package/dist/default-routes-pre.js +1 -0
- package/dist/environment.js +1 -0
- package/dist/factory/api-gateway.js +1 -0
- package/dist/factory/client-factory.js +1 -0
- package/dist/factory/function-factory.js +1 -0
- package/dist/factory/operation-flow-factory.js +1 -0
- package/dist/factory/server-factory.js +1 -0
- package/dist/factory/transformation-function-factory.js +1 -0
- package/dist/handle-route.js +1 -0
- package/dist/index.js +2 -0
- package/dist/jwt-util.js +1 -0
- package/dist/license/license-service.js +1 -0
- package/dist/models/base-context.js +1 -0
- package/dist/models/elastic-index-data.js +1 -0
- package/dist/models/flow-context.js +1 -0
- package/dist/models/flow-indexed.js +1 -0
- package/dist/models/operation-function-indexed.js +1 -0
- package/dist/models/operation-function-transformation-indexed.js +1 -0
- package/dist/models/operation-http-indexed.js +1 -0
- package/dist/models/operation-mock-indexed.js +1 -0
- package/dist/models/route-context.js +1 -0
- package/dist/models/security-route.js +1 -0
- package/dist/models/service-context.js +1 -0
- package/dist/models/service-group.js +1 -0
- package/dist/models/service-route.js +1 -0
- package/dist/models/splunk-data.js +1 -0
- package/dist/operations/abstract-operation.js +1 -0
- package/dist/operations/function.js +1 -0
- package/dist/operations/http.js +1 -0
- package/dist/operations/mock.js +1 -0
- package/dist/operations/monitor-check.js +1 -0
- package/dist/orchestration-flow.js +1 -0
- package/dist/router.js +1 -0
- package/dist/security-validation.js +1 -0
- package/dist/services/server.js +1 -0
- package/dist/services/template-monitorcheck-route.js +1 -0
- package/package.json +4 -4
- package/lib/clients/http-client.js +0 -296
- package/lib/commons-cache.js +0 -185
- package/lib/commons-const.js +0 -203
- package/lib/commons-elasticsearch.js +0 -49
- package/lib/commons-errors.js +0 -278
- package/lib/commons-opensearch.js +0 -37
- package/lib/commons-splunk.js +0 -105
- package/lib/commons-util.js +0 -669
- package/lib/default-routes-docs.js +0 -141
- package/lib/default-routes-pos.js +0 -111
- package/lib/default-routes-pre.js +0 -151
- package/lib/environment.js +0 -81
- package/lib/factory/api-gateway.js +0 -12
- package/lib/factory/client-factory.js +0 -41
- package/lib/factory/function-factory.js +0 -40
- package/lib/factory/operation-flow-factory.js +0 -64
- package/lib/factory/server-factory.js +0 -15
- package/lib/factory/transformation-function-factory.js +0 -47
- package/lib/handle-route.js +0 -472
- package/lib/index.js +0 -50
- package/lib/jwt-util.js +0 -38
- package/lib/license/license-service.js +0 -27
- package/lib/models/base-context.js +0 -77
- package/lib/models/elastic-index-data.js +0 -76
- package/lib/models/flow-context.js +0 -58
- package/lib/models/flow-indexed.js +0 -62
- package/lib/models/operation-function-indexed.js +0 -22
- package/lib/models/operation-function-transformation-indexed.js +0 -23
- package/lib/models/operation-http-indexed.js +0 -38
- package/lib/models/operation-mock-indexed.js +0 -22
- package/lib/models/route-context.js +0 -69
- package/lib/models/security-route.js +0 -41
- package/lib/models/service-context.js +0 -65
- package/lib/models/service-group.js +0 -15
- package/lib/models/service-route.js +0 -23
- package/lib/models/splunk-data.js +0 -70
- package/lib/operations/abstract-operation.js +0 -73
- package/lib/operations/function.js +0 -143
- package/lib/operations/http.js +0 -286
- package/lib/operations/mock.js +0 -34
- package/lib/operations/monitor-check.js +0 -151
- package/lib/orchestration-flow.js +0 -323
- package/lib/public/redoc.html +0 -152
- package/lib/public/swagger.html +0 -143
- package/lib/router.js +0 -29
- package/lib/security-validation.js +0 -46
- package/lib/services/server.js +0 -211
- package/lib/services/template-monitorcheck-route.js +0 -61
package/lib/commons-const.js
DELETED
|
@@ -1,203 +0,0 @@
|
|
|
1
|
-
module.exports = {
|
|
2
|
-
OPERATION_RESULT_IS_ORCHESTRATION_RESULT: ".",
|
|
3
|
-
NOT_IMPLEMENTED_FUNCTION: "NotImplementedFunction",
|
|
4
|
-
DEFAULT_ENCODE_UTF8: "utf-8",
|
|
5
|
-
DEFAULT_TIMEOUT_MS: 300000,
|
|
6
|
-
DEFAULT_POOLSIZE: Infinity,
|
|
7
|
-
DEFAULT_ERROR_CODE: 500,
|
|
8
|
-
DEFAULT_CONTENT_TYPE_VALUE: "text/html;charset=UTF-8",
|
|
9
|
-
STREAM_CONTENT_TYPE_VALUE: "application/octet-stream",
|
|
10
|
-
JSON_CONTENT_TYPE_VALUE: "application/json",
|
|
11
|
-
FORM_CONTENT_TYPE_VALUE: "application/x-www-form-urlencoded",
|
|
12
|
-
FORM_MULTIPART_CONTENT_TYPE_VALUE: "multipart/form-data",
|
|
13
|
-
OBJECT_TYPE: {
|
|
14
|
-
READSTREAM: "ReadStream",
|
|
15
|
-
PASSTHROUGH: "PassThrough",
|
|
16
|
-
BUFFER: "Buffer",
|
|
17
|
-
OBJECT: "Object",
|
|
18
|
-
STRING: "String",
|
|
19
|
-
},
|
|
20
|
-
FLOW_OPERATION_TYPE: {
|
|
21
|
-
HTTP: "http",
|
|
22
|
-
FUNCTION: "function",
|
|
23
|
-
MOCK: "mock",
|
|
24
|
-
MONITOR_CHECK: "monitor",
|
|
25
|
-
},
|
|
26
|
-
HTTP_STATUS: {
|
|
27
|
-
// 1xx Informational
|
|
28
|
-
CONTINUE: 100,
|
|
29
|
-
SWITCHING_PROTOCOLS: 101,
|
|
30
|
-
PROCESSING: 102,
|
|
31
|
-
CHECKPOINT: 103,
|
|
32
|
-
OK: 200,
|
|
33
|
-
CREATED: 201,
|
|
34
|
-
ACCEPTED: 202,
|
|
35
|
-
NON_AUTHORITATIVE_INFORMATIO: 203,
|
|
36
|
-
NO_CONTENT: 204,
|
|
37
|
-
RESET_CONTENT: 205,
|
|
38
|
-
PARTIAL_CONTENT: 206,
|
|
39
|
-
MULTI_STATUS: 207,
|
|
40
|
-
ALREADY_REPORTED: 208,
|
|
41
|
-
IM_USED: 226,
|
|
42
|
-
MULTIPLE_CHOICES: 300,
|
|
43
|
-
MOVED_PERMANENTLY: 301,
|
|
44
|
-
FOUND: 302,
|
|
45
|
-
MOVED_TEMPORARILY: 302,
|
|
46
|
-
SEE_OTHER: 303,
|
|
47
|
-
NOT_MODIFIED: 304,
|
|
48
|
-
USE_PROXY: 305,
|
|
49
|
-
TEMPORARY_REDIRECT: 307,
|
|
50
|
-
PERMANENT_REDIRECT: 308,
|
|
51
|
-
// --- 4xx Client Error ---
|
|
52
|
-
ERROR_CLIENT_RANGE_START: 400,
|
|
53
|
-
BAD_REQUEST: 400,
|
|
54
|
-
UNAUTHORIZED: 401,
|
|
55
|
-
PAYMENT_REQUIRED: 402,
|
|
56
|
-
FORBIDDEN: 403,
|
|
57
|
-
NOT_FOUND: 404,
|
|
58
|
-
METHOD_NOT_ALLOWED: 405,
|
|
59
|
-
NOT_ACCEPTABLE: 406,
|
|
60
|
-
PROXY_AUTHENTICATION_REQUIRED: 407,
|
|
61
|
-
REQUEST_TIMEOUT: 408,
|
|
62
|
-
CONFLICT: 409,
|
|
63
|
-
GONE: 410,
|
|
64
|
-
LENGTH_REQUIRED: 411,
|
|
65
|
-
PRECONDITION_FAILED: 412,
|
|
66
|
-
PAYLOAD_TOO_LARGE: 413,
|
|
67
|
-
REQUEST_ENTITY_TOO_LARGE: 413,
|
|
68
|
-
URI_TOO_LONG: 414,
|
|
69
|
-
REQUEST_URI_TOO_LONG: 414,
|
|
70
|
-
UNSUPPORTED_MEDIA_TYPE: 415,
|
|
71
|
-
REQUESTED_RANGE_NOT_SATISFIABLE: 416,
|
|
72
|
-
EXPECTATION_FAILED: 417,
|
|
73
|
-
I_AM_A_TEAPOT: 418,
|
|
74
|
-
INSUFFICIENT_SPACE_ON_RESOURCE: 419,
|
|
75
|
-
METHOD_FAILURE: 420,
|
|
76
|
-
DESTINATION_LOCKED: 421,
|
|
77
|
-
UNPROCESSABLE_ENTITY: 422,
|
|
78
|
-
LOCKED: 423,
|
|
79
|
-
FAILED_DEPENDENCY: 424,
|
|
80
|
-
UPGRADE_REQUIRED: 426,
|
|
81
|
-
PRECONDITION_REQUIRED: 428,
|
|
82
|
-
TOO_MANY_REQUESTS: 429,
|
|
83
|
-
REQUEST_HEADER_FIELDS_TOO_LARGE: 431,
|
|
84
|
-
UNAVAILABLE_FOR_LEGAL_REASONS: 451,
|
|
85
|
-
// --- 5xx Server Error ---
|
|
86
|
-
INTERNAL_SERVER_ERROR: 500,
|
|
87
|
-
NOT_IMPLEMENTED: 501,
|
|
88
|
-
BAD_GATEWAY: 502,
|
|
89
|
-
SERVICE_UNAVAILABLE: 503,
|
|
90
|
-
GATEWAY_TIMEOUT: 504,
|
|
91
|
-
HTTP_VERSION_NOT_SUPPORTED: 505,
|
|
92
|
-
VARIANT_ALSO_NEGOTIATES: 506,
|
|
93
|
-
INSUFFICIENT_STORAGE: 507,
|
|
94
|
-
LOOP_DETECTED: 508,
|
|
95
|
-
BANDWIDTH_LIMIT_EXCEEDED: 509,
|
|
96
|
-
NOT_EXTENDED: 510,
|
|
97
|
-
NETWORK_AUTHENTICATION_REQUIRED: 511,
|
|
98
|
-
},
|
|
99
|
-
HTTP_METHOD: {
|
|
100
|
-
GET: "GET",
|
|
101
|
-
HEAD: "HEAD",
|
|
102
|
-
POST: "POST",
|
|
103
|
-
PUT: "PUT",
|
|
104
|
-
PATCH: "PATCH",
|
|
105
|
-
DELETE: "DELETE",
|
|
106
|
-
OPTIONS: "OPTIONS",
|
|
107
|
-
TRACE: "TRACE",
|
|
108
|
-
},
|
|
109
|
-
HEADERS: {
|
|
110
|
-
X_USER_TYPE: "x-user-type",
|
|
111
|
-
X_REQUEST_UUID_NAME: "x-request-uuid",
|
|
112
|
-
X_REQUEST_SERVICE_NAME: "x-service-name",
|
|
113
|
-
X_REQUEST_SERVICE_DESCRIPTION: "x-service-description",
|
|
114
|
-
X_REQUEST_DURATION_NAME: "x-request-duration",
|
|
115
|
-
X_CUSTOMER_UUID_NAME: "x-customer-uuid",
|
|
116
|
-
X_WHITE_LABEL_UUID_NAME: "x-white-label-uuid",
|
|
117
|
-
X_ACCESS_TOKEN_NAME: "x-access-token",
|
|
118
|
-
X_AUTHORIZATION_NAME: "x-authorization",
|
|
119
|
-
X_DEVICE_DNA_NAME: "x-device-dna",
|
|
120
|
-
X_DEVICE_PUBLIC_KEY_NAME: "x-device-public-key",
|
|
121
|
-
X_VTEX_API_APPKEY_NAME: "x-vtex-api-appkey",
|
|
122
|
-
X_VTEX_API_APPTOKEN_NAME: "x-vtex-api-apptoken",
|
|
123
|
-
X_MERCHANT_ID: "x-merchant-id",
|
|
124
|
-
ACCEPT: "Accept",
|
|
125
|
-
ACCEPT_CHARSET: "Accept-Charset",
|
|
126
|
-
ACCEPT_ENCODING: "Accept-Encoding",
|
|
127
|
-
ACCEPT_LANGUAGE: "Accept-Language",
|
|
128
|
-
ACCEPT_RANGES: "Accept-Ranges",
|
|
129
|
-
ACCESS_CONTROL_ALLOW_CREDENTIALS: "Access-Control-Allow-Credentials",
|
|
130
|
-
ACCESS_CONTROL_ALLOW_HEADERS: "Access-Control-Allow-Headers",
|
|
131
|
-
ACCESS_CONTROL_ALLOW_METHODS: "Access-Control-Allow-Methods",
|
|
132
|
-
ACCESS_CONTROL_ALLOW_ORIGIN: "Access-Control-Allow-Origin",
|
|
133
|
-
ACCESS_CONTROL_EXPOSE_HEADERS: "Access-Control-Expose-Headers",
|
|
134
|
-
ACCESS_CONTROL_MAX_AGE: "Access-Control-Max-Age",
|
|
135
|
-
ACCESS_CONTROL_REQUEST_HEADERS: "Access-Control-Request-Headers",
|
|
136
|
-
ACCESS_CONTROL_REQUEST_METHOD: "Access-Control-Request-Method",
|
|
137
|
-
AGE: "Age",
|
|
138
|
-
ALLOW: "Allow",
|
|
139
|
-
AUTHORIZATION: "Authorization",
|
|
140
|
-
CACHE_CONTROL: "Cache-Control",
|
|
141
|
-
CONNECTION: "Connection",
|
|
142
|
-
CONTENT_ENCODING: "Content-Encoding",
|
|
143
|
-
CONTENT_DISPOSITION: "Content-Disposition",
|
|
144
|
-
CONTENT_LANGUAGE: "Content-Language",
|
|
145
|
-
CONTENT_LENGTH: "Content-Length",
|
|
146
|
-
CONTENT_LOCATION: "Content-Location",
|
|
147
|
-
CONTENT_RANGE: "Content-Range",
|
|
148
|
-
CONTENT_TYPE: "Content-Type",
|
|
149
|
-
COOKIE: "Cookie",
|
|
150
|
-
DATE: "Date",
|
|
151
|
-
ETAG: "ETag",
|
|
152
|
-
EXPECT: "Expect",
|
|
153
|
-
EXPIRES: "Expires",
|
|
154
|
-
FROM: "From",
|
|
155
|
-
HOST: "Host",
|
|
156
|
-
IF_MATCH: "If-Match",
|
|
157
|
-
IF_MODIFIED_SINCE: "If-Modified-Since",
|
|
158
|
-
IF_NONE_MATCH: "If-None-Match",
|
|
159
|
-
IF_RANGE: "If-Range",
|
|
160
|
-
IF_UNMODIFIED_SINCE: "If-Unmodified-Since",
|
|
161
|
-
LAST_MODIFIED: "Last-Modified",
|
|
162
|
-
LINK: "Link",
|
|
163
|
-
LOCATION: "Location",
|
|
164
|
-
MAX_FORWARDS: "Max-Forwards",
|
|
165
|
-
ORIGIN: "Origin",
|
|
166
|
-
PRAGMA: "Pragma",
|
|
167
|
-
PROXY_AUTHENTICATE: "Proxy-Authenticate",
|
|
168
|
-
PROXY_AUTHORIZATION: "Proxy-Authorization",
|
|
169
|
-
RANGE: "Range",
|
|
170
|
-
REFERER: "Referer",
|
|
171
|
-
RETRY_AFTER: "Retry-After",
|
|
172
|
-
SERVER: "Server",
|
|
173
|
-
SET_COOKIE: "Set-Cookie",
|
|
174
|
-
SET_COOKIE2: "Set-Cookie2",
|
|
175
|
-
TE: "TE",
|
|
176
|
-
TRAILER: "Trailer",
|
|
177
|
-
TRANSFER_ENCODING: "Transfer-Encoding",
|
|
178
|
-
UPGRADE: "Upgrade",
|
|
179
|
-
USER_AGENT: "User-Agent",
|
|
180
|
-
VARY: "Vary",
|
|
181
|
-
VIA: "Via",
|
|
182
|
-
WARNING: "Warning",
|
|
183
|
-
WWW_AUTHENTICATE: "WWW-Authenticate",
|
|
184
|
-
},
|
|
185
|
-
ALLOW_HEADERS_DEFAULT: [
|
|
186
|
-
"authorization",
|
|
187
|
-
"content-type",
|
|
188
|
-
"accept",
|
|
189
|
-
"accept-version",
|
|
190
|
-
"api-version",
|
|
191
|
-
"origin",
|
|
192
|
-
"vtexidclientautcookie",
|
|
193
|
-
"x-authorization",
|
|
194
|
-
"x-vtex-api-appkey",
|
|
195
|
-
"x-vtex-api-apptoken",
|
|
196
|
-
"x-access-token",
|
|
197
|
-
"x-device-public-key",
|
|
198
|
-
"x-pay2b-client-id",
|
|
199
|
-
"sentry-trace",
|
|
200
|
-
"x-merchant-id",
|
|
201
|
-
"x-customer-uuid",
|
|
202
|
-
],
|
|
203
|
-
};
|
|
@@ -1,49 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
const Util = require("./commons-util");
|
|
4
|
-
const { Client } = require("elasticsearch");
|
|
5
|
-
const HOST_DEFAULT = "localhost:9200";
|
|
6
|
-
|
|
7
|
-
class ElasticSearch {
|
|
8
|
-
constructor(options) {
|
|
9
|
-
this.instance = null;
|
|
10
|
-
this.enabled = options.hasOwnProperty("enableElasticSearch") ? options.enableElasticSearch : false;
|
|
11
|
-
|
|
12
|
-
if (this.enabled) {
|
|
13
|
-
let hasConfig = options.hasOwnProperty("elasticSearch");
|
|
14
|
-
|
|
15
|
-
if (hasConfig) {
|
|
16
|
-
Util.info("Creating ElasticSearch Instance", Util.stringifyInfo(options.elasticSearch));
|
|
17
|
-
|
|
18
|
-
let elasticSearch = options.elasticSearch;
|
|
19
|
-
|
|
20
|
-
const clientConfig = {
|
|
21
|
-
host: elasticSearch.host || HOST_DEFAULT
|
|
22
|
-
};
|
|
23
|
-
|
|
24
|
-
if (elasticSearch.user && elasticSearch.password) {
|
|
25
|
-
clientConfig.auth = {
|
|
26
|
-
username: elasticSearch.user,
|
|
27
|
-
password: elasticSearch.password
|
|
28
|
-
};
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
this.instance = new Client(clientConfig);
|
|
32
|
-
}
|
|
33
|
-
} else {
|
|
34
|
-
this.enabled = false;
|
|
35
|
-
}
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
getInstance() {
|
|
39
|
-
return this.instance;
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
isEnabled() {
|
|
43
|
-
return this.enabled;
|
|
44
|
-
}
|
|
45
|
-
}
|
|
46
|
-
|
|
47
|
-
exports.createClient = function (options) {
|
|
48
|
-
return new ElasticSearch(options);
|
|
49
|
-
};
|
package/lib/commons-errors.js
DELETED
|
@@ -1,278 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
const Util = require("./commons-util");
|
|
4
|
-
const Const = require("./commons-const");
|
|
5
|
-
|
|
6
|
-
const BAD_REQUEST = 400,
|
|
7
|
-
UNAUTHORIZED_ERROR_CODE = 401,
|
|
8
|
-
FORBIDDEN_ERROR_CODE = 403,
|
|
9
|
-
NOT_FOUND_ERROR_CODE = 404,
|
|
10
|
-
ENOTFOUND_ERROR = "ENOTFOUND",
|
|
11
|
-
ETIMEDOUT_ERROR = "ETIMEDOUT",
|
|
12
|
-
REQUEST_TOO_MANY_REQUESTS = 429,
|
|
13
|
-
REQUEST_TOO_MANY_REQUESTS_MESSAGE = "Too Many Requests.",
|
|
14
|
-
REQUEST_TIMEOUT_ERROR_CODE = 408,
|
|
15
|
-
NOT_ACCEPTABLE_ERROR_CODE = 406,
|
|
16
|
-
UNAVAILABLE_ERROR_CODE = 503,
|
|
17
|
-
INTERNAL_SERVER_ERROR_CODE = 500,
|
|
18
|
-
DEFAULT_ERROR = "default",
|
|
19
|
-
DEFAULT_SECURITY_ERROR_MESSAGE = "Request Unauthorized.",
|
|
20
|
-
DEFAULT_VALIDATION_ERROR_MESSAGE = "Invalid Arguments.",
|
|
21
|
-
DEFAULT_NOT_FOUND_MESSAGE = "Not Found.",
|
|
22
|
-
DEFAULT_REQUEST_TIMEOUT_MESSAGE = "Request Timeout.",
|
|
23
|
-
DEFAULT_ERROR_MESSAGE = "Error processing the Request.",
|
|
24
|
-
DEFAULT_HANDLERS = {
|
|
25
|
-
[BAD_REQUEST]: (error) => {
|
|
26
|
-
return Errors.handleValidationError(error, BAD_REQUEST);
|
|
27
|
-
},
|
|
28
|
-
[UNAUTHORIZED_ERROR_CODE]: (error) => {
|
|
29
|
-
return Errors.handleSecurityError(error, UNAUTHORIZED_ERROR_CODE);
|
|
30
|
-
},
|
|
31
|
-
[FORBIDDEN_ERROR_CODE]: (error) => {
|
|
32
|
-
return Errors.handleSecurityError(error, FORBIDDEN_ERROR_CODE);
|
|
33
|
-
},
|
|
34
|
-
[NOT_FOUND_ERROR_CODE]: (error) => {
|
|
35
|
-
return Errors.handleNotFoundError(error);
|
|
36
|
-
},
|
|
37
|
-
[ENOTFOUND_ERROR]: (error) => {
|
|
38
|
-
return Errors.handleNotFoundError(error);
|
|
39
|
-
},
|
|
40
|
-
[NOT_ACCEPTABLE_ERROR_CODE]: (error) => {
|
|
41
|
-
return Errors.handleValidationError(error, NOT_ACCEPTABLE_ERROR_CODE);
|
|
42
|
-
},
|
|
43
|
-
[UNAVAILABLE_ERROR_CODE]: (error) => {
|
|
44
|
-
return Errors.handleDefaultError(error);
|
|
45
|
-
},
|
|
46
|
-
[REQUEST_TIMEOUT_ERROR_CODE]: (error) => {
|
|
47
|
-
return Errors.handleRequestTimeoutError(error, REQUEST_TIMEOUT_ERROR_CODE);
|
|
48
|
-
},
|
|
49
|
-
[ETIMEDOUT_ERROR]: (error) => {
|
|
50
|
-
return Errors.handleRequestTimeoutError(error, REQUEST_TIMEOUT_ERROR_CODE);
|
|
51
|
-
},
|
|
52
|
-
[DEFAULT_ERROR]: (error) => {
|
|
53
|
-
return Errors.handleDefaultError(error);
|
|
54
|
-
},
|
|
55
|
-
};
|
|
56
|
-
|
|
57
|
-
function validateCause(cause) {
|
|
58
|
-
if (cause) {
|
|
59
|
-
if (cause instanceof TypeError || cause instanceof ReferenceError) {
|
|
60
|
-
return {
|
|
61
|
-
name: cause.name,
|
|
62
|
-
message: cause.message,
|
|
63
|
-
stack: cause.stack,
|
|
64
|
-
};
|
|
65
|
-
} else {
|
|
66
|
-
return cause.hasOwnProperty("message") ? cause.message : cause;
|
|
67
|
-
}
|
|
68
|
-
}
|
|
69
|
-
|
|
70
|
-
return null;
|
|
71
|
-
}
|
|
72
|
-
|
|
73
|
-
class BaseError extends Error {
|
|
74
|
-
constructor(message, cause) {
|
|
75
|
-
super();
|
|
76
|
-
}
|
|
77
|
-
}
|
|
78
|
-
|
|
79
|
-
class ApiGatewayError extends BaseError {
|
|
80
|
-
constructor(message, cause) {
|
|
81
|
-
super();
|
|
82
|
-
this.name = "ApiGatewayError";
|
|
83
|
-
this.propagable = true;
|
|
84
|
-
this.responseCode = INTERNAL_SERVER_ERROR_CODE;
|
|
85
|
-
this.message = message || DEFAULT_ERROR_MESSAGE;
|
|
86
|
-
this.cause = validateCause(cause);
|
|
87
|
-
Error.captureStackTrace(this, ApiGatewayError);
|
|
88
|
-
}
|
|
89
|
-
}
|
|
90
|
-
|
|
91
|
-
class ValidationError extends BaseError {
|
|
92
|
-
constructor(message, cause, responseCode) {
|
|
93
|
-
super();
|
|
94
|
-
this.name = "ValidationError";
|
|
95
|
-
this.propagable = true;
|
|
96
|
-
this.responseCode = responseCode || BAD_REQUEST;
|
|
97
|
-
this.message = message || DEFAULT_VALIDATION_ERROR_MESSAGE;
|
|
98
|
-
this.cause = validateCause(cause);
|
|
99
|
-
Error.captureStackTrace(this, ValidationError);
|
|
100
|
-
}
|
|
101
|
-
}
|
|
102
|
-
|
|
103
|
-
class SecurityError extends BaseError {
|
|
104
|
-
constructor(message, cause, responseCode) {
|
|
105
|
-
super();
|
|
106
|
-
this.name = "SecurityError";
|
|
107
|
-
this.propagable = true;
|
|
108
|
-
this.responseCode = responseCode || UNAUTHORIZED_ERROR_CODE;
|
|
109
|
-
this.message = message || DEFAULT_SECURITY_ERROR_MESSAGE;
|
|
110
|
-
this.cause = validateCause(cause);
|
|
111
|
-
Error.captureStackTrace(this, SecurityError);
|
|
112
|
-
}
|
|
113
|
-
}
|
|
114
|
-
|
|
115
|
-
class NotFoundError extends BaseError {
|
|
116
|
-
constructor(message, cause) {
|
|
117
|
-
super();
|
|
118
|
-
this.name = "NotFoundError";
|
|
119
|
-
this.propagable = true;
|
|
120
|
-
this.responseCode = NOT_FOUND_ERROR_CODE;
|
|
121
|
-
this.message = message || DEFAULT_NOT_FOUND_MESSAGE;
|
|
122
|
-
this.cause = validateCause(cause);
|
|
123
|
-
Error.captureStackTrace(this, NotFoundError);
|
|
124
|
-
}
|
|
125
|
-
}
|
|
126
|
-
|
|
127
|
-
class RequestTimeoutError extends BaseError {
|
|
128
|
-
constructor(message, cause) {
|
|
129
|
-
super();
|
|
130
|
-
this.name = "RequestTimeout";
|
|
131
|
-
this.propagable = true;
|
|
132
|
-
this.responseCode = REQUEST_TIMEOUT_ERROR_CODE;
|
|
133
|
-
this.message = message || DEFAULT_REQUEST_TIMEOUT_MESSAGE;
|
|
134
|
-
this.cause = validateCause(cause);
|
|
135
|
-
Error.captureStackTrace(this, RequestTimeoutError);
|
|
136
|
-
}
|
|
137
|
-
}
|
|
138
|
-
|
|
139
|
-
class RequestTooManyRequests extends BaseError {
|
|
140
|
-
constructor(message, cause) {
|
|
141
|
-
super();
|
|
142
|
-
this.name = "RequestTooManyRequests";
|
|
143
|
-
this.propagable = true;
|
|
144
|
-
this.responseCode = REQUEST_TOO_MANY_REQUESTS;
|
|
145
|
-
this.message = message || REQUEST_TOO_MANY_REQUESTS_MESSAGE;
|
|
146
|
-
this.cause = validateCause(cause);
|
|
147
|
-
Error.captureStackTrace(this, RequestTooManyRequests);
|
|
148
|
-
}
|
|
149
|
-
}
|
|
150
|
-
|
|
151
|
-
class Errors {
|
|
152
|
-
|
|
153
|
-
static handlers() {
|
|
154
|
-
return DEFAULT_HANDLERS;
|
|
155
|
-
}
|
|
156
|
-
|
|
157
|
-
static handleError(error) {
|
|
158
|
-
|
|
159
|
-
if (error instanceof BaseError) return error;
|
|
160
|
-
|
|
161
|
-
let errorCode = DEFAULT_ERROR;
|
|
162
|
-
|
|
163
|
-
if (error.hasOwnProperty("code")) errorCode = error.code;
|
|
164
|
-
|
|
165
|
-
if (error.hasOwnProperty("responseCode")) errorCode = error.responseCode;
|
|
166
|
-
|
|
167
|
-
let handler = this.handlers()[errorCode];
|
|
168
|
-
|
|
169
|
-
if (handler) {
|
|
170
|
-
return handler(error);
|
|
171
|
-
} else {
|
|
172
|
-
return this.handleDefaultError(error);
|
|
173
|
-
}
|
|
174
|
-
|
|
175
|
-
}
|
|
176
|
-
|
|
177
|
-
static handleSecurityError(error, responseCode) {
|
|
178
|
-
return new SecurityError(DEFAULT_SECURITY_ERROR_MESSAGE, error, responseCode);
|
|
179
|
-
}
|
|
180
|
-
|
|
181
|
-
static handleValidationError(error, responseCode) {
|
|
182
|
-
return new ValidationError(DEFAULT_VALIDATION_ERROR_MESSAGE, error, responseCode);
|
|
183
|
-
}
|
|
184
|
-
|
|
185
|
-
static handleNotFoundError(error) {
|
|
186
|
-
return new NotFoundError(DEFAULT_NOT_FOUND_MESSAGE, error);
|
|
187
|
-
}
|
|
188
|
-
|
|
189
|
-
static handleRequestTimeoutError(error) {
|
|
190
|
-
return new RequestTimeoutError(DEFAULT_REQUEST_TIMEOUT_MESSAGE, error);
|
|
191
|
-
}
|
|
192
|
-
|
|
193
|
-
static handleDefaultError(error) {
|
|
194
|
-
return new ApiGatewayError(DEFAULT_ERROR_MESSAGE, error);
|
|
195
|
-
}
|
|
196
|
-
}
|
|
197
|
-
|
|
198
|
-
function createFunctionError(error) {
|
|
199
|
-
|
|
200
|
-
if (error instanceof BaseError) return error;
|
|
201
|
-
|
|
202
|
-
let defaultError = {
|
|
203
|
-
responseCode: INTERNAL_SERVER_ERROR_CODE,
|
|
204
|
-
message: (error || {}).hasOwnProperty("message") ? error.message : DEFAULT_ERROR_MESSAGE,
|
|
205
|
-
stack: (error || {}).hasOwnProperty("stack") ? error.stack : error,
|
|
206
|
-
};
|
|
207
|
-
|
|
208
|
-
return defaultError;
|
|
209
|
-
|
|
210
|
-
}
|
|
211
|
-
|
|
212
|
-
function createHttpError(error) {
|
|
213
|
-
|
|
214
|
-
let defaultError = createCustomError(INTERNAL_SERVER_ERROR_CODE, DEFAULT_ERROR_MESSAGE);
|
|
215
|
-
|
|
216
|
-
if (error.hasOwnProperty("response")) {
|
|
217
|
-
|
|
218
|
-
defaultError.code = error.response.status || Const.DEFAULT_ERROR_CODE;
|
|
219
|
-
defaultError.message = error.response.data;
|
|
220
|
-
|
|
221
|
-
} else {
|
|
222
|
-
|
|
223
|
-
// let errorJSON = Util.underscore().clone(error.toJSON());
|
|
224
|
-
|
|
225
|
-
// delete errorJSON.code;
|
|
226
|
-
// delete errorJSON.config;
|
|
227
|
-
// delete errorJSON.request;
|
|
228
|
-
// delete errorJSON.status;
|
|
229
|
-
// delete errorJSON.stack;
|
|
230
|
-
// delete errorJSON.name;
|
|
231
|
-
// delete errorJSON.number;
|
|
232
|
-
// delete errorJSON.columnNumber;
|
|
233
|
-
// delete errorJSON.fileName;
|
|
234
|
-
// delete errorJSON.lineNumber;
|
|
235
|
-
|
|
236
|
-
defaultError.code = error.code || Const.DEFAULT_ERROR_CODE;
|
|
237
|
-
defaultError.message = createCustomError(
|
|
238
|
-
error.code || Const.DEFAULT_ERROR_CODE,
|
|
239
|
-
error.description || error.message
|
|
240
|
-
);
|
|
241
|
-
|
|
242
|
-
}
|
|
243
|
-
|
|
244
|
-
return defaultError;
|
|
245
|
-
|
|
246
|
-
}
|
|
247
|
-
|
|
248
|
-
function createCustomError(code, message) {
|
|
249
|
-
return {
|
|
250
|
-
errors: [
|
|
251
|
-
{
|
|
252
|
-
error: code,
|
|
253
|
-
message: message,
|
|
254
|
-
},
|
|
255
|
-
],
|
|
256
|
-
};
|
|
257
|
-
}
|
|
258
|
-
|
|
259
|
-
function createCustomErrors(errors) {
|
|
260
|
-
return {
|
|
261
|
-
errors: errors,
|
|
262
|
-
};
|
|
263
|
-
}
|
|
264
|
-
|
|
265
|
-
module.exports = {
|
|
266
|
-
ApiGatewayError: ApiGatewayError,
|
|
267
|
-
ValidationError: ValidationError,
|
|
268
|
-
SecurityError: SecurityError,
|
|
269
|
-
NotFoundError: NotFoundError,
|
|
270
|
-
RequestTimeoutError: RequestTimeoutError,
|
|
271
|
-
RequestTooManyRequests: RequestTooManyRequests,
|
|
272
|
-
Errors: Errors,
|
|
273
|
-
CreateCustomError: createCustomError,
|
|
274
|
-
CreateCustomErrors: createCustomErrors,
|
|
275
|
-
CreateHttpError: createHttpError,
|
|
276
|
-
CreateFunctionError: createFunctionError,
|
|
277
|
-
BaseError: BaseError,
|
|
278
|
-
};
|
|
@@ -1,37 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
const Util = require("./commons-util");
|
|
4
|
-
const { Client } = require("@opensearch-project/opensearch");
|
|
5
|
-
|
|
6
|
-
class OpenSearch {
|
|
7
|
-
constructor({ enableOpenSearch = false, openSearch = {} } = {}) {
|
|
8
|
-
this.enabled = enableOpenSearch;
|
|
9
|
-
this.instance = null;
|
|
10
|
-
|
|
11
|
-
if (this.enabled && openSearch.host) {
|
|
12
|
-
Util.info("Creating OpenSearch Instance", Util.stringifyInfo(openSearch));
|
|
13
|
-
|
|
14
|
-
const { host, auth = {} } = openSearch;
|
|
15
|
-
const { username, password } = auth;
|
|
16
|
-
const clientConfig = { node: host };
|
|
17
|
-
|
|
18
|
-
if (username && password) {
|
|
19
|
-
clientConfig.auth = { username, password };
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
this.instance = new Client(clientConfig);
|
|
23
|
-
} else {
|
|
24
|
-
this.enabled = false;
|
|
25
|
-
}
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
getInstance() {
|
|
29
|
-
return this.instance;
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
isEnabled() {
|
|
33
|
-
return this.enabled;
|
|
34
|
-
}
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
exports.createClient = (options) => new OpenSearch(options);
|
package/lib/commons-splunk.js
DELETED
|
@@ -1,105 +0,0 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
|
|
3
|
-
const Util = require('./commons-util');
|
|
4
|
-
const axios = require('axios');
|
|
5
|
-
const { JSON_CONTENT_TYPE_VALUE } = require('./commons-const');
|
|
6
|
-
|
|
7
|
-
const DEFAULT_PROTOCOL = 'https';
|
|
8
|
-
const DEFAULT_PATH = '/services/collector/event';
|
|
9
|
-
const DEFAULT_PORT = '443';
|
|
10
|
-
const DEFAULT_TIMEOUT = 10000;
|
|
11
|
-
|
|
12
|
-
class SplunkInstance {
|
|
13
|
-
|
|
14
|
-
constructor(options) {
|
|
15
|
-
|
|
16
|
-
this.instance = null;
|
|
17
|
-
|
|
18
|
-
this.enabled = options.hasOwnProperty('enableSplunkMonitoring') ? options.enableSplunkMonitoring : false;
|
|
19
|
-
|
|
20
|
-
if (this.enabled) {
|
|
21
|
-
|
|
22
|
-
let hasConfig = options.hasOwnProperty('splunk');
|
|
23
|
-
|
|
24
|
-
if (hasConfig) {
|
|
25
|
-
|
|
26
|
-
this.token = options.splunk.auth;
|
|
27
|
-
this.host = options.splunk.host;
|
|
28
|
-
|
|
29
|
-
if (!this.host || !this.token) {
|
|
30
|
-
Util.error(
|
|
31
|
-
'It was not possible to create the splunk client. '
|
|
32
|
-
+ 'splunk.host and splunk.token are mandatory properties. '
|
|
33
|
-
+ 'Please inform them in your application configuration file');
|
|
34
|
-
this.enabled = false;
|
|
35
|
-
return;
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
this.protocol = options.splunk.protocol || DEFAULT_PROTOCOL;
|
|
39
|
-
this.path = options.splunk.path || DEFAULT_PATH;
|
|
40
|
-
this.port = options.splunk.port || DEFAULT_PORT;
|
|
41
|
-
this.timeout = options.splunk.timeout || DEFAULT_TIMEOUT;
|
|
42
|
-
this.contentType = options.splunk.contentType || JSON_CONTENT_TYPE_VALUE;
|
|
43
|
-
|
|
44
|
-
let config = {
|
|
45
|
-
baseURL: `${this.protocol}://${this.host}:${this.port}`,
|
|
46
|
-
headers: {
|
|
47
|
-
'Authorization': `Splunk ${this.token}`,
|
|
48
|
-
'Content-Type': this.contentType
|
|
49
|
-
},
|
|
50
|
-
}
|
|
51
|
-
|
|
52
|
-
this.instance = axios.create(config);
|
|
53
|
-
|
|
54
|
-
Util.info('Creating Splunk Instance', Util.stringifyInfo(options.splunk));
|
|
55
|
-
|
|
56
|
-
} else {
|
|
57
|
-
this.enabled = false;
|
|
58
|
-
};
|
|
59
|
-
|
|
60
|
-
};
|
|
61
|
-
|
|
62
|
-
};
|
|
63
|
-
|
|
64
|
-
getInstance() {
|
|
65
|
-
return this.instance;
|
|
66
|
-
};
|
|
67
|
-
|
|
68
|
-
isEnabled() {
|
|
69
|
-
return this.enabled;
|
|
70
|
-
};
|
|
71
|
-
|
|
72
|
-
async sendEvent(body, currentAttempt = 1) {
|
|
73
|
-
|
|
74
|
-
if (currentAttempt >= 10) {
|
|
75
|
-
return;
|
|
76
|
-
}
|
|
77
|
-
|
|
78
|
-
this.instance.post(this.path, body,
|
|
79
|
-
{ timeout: this.timeout })
|
|
80
|
-
.then(function (response) {
|
|
81
|
-
Util.info('Splunk Data Indexed Successfully', { eventId: body.event.id });
|
|
82
|
-
})
|
|
83
|
-
.catch((error) => {
|
|
84
|
-
|
|
85
|
-
Util.error(`Error on Send Event Data to Splunk: ${JSON.stringify(error)} attempt no: ${currentAttempt}`);
|
|
86
|
-
|
|
87
|
-
Util.warning('Retry Index Splunk Data', {
|
|
88
|
-
eventId: body.event.id,
|
|
89
|
-
retryIn: "10s x " + currentAttempt,
|
|
90
|
-
attemptsIndex: currentAttempt
|
|
91
|
-
});
|
|
92
|
-
|
|
93
|
-
setTimeout(() => {
|
|
94
|
-
this.sendEvent(body, ++currentAttempt);
|
|
95
|
-
}, 10000 * currentAttempt);
|
|
96
|
-
|
|
97
|
-
});
|
|
98
|
-
|
|
99
|
-
}
|
|
100
|
-
|
|
101
|
-
}
|
|
102
|
-
|
|
103
|
-
exports.createClient = function (options) {
|
|
104
|
-
return new SplunkInstance(options);
|
|
105
|
-
};
|