@felloh-org/lambda-wrapper 1.0.0 → 1.0.1
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/.github/workflows/release.yml +2 -0
- package/dist/config/dependencies.js +32 -0
- package/dist/dependency-injection/dependency-aware.js +43 -0
- package/dist/dependency-injection/dependency-injection.js +135 -0
- package/dist/index.js +113 -0
- package/dist/model/index.js +45 -0
- package/dist/model/response/index.js +150 -0
- package/dist/model/status/index.js +82 -0
- package/dist/service/http.js +55 -0
- package/dist/service/logger.js +236 -0
- package/dist/service/request.js +342 -0
- package/dist/util/lambda-termination.js +39 -0
- package/dist/util/promisified-delay.js +59 -0
- package/dist/wrapper/index.js +165 -0
- package/package.json +1 -1
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.default = exports.Dependencies = exports.DEFINITIONS = void 0;
|
|
7
|
+
|
|
8
|
+
var _http = _interopRequireDefault(require("../service/http"));
|
|
9
|
+
|
|
10
|
+
var _logger = _interopRequireDefault(require("../service/logger"));
|
|
11
|
+
|
|
12
|
+
var _request = _interopRequireDefault(require("../service/request"));
|
|
13
|
+
|
|
14
|
+
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
15
|
+
|
|
16
|
+
const DEFINITIONS = {
|
|
17
|
+
HTTP: 'HTTP',
|
|
18
|
+
LOGGER: 'LOGGER',
|
|
19
|
+
REQUEST: 'REQUEST'
|
|
20
|
+
};
|
|
21
|
+
exports.DEFINITIONS = DEFINITIONS;
|
|
22
|
+
const Dependencies = {
|
|
23
|
+
[DEFINITIONS.HTTP]: _http.default,
|
|
24
|
+
[DEFINITIONS.LOGGER]: _logger.default,
|
|
25
|
+
[DEFINITIONS.REQUEST]: _request.default
|
|
26
|
+
};
|
|
27
|
+
exports.Dependencies = Dependencies;
|
|
28
|
+
var _default = {
|
|
29
|
+
DEFINITIONS,
|
|
30
|
+
DEPENDENCIES: Dependencies
|
|
31
|
+
};
|
|
32
|
+
exports.default = _default;
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.default = void 0;
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* DependencyAwareClass Class
|
|
10
|
+
*/
|
|
11
|
+
class DependencyAware {
|
|
12
|
+
/**
|
|
13
|
+
* DependencyAwareClass constructor
|
|
14
|
+
*
|
|
15
|
+
* @param {DependencyInjection} di
|
|
16
|
+
*/
|
|
17
|
+
constructor(di) {
|
|
18
|
+
this.di = di;
|
|
19
|
+
}
|
|
20
|
+
/**
|
|
21
|
+
* Get Dependency Injection Container
|
|
22
|
+
*
|
|
23
|
+
* @returns {DependencyInjection}
|
|
24
|
+
*/
|
|
25
|
+
|
|
26
|
+
|
|
27
|
+
getContainer() {
|
|
28
|
+
return this.di;
|
|
29
|
+
}
|
|
30
|
+
/**
|
|
31
|
+
* Shortcut for `this.getContainer().definitions`
|
|
32
|
+
*
|
|
33
|
+
* @returns {object}
|
|
34
|
+
*/
|
|
35
|
+
|
|
36
|
+
|
|
37
|
+
get definitions() {
|
|
38
|
+
return this.getContainer().definitions;
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
exports.default = DependencyAware;
|
|
@@ -0,0 +1,135 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.default = void 0;
|
|
7
|
+
|
|
8
|
+
var _dependencies = require("../config/dependencies");
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* DependencyInjection class
|
|
12
|
+
*/
|
|
13
|
+
class DependencyInjection {
|
|
14
|
+
/**
|
|
15
|
+
* DependencyInjection constructor
|
|
16
|
+
*
|
|
17
|
+
* @param configuration
|
|
18
|
+
* @param event
|
|
19
|
+
* @param context
|
|
20
|
+
*/
|
|
21
|
+
constructor(configuration, event, context) {
|
|
22
|
+
this.event = event;
|
|
23
|
+
this.context = context;
|
|
24
|
+
this.dependencies = {};
|
|
25
|
+
this.configuration = configuration;
|
|
26
|
+
|
|
27
|
+
for (let x = 0; x <= 1; x += 1) {
|
|
28
|
+
// Iterate over dependencies and add to container
|
|
29
|
+
Object.keys(_dependencies.DEFINITIONS).forEach(dependencyKey => {
|
|
30
|
+
this.dependencies[dependencyKey] = new _dependencies.Dependencies[dependencyKey](this);
|
|
31
|
+
}); // Iterate over child dependencies and add to container
|
|
32
|
+
|
|
33
|
+
if (typeof configuration.DEPENDENCIES !== 'undefined') {
|
|
34
|
+
Object.keys(configuration.DEPENDENCIES).forEach(dependencyKey => {
|
|
35
|
+
this.dependencies[dependencyKey] = new configuration.DEPENDENCIES[dependencyKey](this);
|
|
36
|
+
});
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
/**
|
|
41
|
+
* Get Dependency
|
|
42
|
+
*
|
|
43
|
+
* @param definition
|
|
44
|
+
* @returns {*}
|
|
45
|
+
*/
|
|
46
|
+
|
|
47
|
+
|
|
48
|
+
get(definition) {
|
|
49
|
+
if (typeof this.dependencies[definition] === 'undefined') {
|
|
50
|
+
throw new TypeError(`${definition} does not exist in di container`);
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
return this.dependencies[definition];
|
|
54
|
+
}
|
|
55
|
+
/**
|
|
56
|
+
* Get Event
|
|
57
|
+
*
|
|
58
|
+
* @returns {*}
|
|
59
|
+
*/
|
|
60
|
+
|
|
61
|
+
|
|
62
|
+
getEvent() {
|
|
63
|
+
return this.event;
|
|
64
|
+
}
|
|
65
|
+
/**
|
|
66
|
+
* Get Context
|
|
67
|
+
*
|
|
68
|
+
* @returns {*}
|
|
69
|
+
*/
|
|
70
|
+
|
|
71
|
+
|
|
72
|
+
getContext() {
|
|
73
|
+
return this.context;
|
|
74
|
+
}
|
|
75
|
+
/**
|
|
76
|
+
* Get Configuration
|
|
77
|
+
*
|
|
78
|
+
* @param definition string
|
|
79
|
+
* @returns {*}
|
|
80
|
+
*/
|
|
81
|
+
|
|
82
|
+
|
|
83
|
+
getConfiguration(definition = null) {
|
|
84
|
+
if (definition !== null && typeof this.configuration[definition] === 'undefined') {
|
|
85
|
+
return null;
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
if (typeof this.configuration[definition] !== 'undefined') {
|
|
89
|
+
return this.configuration[definition];
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
return this.configuration;
|
|
93
|
+
}
|
|
94
|
+
/**
|
|
95
|
+
* Check whether the function
|
|
96
|
+
* is being executed in a serverless-offline context
|
|
97
|
+
*
|
|
98
|
+
* @returns {boolean}
|
|
99
|
+
*/
|
|
100
|
+
|
|
101
|
+
|
|
102
|
+
get isOffline() {
|
|
103
|
+
const context = this.getContext() || {};
|
|
104
|
+
|
|
105
|
+
if (!Object.prototype.hasOwnProperty.call(context, 'invokedFunctionArn')) {
|
|
106
|
+
return true;
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
if (context.invokedFunctionArn.includes('offline')) {
|
|
110
|
+
return true;
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
if (process.env.USE_SERVERLESS_OFFLINE) {
|
|
114
|
+
return true;
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
return false;
|
|
118
|
+
}
|
|
119
|
+
/**
|
|
120
|
+
* Returns the definitions
|
|
121
|
+
* associated to this DependencyInjection
|
|
122
|
+
* so that services can refer to them
|
|
123
|
+
* without causing circular imports.
|
|
124
|
+
*
|
|
125
|
+
* @returns {object}
|
|
126
|
+
*/
|
|
127
|
+
|
|
128
|
+
|
|
129
|
+
get definitions() {
|
|
130
|
+
return this.configuration.DEFINITIONS;
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
exports.default = DependencyInjection;
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,113 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
Object.defineProperty(exports, "DEFINITIONS", {
|
|
7
|
+
enumerable: true,
|
|
8
|
+
get: function () {
|
|
9
|
+
return _dependencies.DEFINITIONS;
|
|
10
|
+
}
|
|
11
|
+
});
|
|
12
|
+
Object.defineProperty(exports, "DependencyAwareClass", {
|
|
13
|
+
enumerable: true,
|
|
14
|
+
get: function () {
|
|
15
|
+
return _dependencyAware.default;
|
|
16
|
+
}
|
|
17
|
+
});
|
|
18
|
+
Object.defineProperty(exports, "DependencyInjection", {
|
|
19
|
+
enumerable: true,
|
|
20
|
+
get: function () {
|
|
21
|
+
return _dependencyInjection.default;
|
|
22
|
+
}
|
|
23
|
+
});
|
|
24
|
+
Object.defineProperty(exports, "HTTPService", {
|
|
25
|
+
enumerable: true,
|
|
26
|
+
get: function () {
|
|
27
|
+
return _http.default;
|
|
28
|
+
}
|
|
29
|
+
});
|
|
30
|
+
Object.defineProperty(exports, "LambdaTermination", {
|
|
31
|
+
enumerable: true,
|
|
32
|
+
get: function () {
|
|
33
|
+
return _lambdaTermination.default;
|
|
34
|
+
}
|
|
35
|
+
});
|
|
36
|
+
Object.defineProperty(exports, "LambdaWrapper", {
|
|
37
|
+
enumerable: true,
|
|
38
|
+
get: function () {
|
|
39
|
+
return _wrapper.default;
|
|
40
|
+
}
|
|
41
|
+
});
|
|
42
|
+
Object.defineProperty(exports, "LoggerService", {
|
|
43
|
+
enumerable: true,
|
|
44
|
+
get: function () {
|
|
45
|
+
return _logger.default;
|
|
46
|
+
}
|
|
47
|
+
});
|
|
48
|
+
Object.defineProperty(exports, "Model", {
|
|
49
|
+
enumerable: true,
|
|
50
|
+
get: function () {
|
|
51
|
+
return _model.default;
|
|
52
|
+
}
|
|
53
|
+
});
|
|
54
|
+
Object.defineProperty(exports, "PromisifiedDelay", {
|
|
55
|
+
enumerable: true,
|
|
56
|
+
get: function () {
|
|
57
|
+
return _promisifiedDelay.default;
|
|
58
|
+
}
|
|
59
|
+
});
|
|
60
|
+
Object.defineProperty(exports, "RequestService", {
|
|
61
|
+
enumerable: true,
|
|
62
|
+
get: function () {
|
|
63
|
+
return _request.default;
|
|
64
|
+
}
|
|
65
|
+
});
|
|
66
|
+
Object.defineProperty(exports, "ResponseModel", {
|
|
67
|
+
enumerable: true,
|
|
68
|
+
get: function () {
|
|
69
|
+
return _response.default;
|
|
70
|
+
}
|
|
71
|
+
});
|
|
72
|
+
Object.defineProperty(exports, "STATUS_TYPES", {
|
|
73
|
+
enumerable: true,
|
|
74
|
+
get: function () {
|
|
75
|
+
return _status.STATUS_TYPES;
|
|
76
|
+
}
|
|
77
|
+
});
|
|
78
|
+
Object.defineProperty(exports, "StatusModel", {
|
|
79
|
+
enumerable: true,
|
|
80
|
+
get: function () {
|
|
81
|
+
return _status.default;
|
|
82
|
+
}
|
|
83
|
+
});
|
|
84
|
+
|
|
85
|
+
var _dependencies = require("./config/dependencies");
|
|
86
|
+
|
|
87
|
+
var _dependencyAware = _interopRequireDefault(require("./dependency-injection/dependency-aware"));
|
|
88
|
+
|
|
89
|
+
var _dependencyInjection = _interopRequireDefault(require("./dependency-injection/dependency-injection"));
|
|
90
|
+
|
|
91
|
+
var _model = _interopRequireDefault(require("./model"));
|
|
92
|
+
|
|
93
|
+
var _response = _interopRequireDefault(require("./model/response"));
|
|
94
|
+
|
|
95
|
+
var _status = _interopRequireWildcard(require("./model/status"));
|
|
96
|
+
|
|
97
|
+
var _http = _interopRequireDefault(require("./service/http"));
|
|
98
|
+
|
|
99
|
+
var _logger = _interopRequireDefault(require("./service/logger"));
|
|
100
|
+
|
|
101
|
+
var _request = _interopRequireDefault(require("./service/request"));
|
|
102
|
+
|
|
103
|
+
var _lambdaTermination = _interopRequireDefault(require("./util/lambda-termination"));
|
|
104
|
+
|
|
105
|
+
var _promisifiedDelay = _interopRequireDefault(require("./util/promisified-delay"));
|
|
106
|
+
|
|
107
|
+
var _wrapper = _interopRequireDefault(require("./wrapper"));
|
|
108
|
+
|
|
109
|
+
function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function (nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
|
|
110
|
+
|
|
111
|
+
function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
|
|
112
|
+
|
|
113
|
+
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.default = void 0;
|
|
7
|
+
|
|
8
|
+
var _validate = _interopRequireDefault(require("validate.js/validate"));
|
|
9
|
+
|
|
10
|
+
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
11
|
+
|
|
12
|
+
/* eslint-disable class-methods-use-this */
|
|
13
|
+
|
|
14
|
+
/**
|
|
15
|
+
* Model base class
|
|
16
|
+
*/
|
|
17
|
+
class Model {
|
|
18
|
+
/**
|
|
19
|
+
* Instantiate a function with a value if defined
|
|
20
|
+
*
|
|
21
|
+
* @param classFunctionName string
|
|
22
|
+
* @param value mixed
|
|
23
|
+
*/
|
|
24
|
+
instantiateFunctionWithDefinedValue(classFunctionName, value) {
|
|
25
|
+
if (typeof value !== 'undefined') {
|
|
26
|
+
this[classFunctionName](value);
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
/**
|
|
30
|
+
* Validate values against constraints
|
|
31
|
+
*
|
|
32
|
+
* @param values object
|
|
33
|
+
* @param constraints object
|
|
34
|
+
* @returns {boolean}
|
|
35
|
+
*/
|
|
36
|
+
|
|
37
|
+
|
|
38
|
+
validateAgainstConstraints(values, constraints) {
|
|
39
|
+
const validation = (0, _validate.default)(values, constraints);
|
|
40
|
+
return typeof validation === 'undefined';
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
exports.default = Model;
|
|
@@ -0,0 +1,150 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.default = exports.RESPONSE_HEADERS = exports.DEFAULT_MESSAGE = void 0;
|
|
7
|
+
|
|
8
|
+
var _ = _interopRequireDefault(require(".."));
|
|
9
|
+
|
|
10
|
+
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
11
|
+
|
|
12
|
+
/**
|
|
13
|
+
*
|
|
14
|
+
* @type {object}
|
|
15
|
+
*/
|
|
16
|
+
const RESPONSE_HEADERS = {
|
|
17
|
+
'Content-Type': 'application/json',
|
|
18
|
+
'Access-Control-Allow-Origin': '*',
|
|
19
|
+
// Required for CORS support to work
|
|
20
|
+
'Access-Control-Allow-Credentials': true // Required for cookies, authorization headers with HTTPS
|
|
21
|
+
|
|
22
|
+
};
|
|
23
|
+
/**
|
|
24
|
+
* Default message provided as part of response
|
|
25
|
+
*
|
|
26
|
+
* @type {string}
|
|
27
|
+
*/
|
|
28
|
+
|
|
29
|
+
exports.RESPONSE_HEADERS = RESPONSE_HEADERS;
|
|
30
|
+
const DEFAULT_MESSAGE = 'success';
|
|
31
|
+
/**
|
|
32
|
+
* class ResponseModel
|
|
33
|
+
*/
|
|
34
|
+
|
|
35
|
+
exports.DEFAULT_MESSAGE = DEFAULT_MESSAGE;
|
|
36
|
+
|
|
37
|
+
class Index extends _.default {
|
|
38
|
+
/**
|
|
39
|
+
* ResponseModel Constructor
|
|
40
|
+
*
|
|
41
|
+
* @param data
|
|
42
|
+
* @param code
|
|
43
|
+
* @param message
|
|
44
|
+
*/
|
|
45
|
+
constructor(data = null, code = null, message = null) {
|
|
46
|
+
super();
|
|
47
|
+
this.body = {
|
|
48
|
+
data: data !== null ? data : {},
|
|
49
|
+
message: message !== null ? message : DEFAULT_MESSAGE
|
|
50
|
+
};
|
|
51
|
+
this.code = code !== null ? code : {};
|
|
52
|
+
}
|
|
53
|
+
/**
|
|
54
|
+
* Add or update a body variable
|
|
55
|
+
*
|
|
56
|
+
* @param variable
|
|
57
|
+
* @param value
|
|
58
|
+
*/
|
|
59
|
+
|
|
60
|
+
|
|
61
|
+
setBodyVariable(variable, value) {
|
|
62
|
+
this.body[variable] = value;
|
|
63
|
+
}
|
|
64
|
+
/**
|
|
65
|
+
* Set Data
|
|
66
|
+
*
|
|
67
|
+
* @param data
|
|
68
|
+
*/
|
|
69
|
+
|
|
70
|
+
|
|
71
|
+
setData(data) {
|
|
72
|
+
this.body.data = data;
|
|
73
|
+
}
|
|
74
|
+
/**
|
|
75
|
+
* Set Status Code
|
|
76
|
+
*
|
|
77
|
+
* @param code
|
|
78
|
+
*/
|
|
79
|
+
|
|
80
|
+
|
|
81
|
+
setCode(code) {
|
|
82
|
+
this.code = code;
|
|
83
|
+
}
|
|
84
|
+
/**
|
|
85
|
+
* Get Status Code
|
|
86
|
+
*
|
|
87
|
+
* @returns {*}
|
|
88
|
+
*/
|
|
89
|
+
|
|
90
|
+
|
|
91
|
+
getCode() {
|
|
92
|
+
return this.code;
|
|
93
|
+
}
|
|
94
|
+
/**
|
|
95
|
+
* Set message
|
|
96
|
+
*
|
|
97
|
+
* @param message
|
|
98
|
+
*/
|
|
99
|
+
|
|
100
|
+
|
|
101
|
+
setMessage(message) {
|
|
102
|
+
this.body.message = message;
|
|
103
|
+
}
|
|
104
|
+
/**
|
|
105
|
+
* Get Message
|
|
106
|
+
*
|
|
107
|
+
* @returns {string|*}
|
|
108
|
+
*/
|
|
109
|
+
|
|
110
|
+
|
|
111
|
+
getMessage() {
|
|
112
|
+
return this.body.message;
|
|
113
|
+
}
|
|
114
|
+
/**
|
|
115
|
+
* Geneate a response
|
|
116
|
+
*
|
|
117
|
+
* @returns {object}
|
|
118
|
+
*/
|
|
119
|
+
|
|
120
|
+
|
|
121
|
+
generate() {
|
|
122
|
+
return {
|
|
123
|
+
statusCode: this.code,
|
|
124
|
+
headers: RESPONSE_HEADERS,
|
|
125
|
+
body: JSON.stringify(this.body)
|
|
126
|
+
};
|
|
127
|
+
}
|
|
128
|
+
/**
|
|
129
|
+
* Shorthand static method
|
|
130
|
+
* that generates the response immediately
|
|
131
|
+
* if no additional processing is required.
|
|
132
|
+
*
|
|
133
|
+
* Saves only 1 line of code
|
|
134
|
+
* but keeps code terse in a lot of places.
|
|
135
|
+
*
|
|
136
|
+
* @param {*} data
|
|
137
|
+
* @param {*} code
|
|
138
|
+
* @param {*} message
|
|
139
|
+
* @returns {object}
|
|
140
|
+
*/
|
|
141
|
+
|
|
142
|
+
|
|
143
|
+
static generate(data = null, code = null, message = null) {
|
|
144
|
+
const response = new this(data, code, message);
|
|
145
|
+
return response.generate();
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
exports.default = Index;
|
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.default = exports.STATUS_TYPES = void 0;
|
|
7
|
+
|
|
8
|
+
var _index = _interopRequireDefault(require("../index"));
|
|
9
|
+
|
|
10
|
+
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
11
|
+
|
|
12
|
+
const STATUS_TYPES = {
|
|
13
|
+
OK: 'OK',
|
|
14
|
+
ACCEPTABLE_FAILURE: 'ACCEPTABLE_FAILURE',
|
|
15
|
+
APPLICATION_FAILURE: 'APPLICATION_FAILURE'
|
|
16
|
+
};
|
|
17
|
+
/**
|
|
18
|
+
* StatusModel Class
|
|
19
|
+
*/
|
|
20
|
+
|
|
21
|
+
exports.STATUS_TYPES = STATUS_TYPES;
|
|
22
|
+
|
|
23
|
+
class Index extends _index.default {
|
|
24
|
+
/**
|
|
25
|
+
* StatusModel constructor
|
|
26
|
+
*
|
|
27
|
+
* @param service
|
|
28
|
+
* @param status
|
|
29
|
+
*/
|
|
30
|
+
constructor(service, status) {
|
|
31
|
+
super();
|
|
32
|
+
this.setService(service);
|
|
33
|
+
this.setStatus(status);
|
|
34
|
+
}
|
|
35
|
+
/**
|
|
36
|
+
* Get Service
|
|
37
|
+
*
|
|
38
|
+
* @returns {*}
|
|
39
|
+
*/
|
|
40
|
+
|
|
41
|
+
|
|
42
|
+
getService() {
|
|
43
|
+
return this.service;
|
|
44
|
+
}
|
|
45
|
+
/**
|
|
46
|
+
* Set Service
|
|
47
|
+
*
|
|
48
|
+
* @param service
|
|
49
|
+
*/
|
|
50
|
+
|
|
51
|
+
|
|
52
|
+
setService(service) {
|
|
53
|
+
this.service = service;
|
|
54
|
+
}
|
|
55
|
+
/**
|
|
56
|
+
* Set the status
|
|
57
|
+
*
|
|
58
|
+
* @param status
|
|
59
|
+
*/
|
|
60
|
+
|
|
61
|
+
|
|
62
|
+
setStatus(status) {
|
|
63
|
+
if (typeof STATUS_TYPES[status] === 'undefined') {
|
|
64
|
+
throw new TypeError(`${Index.name} - ${status} is not a valid status type`);
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
this.status = status;
|
|
68
|
+
}
|
|
69
|
+
/**
|
|
70
|
+
* Get status
|
|
71
|
+
*
|
|
72
|
+
* @returns {string|*}
|
|
73
|
+
*/
|
|
74
|
+
|
|
75
|
+
|
|
76
|
+
getStatus() {
|
|
77
|
+
return this.status;
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
exports.default = Index;
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.default = exports.DEFAULT_HTTP_TIMEOUT = void 0;
|
|
7
|
+
|
|
8
|
+
var _axios = _interopRequireDefault(require("axios"));
|
|
9
|
+
|
|
10
|
+
var _dependencyAware = _interopRequireDefault(require("../dependency-injection/dependency-aware"));
|
|
11
|
+
|
|
12
|
+
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
13
|
+
|
|
14
|
+
const DEFAULT_HTTP_TIMEOUT = 10 * 1000;
|
|
15
|
+
/**
|
|
16
|
+
* HTTPService class
|
|
17
|
+
*/
|
|
18
|
+
|
|
19
|
+
exports.DEFAULT_HTTP_TIMEOUT = DEFAULT_HTTP_TIMEOUT;
|
|
20
|
+
|
|
21
|
+
class Http extends _dependencyAware.default {
|
|
22
|
+
constructor(di) {
|
|
23
|
+
super(di);
|
|
24
|
+
this.config = {
|
|
25
|
+
timeout: DEFAULT_HTTP_TIMEOUT
|
|
26
|
+
};
|
|
27
|
+
}
|
|
28
|
+
/**
|
|
29
|
+
* Sets the default timeout
|
|
30
|
+
*
|
|
31
|
+
* @param {number} ms
|
|
32
|
+
*/
|
|
33
|
+
|
|
34
|
+
|
|
35
|
+
setDefaultTimeout(ms) {
|
|
36
|
+
this.config.timeout = ms;
|
|
37
|
+
}
|
|
38
|
+
/**
|
|
39
|
+
* Performs and HTTP Request
|
|
40
|
+
*
|
|
41
|
+
* @param config
|
|
42
|
+
*/
|
|
43
|
+
|
|
44
|
+
|
|
45
|
+
async request(config) {
|
|
46
|
+
return _axios.default.request({
|
|
47
|
+
timeout: this.config.timeout,
|
|
48
|
+
headers: {},
|
|
49
|
+
...config
|
|
50
|
+
});
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
exports.default = Http;
|