@comicrelief/lambda-wrapper 1.10.1 → 1.10.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/README.md +2 -0
- package/dist/Config/Dependencies.js +0 -7
- package/dist/DependencyInjection/DependencyAware.class.js +2 -9
- package/dist/DependencyInjection/DependencyInjection.class.js +8 -24
- package/dist/Model/CloudEvent.model.js +12 -30
- package/dist/Model/Model.model.js +1 -7
- package/dist/Model/Response.model.js +10 -25
- package/dist/Model/SQS/MarketingPreference.model.js +52 -110
- package/dist/Model/SQS/Message.model.js +7 -19
- package/dist/Model/Status.model.js +5 -16
- package/dist/Service/BaseConfig.service.js +20 -41
- package/dist/Service/HTTP.service.js +3 -16
- package/dist/Service/Logger.service.js +17 -54
- package/dist/Service/Request.service.js +26 -73
- package/dist/Service/SQS.service.js +17 -70
- package/dist/Service/Timer.service.js +2 -11
- package/dist/Wrapper/LambdaTermination.js +0 -5
- package/dist/Wrapper/LambdaWrapper.js +15 -36
- package/dist/Wrapper/PromisifiedDelay.js +2 -6
- package/dist/index.js +0 -19
- package/package.json +17 -17
package/README.md
CHANGED
|
@@ -6,6 +6,8 @@
|
|
|
6
6
|
|
|
7
7
|
When writing Serverless endpoints, we have found ourselves replicating a lot of boiler plate code to do basic actions, such as reading request variables or writing to SQS. The aim of this package is to provide a wrapper for our Lambda functions, to provide some level of dependency and configuration injection and to reduce time spent on project setup.
|
|
8
8
|
|
|
9
|
+
> 🚀 [Lambda Wrapper v2 is now available in beta!](https://github.com/comicrelief/lambda-wrapper/tree/beta) This major release includes TypeScript support and some significant design changes.
|
|
10
|
+
|
|
9
11
|
## Installation & usage
|
|
10
12
|
|
|
11
13
|
Install via npm:
|
|
@@ -4,19 +4,12 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
6
|
exports.default = exports.DEPENDENCIES = exports.DEFINITIONS = void 0;
|
|
7
|
-
|
|
8
7
|
var _HTTP = _interopRequireDefault(require("../Service/HTTP.service"));
|
|
9
|
-
|
|
10
8
|
var _Logger = _interopRequireDefault(require("../Service/Logger.service"));
|
|
11
|
-
|
|
12
9
|
var _Request = _interopRequireDefault(require("../Service/Request.service"));
|
|
13
|
-
|
|
14
10
|
var _SQS = _interopRequireDefault(require("../Service/SQS.service"));
|
|
15
|
-
|
|
16
11
|
var _Timer = _interopRequireDefault(require("../Service/Timer.service"));
|
|
17
|
-
|
|
18
12
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
19
|
-
|
|
20
13
|
const DEFINITIONS = {
|
|
21
14
|
HTTP: 'HTTP',
|
|
22
15
|
LOGGER: 'LOGGER',
|
|
@@ -4,11 +4,8 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
6
|
exports.default = void 0;
|
|
7
|
-
|
|
8
7
|
var _DependencyInjection = _interopRequireDefault(require("./DependencyInjection.class"));
|
|
9
|
-
|
|
10
8
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
11
|
-
|
|
12
9
|
/**
|
|
13
10
|
* DependencyAwareClass Class
|
|
14
11
|
*/
|
|
@@ -21,27 +18,23 @@ class DependencyAwareClass {
|
|
|
21
18
|
constructor(di) {
|
|
22
19
|
this.di = di;
|
|
23
20
|
}
|
|
21
|
+
|
|
24
22
|
/**
|
|
25
23
|
* Get Dependency Injection Container
|
|
26
24
|
*
|
|
27
25
|
* @returns {DependencyInjection}
|
|
28
26
|
*/
|
|
29
|
-
|
|
30
|
-
|
|
31
27
|
getContainer() {
|
|
32
28
|
return this.di;
|
|
33
29
|
}
|
|
30
|
+
|
|
34
31
|
/**
|
|
35
32
|
* Shortcut for `this.getContainer().definitions`
|
|
36
33
|
*
|
|
37
34
|
* @returns {object}
|
|
38
35
|
*/
|
|
39
|
-
|
|
40
|
-
|
|
41
36
|
get definitions() {
|
|
42
37
|
return this.getContainer().definitions;
|
|
43
38
|
}
|
|
44
|
-
|
|
45
39
|
}
|
|
46
|
-
|
|
47
40
|
exports.default = DependencyAwareClass;
|
|
@@ -4,9 +4,7 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
6
|
exports.default = void 0;
|
|
7
|
-
|
|
8
7
|
var _Dependencies = require("../Config/Dependencies");
|
|
9
|
-
|
|
10
8
|
/**
|
|
11
9
|
* DependencyInjection class
|
|
12
10
|
*/
|
|
@@ -23,13 +21,13 @@ class DependencyInjection {
|
|
|
23
21
|
this.context = context;
|
|
24
22
|
this.dependencies = {};
|
|
25
23
|
this.configuration = configuration;
|
|
26
|
-
|
|
27
24
|
for (let x = 0; x <= 1; x += 1) {
|
|
28
25
|
// Iterate over lapper dependencies and add to container
|
|
29
26
|
Object.keys(_Dependencies.DEFINITIONS).forEach(dependencyKey => {
|
|
30
27
|
this.dependencies[dependencyKey] = new _Dependencies.DEPENDENCIES[dependencyKey](this);
|
|
31
|
-
});
|
|
28
|
+
});
|
|
32
29
|
|
|
30
|
+
// Iterate over child dependencies and add to container
|
|
33
31
|
if (typeof configuration.DEPENDENCIES !== 'undefined') {
|
|
34
32
|
Object.keys(configuration.DEPENDENCIES).forEach(dependencyKey => {
|
|
35
33
|
this.dependencies[dependencyKey] = new configuration.DEPENDENCIES[dependencyKey](this);
|
|
@@ -37,81 +35,71 @@ class DependencyInjection {
|
|
|
37
35
|
}
|
|
38
36
|
}
|
|
39
37
|
}
|
|
38
|
+
|
|
40
39
|
/**
|
|
41
40
|
* Get Dependency
|
|
42
41
|
*
|
|
43
42
|
* @param definition
|
|
44
43
|
* @returns {*}
|
|
45
44
|
*/
|
|
46
|
-
|
|
47
|
-
|
|
48
45
|
get(definition) {
|
|
49
46
|
if (typeof this.dependencies[definition] === 'undefined') {
|
|
50
47
|
throw new TypeError(`${definition} does not exist in di container`);
|
|
51
48
|
}
|
|
52
|
-
|
|
53
49
|
return this.dependencies[definition];
|
|
54
50
|
}
|
|
51
|
+
|
|
55
52
|
/**
|
|
56
53
|
* Get Event
|
|
57
54
|
*
|
|
58
55
|
* @returns {*}
|
|
59
56
|
*/
|
|
60
|
-
|
|
61
|
-
|
|
62
57
|
getEvent() {
|
|
63
58
|
return this.event;
|
|
64
59
|
}
|
|
60
|
+
|
|
65
61
|
/**
|
|
66
62
|
* Get Context
|
|
67
63
|
*
|
|
68
64
|
* @returns {*}
|
|
69
65
|
*/
|
|
70
|
-
|
|
71
|
-
|
|
72
66
|
getContext() {
|
|
73
67
|
return this.context;
|
|
74
68
|
}
|
|
69
|
+
|
|
75
70
|
/**
|
|
76
71
|
* Get Configuration
|
|
77
72
|
*
|
|
78
73
|
* @param definition string
|
|
79
74
|
* @returns {*}
|
|
80
75
|
*/
|
|
81
|
-
|
|
82
|
-
|
|
83
76
|
getConfiguration(definition = null) {
|
|
84
77
|
if (definition !== null && typeof this.configuration[definition] === 'undefined') {
|
|
85
78
|
return null;
|
|
86
79
|
}
|
|
87
|
-
|
|
88
80
|
if (typeof this.configuration[definition] !== 'undefined') {
|
|
89
81
|
return this.configuration[definition];
|
|
90
82
|
}
|
|
91
|
-
|
|
92
83
|
return this.configuration;
|
|
93
84
|
}
|
|
85
|
+
|
|
94
86
|
/**
|
|
95
87
|
* Check whether the function
|
|
96
88
|
* is being executed in a serverless-offline context
|
|
97
89
|
*
|
|
98
90
|
* @returns {boolean}
|
|
99
91
|
*/
|
|
100
|
-
|
|
101
|
-
|
|
102
92
|
get isOffline() {
|
|
103
93
|
const context = this.getContext() || {};
|
|
104
|
-
|
|
105
94
|
if (!Object.prototype.hasOwnProperty.call(context, 'invokedFunctionArn')) {
|
|
106
95
|
return true;
|
|
107
96
|
}
|
|
108
|
-
|
|
109
97
|
if (context.invokedFunctionArn.includes('offline')) {
|
|
110
98
|
return true;
|
|
111
99
|
}
|
|
112
|
-
|
|
113
100
|
return !!process.env.USE_SERVERLESS_OFFLINE;
|
|
114
101
|
}
|
|
102
|
+
|
|
115
103
|
/**
|
|
116
104
|
* Returns the definitions
|
|
117
105
|
* associated to this DependencyInjection
|
|
@@ -120,12 +108,8 @@ class DependencyInjection {
|
|
|
120
108
|
*
|
|
121
109
|
* @returns {object}
|
|
122
110
|
*/
|
|
123
|
-
|
|
124
|
-
|
|
125
111
|
get definitions() {
|
|
126
112
|
return this.configuration.DEFINITIONS;
|
|
127
113
|
}
|
|
128
|
-
|
|
129
114
|
}
|
|
130
|
-
|
|
131
115
|
exports.default = DependencyInjection;
|
|
@@ -4,13 +4,9 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
6
|
exports.default = void 0;
|
|
7
|
-
|
|
8
7
|
var _uuid = require("uuid");
|
|
9
|
-
|
|
10
8
|
var _Model = _interopRequireDefault(require("./Model.model"));
|
|
11
|
-
|
|
12
9
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
13
|
-
|
|
14
10
|
/**
|
|
15
11
|
* CloudEventModel class
|
|
16
12
|
* Class to implement cloud events - https://github.com/cloudevents/spec/blob/master/spec.md
|
|
@@ -30,127 +26,113 @@ class CloudEventModel extends _Model.default {
|
|
|
30
26
|
this.contentType = 'application/json';
|
|
31
27
|
this.data = {};
|
|
32
28
|
}
|
|
29
|
+
|
|
33
30
|
/**
|
|
34
31
|
* Get Cloud Events Version
|
|
35
32
|
*
|
|
36
33
|
* @returns {number}
|
|
37
34
|
*/
|
|
38
|
-
|
|
39
|
-
|
|
40
35
|
getCloudEventsVersion() {
|
|
41
36
|
return this.cloudEventsVersion;
|
|
42
37
|
}
|
|
38
|
+
|
|
43
39
|
/**
|
|
44
40
|
* Get event type
|
|
45
41
|
*
|
|
46
42
|
* @returns {string|*}
|
|
47
43
|
*/
|
|
48
|
-
|
|
49
|
-
|
|
50
44
|
getEventType() {
|
|
51
45
|
return this.eventType;
|
|
52
46
|
}
|
|
47
|
+
|
|
53
48
|
/**
|
|
54
49
|
* Set event type
|
|
55
50
|
*
|
|
56
51
|
* @param value string
|
|
57
52
|
*/
|
|
58
|
-
|
|
59
|
-
|
|
60
53
|
setEventType(value) {
|
|
61
54
|
this.eventType = value;
|
|
62
55
|
}
|
|
56
|
+
|
|
63
57
|
/**
|
|
64
58
|
* Get source
|
|
65
59
|
*
|
|
66
60
|
* @returns {string|*}
|
|
67
61
|
*/
|
|
68
|
-
|
|
69
|
-
|
|
70
62
|
getSource() {
|
|
71
63
|
return this.source;
|
|
72
64
|
}
|
|
65
|
+
|
|
73
66
|
/**
|
|
74
67
|
* Set source
|
|
75
68
|
*
|
|
76
69
|
* @param value string
|
|
77
70
|
*/
|
|
78
|
-
|
|
79
|
-
|
|
80
71
|
setSource(value) {
|
|
81
72
|
this.source = value;
|
|
82
73
|
}
|
|
74
|
+
|
|
83
75
|
/**
|
|
84
76
|
* Get event id
|
|
85
77
|
*
|
|
86
78
|
* @returns {*|string}
|
|
87
79
|
*/
|
|
88
|
-
|
|
89
|
-
|
|
90
80
|
getEventID() {
|
|
91
81
|
return this.eventID;
|
|
92
82
|
}
|
|
83
|
+
|
|
93
84
|
/**
|
|
94
85
|
* Get event time
|
|
95
86
|
*
|
|
96
87
|
* @returns {*|string}
|
|
97
88
|
*/
|
|
98
|
-
|
|
99
|
-
|
|
100
89
|
getEventTime() {
|
|
101
90
|
return this.eventTime;
|
|
102
91
|
}
|
|
92
|
+
|
|
103
93
|
/**
|
|
104
94
|
* Get extensions
|
|
105
95
|
*
|
|
106
96
|
* @returns {{}|*}
|
|
107
97
|
*/
|
|
108
|
-
|
|
109
|
-
|
|
110
98
|
getExtensions() {
|
|
111
99
|
return this.extensions;
|
|
112
100
|
}
|
|
101
|
+
|
|
113
102
|
/**
|
|
114
103
|
* Set extensions
|
|
115
104
|
*
|
|
116
105
|
* @param value object
|
|
117
106
|
*/
|
|
118
|
-
|
|
119
|
-
|
|
120
107
|
setExtensions(value) {
|
|
121
108
|
this.extensions = value;
|
|
122
109
|
}
|
|
110
|
+
|
|
123
111
|
/**
|
|
124
112
|
* Get content type
|
|
125
113
|
*
|
|
126
114
|
* @returns {string}
|
|
127
115
|
*/
|
|
128
|
-
|
|
129
|
-
|
|
130
116
|
getContentType() {
|
|
131
117
|
return this.contentType;
|
|
132
118
|
}
|
|
119
|
+
|
|
133
120
|
/**
|
|
134
121
|
* Get data
|
|
135
122
|
*
|
|
136
123
|
* @returns {{}|*}
|
|
137
124
|
*/
|
|
138
|
-
|
|
139
|
-
|
|
140
125
|
getData() {
|
|
141
126
|
return this.data;
|
|
142
127
|
}
|
|
128
|
+
|
|
143
129
|
/**
|
|
144
130
|
* Set data
|
|
145
131
|
*
|
|
146
132
|
* @param value object
|
|
147
133
|
*/
|
|
148
|
-
|
|
149
|
-
|
|
150
134
|
setData(value) {
|
|
151
135
|
this.data = value;
|
|
152
136
|
}
|
|
153
|
-
|
|
154
137
|
}
|
|
155
|
-
|
|
156
138
|
exports.default = CloudEventModel;
|
|
@@ -4,11 +4,8 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
6
|
exports.default = void 0;
|
|
7
|
-
|
|
8
7
|
var _validate = _interopRequireDefault(require("validate.js/validate"));
|
|
9
|
-
|
|
10
8
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
11
|
-
|
|
12
9
|
/* eslint-disable class-methods-use-this */
|
|
13
10
|
|
|
14
11
|
/**
|
|
@@ -26,6 +23,7 @@ class Model {
|
|
|
26
23
|
this[classFunctionName](value);
|
|
27
24
|
}
|
|
28
25
|
}
|
|
26
|
+
|
|
29
27
|
/**
|
|
30
28
|
* Validate values against constraints
|
|
31
29
|
*
|
|
@@ -33,13 +31,9 @@ class Model {
|
|
|
33
31
|
* @param constraints object
|
|
34
32
|
* @returns {boolean}
|
|
35
33
|
*/
|
|
36
|
-
|
|
37
|
-
|
|
38
34
|
validateAgainstConstraints(values, constraints) {
|
|
39
35
|
const validation = (0, _validate.default)(values, constraints);
|
|
40
36
|
return typeof validation === 'undefined';
|
|
41
37
|
}
|
|
42
|
-
|
|
43
38
|
}
|
|
44
|
-
|
|
45
39
|
exports.default = Model;
|
|
@@ -4,11 +4,8 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
6
|
exports.default = exports.RESPONSE_HEADERS = exports.DEFAULT_MESSAGE = void 0;
|
|
7
|
-
|
|
8
7
|
var _Model = _interopRequireDefault(require("./Model.model"));
|
|
9
|
-
|
|
10
8
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
11
|
-
|
|
12
9
|
/**
|
|
13
10
|
*
|
|
14
11
|
* @type {object}
|
|
@@ -18,22 +15,20 @@ const RESPONSE_HEADERS = {
|
|
|
18
15
|
'Access-Control-Allow-Origin': '*',
|
|
19
16
|
// Required for CORS support to work
|
|
20
17
|
'Access-Control-Allow-Credentials': true // Required for cookies, authorization headers with HTTPS
|
|
21
|
-
|
|
22
18
|
};
|
|
19
|
+
|
|
23
20
|
/**
|
|
24
21
|
* Default message provided as part of response
|
|
25
22
|
*
|
|
26
23
|
* @type {string}
|
|
27
24
|
*/
|
|
28
|
-
|
|
29
25
|
exports.RESPONSE_HEADERS = RESPONSE_HEADERS;
|
|
30
26
|
const DEFAULT_MESSAGE = 'success';
|
|
27
|
+
|
|
31
28
|
/**
|
|
32
29
|
* class ResponseModel
|
|
33
30
|
*/
|
|
34
|
-
|
|
35
31
|
exports.DEFAULT_MESSAGE = DEFAULT_MESSAGE;
|
|
36
|
-
|
|
37
32
|
class ResponseModel extends _Model.default {
|
|
38
33
|
/**
|
|
39
34
|
* ResponseModel Constructor
|
|
@@ -50,74 +45,67 @@ class ResponseModel extends _Model.default {
|
|
|
50
45
|
};
|
|
51
46
|
this.code = code !== null ? code : {};
|
|
52
47
|
}
|
|
48
|
+
|
|
53
49
|
/**
|
|
54
50
|
* Add or update a body variable
|
|
55
51
|
*
|
|
56
52
|
* @param variable
|
|
57
53
|
* @param value
|
|
58
54
|
*/
|
|
59
|
-
|
|
60
|
-
|
|
61
55
|
setBodyVariable(variable, value) {
|
|
62
56
|
this.body[variable] = value;
|
|
63
57
|
}
|
|
58
|
+
|
|
64
59
|
/**
|
|
65
60
|
* Set Data
|
|
66
61
|
*
|
|
67
62
|
* @param data
|
|
68
63
|
*/
|
|
69
|
-
|
|
70
|
-
|
|
71
64
|
setData(data) {
|
|
72
65
|
this.body.data = data;
|
|
73
66
|
}
|
|
67
|
+
|
|
74
68
|
/**
|
|
75
69
|
* Set Status Code
|
|
76
70
|
*
|
|
77
71
|
* @param code
|
|
78
72
|
*/
|
|
79
|
-
|
|
80
|
-
|
|
81
73
|
setCode(code) {
|
|
82
74
|
this.code = code;
|
|
83
75
|
}
|
|
76
|
+
|
|
84
77
|
/**
|
|
85
78
|
* Get Status Code
|
|
86
79
|
*
|
|
87
80
|
* @returns {*}
|
|
88
81
|
*/
|
|
89
|
-
|
|
90
|
-
|
|
91
82
|
getCode() {
|
|
92
83
|
return this.code;
|
|
93
84
|
}
|
|
85
|
+
|
|
94
86
|
/**
|
|
95
87
|
* Set message
|
|
96
88
|
*
|
|
97
89
|
* @param message
|
|
98
90
|
*/
|
|
99
|
-
|
|
100
|
-
|
|
101
91
|
setMessage(message) {
|
|
102
92
|
this.body.message = message;
|
|
103
93
|
}
|
|
94
|
+
|
|
104
95
|
/**
|
|
105
96
|
* Get Message
|
|
106
97
|
*
|
|
107
98
|
* @returns {string|*}
|
|
108
99
|
*/
|
|
109
|
-
|
|
110
|
-
|
|
111
100
|
getMessage() {
|
|
112
101
|
return this.body.message;
|
|
113
102
|
}
|
|
103
|
+
|
|
114
104
|
/**
|
|
115
105
|
* Geneate a response
|
|
116
106
|
*
|
|
117
107
|
* @returns {object}
|
|
118
108
|
*/
|
|
119
|
-
|
|
120
|
-
|
|
121
109
|
generate() {
|
|
122
110
|
return {
|
|
123
111
|
statusCode: this.code,
|
|
@@ -125,6 +113,7 @@ class ResponseModel extends _Model.default {
|
|
|
125
113
|
body: JSON.stringify(this.body)
|
|
126
114
|
};
|
|
127
115
|
}
|
|
116
|
+
|
|
128
117
|
/**
|
|
129
118
|
* Shorthand static method
|
|
130
119
|
* that generates the response immediately
|
|
@@ -138,13 +127,9 @@ class ResponseModel extends _Model.default {
|
|
|
138
127
|
* @param {*} message
|
|
139
128
|
* @returns {object}
|
|
140
129
|
*/
|
|
141
|
-
|
|
142
|
-
|
|
143
130
|
static generate(data = null, code = null, message = null) {
|
|
144
131
|
const response = new this(data, code, message);
|
|
145
132
|
return response.generate();
|
|
146
133
|
}
|
|
147
|
-
|
|
148
134
|
}
|
|
149
|
-
|
|
150
135
|
exports.default = ResponseModel;
|