@felloh-org/lambda-wrapper 1.0.13 → 1.0.17

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.
@@ -72,6 +72,32 @@ let Booking = (_dec = (0, _typeorm.Entity)({
72
72
  _initializerDefineProperty(this, "created_at", _descriptor10, this);
73
73
  }
74
74
 
75
+ /**
76
+ * Get Public Data
77
+ * @returns {{departure_date: string, created_at: Date, booking_reference: string, id: (*|string), customer_name: string, email: string, return_date: string}}
78
+ */
79
+ getPublicData() {
80
+ const response = {
81
+ id: this.id,
82
+ booking_reference: this.booking_reference,
83
+ created_at: this.created_at,
84
+ customer_name: this.customer_name,
85
+ departure_date: this.departure_date,
86
+ return_date: this.return_date,
87
+ email: this.email
88
+ };
89
+
90
+ if (typeof this.transactions !== 'undefined') {
91
+ response.transactions = this.transactions.map(transaction => transaction.getPublicCompactData());
92
+ }
93
+
94
+ if (typeof this.user.id !== 'undefined') {
95
+ response.user = this.user.getPublicCompactData();
96
+ }
97
+
98
+ return response;
99
+ }
100
+
75
101
  }, (_descriptor = _applyDecoratedDescriptor(_class2.prototype, "id", [_dec2], {
76
102
  configurable: true,
77
103
  enumerable: true,
@@ -41,6 +41,14 @@ let Supplier = (_dec = (0, _typeorm.Entity)({
41
41
  _initializerDefineProperty(this, "created_at", _descriptor4, this);
42
42
  }
43
43
 
44
+ getPublicData() {
45
+ return {
46
+ id: this.id,
47
+ name: this.name,
48
+ created_at: this.created_at
49
+ };
50
+ }
51
+
44
52
  }, (_descriptor = _applyDecoratedDescriptor(_class2.prototype, "id", [_dec2], {
45
53
  configurable: true,
46
54
  enumerable: true,
@@ -94,6 +94,44 @@ let PaymentLink = (_dec = (0, _typeorm.Entity)({
94
94
  return date;
95
95
  }
96
96
 
97
+ getPublicData() {
98
+ const response = {
99
+ id: this.id,
100
+ amount: this.amount,
101
+ description: this.description,
102
+ success_url: this.success_url,
103
+ failure_url: this.failure_url,
104
+ cancel_url: this.cancel_url,
105
+ customer_name: this.customer_name,
106
+ expires_at: this.expires_at,
107
+ created_at: this.created_at
108
+ };
109
+
110
+ if (this.booking !== null) {
111
+ response.booking = this.booking.getPublicData();
112
+ }
113
+
114
+ if (typeof this.transactions !== 'undefined') {
115
+ response.transactions = this.transactions.map(transaction => transaction.getPublicCompactData());
116
+ }
117
+
118
+ if (this.user !== null) {
119
+ response.user = this.user.getPublicCompactData();
120
+ }
121
+
122
+ return response;
123
+ }
124
+
125
+ getPublicCompactData() {
126
+ return {
127
+ id: this.id,
128
+ amount: this.amount,
129
+ description: this.description,
130
+ expires_at: this.expires_at,
131
+ created_at: this.created_at
132
+ }``;
133
+ }
134
+
97
135
  }, (_descriptor = _applyDecoratedDescriptor(_class2.prototype, "id", [_dec2], {
98
136
  configurable: true,
99
137
  enumerable: true,
@@ -86,6 +86,36 @@ let Transaction = (_dec = (0, _typeorm.Entity)({
86
86
  _initializerDefineProperty(this, "created_at", _descriptor11, this);
87
87
  }
88
88
 
89
+ getPublicData() {
90
+ const response = {
91
+ id: this.id,
92
+ amount: this.amount,
93
+ status: this.status.id,
94
+ method: this.method.id,
95
+ type: this.type.id,
96
+ created_at: this.created_at,
97
+ completed_at: this.completed_at
98
+ };
99
+
100
+ if (this.booking !== null) {
101
+ response.booking = this.booking.getPublicData();
102
+ }
103
+
104
+ return response;
105
+ }
106
+
107
+ getPublicCompactData() {
108
+ return {
109
+ id: this.id,
110
+ amount: this.amount,
111
+ status: this.status.id,
112
+ method: this.method.id,
113
+ type: this.type.id,
114
+ created_at: this.created_at,
115
+ completed_at: this.completed_at
116
+ };
117
+ }
118
+
89
119
  }, (_descriptor = _applyDecoratedDescriptor(_class2.prototype, "id", [_dec2], {
90
120
  configurable: true,
91
121
  enumerable: true,
@@ -63,6 +63,13 @@ let Organisation = (_dec = (0, _typeorm.Entity)({
63
63
  this.name = name;
64
64
  }
65
65
 
66
+ getPublicCompactData() {
67
+ return {
68
+ id: this.id,
69
+ name: this.name
70
+ };
71
+ }
72
+
66
73
  }, (_descriptor = _applyDecoratedDescriptor(_class2.prototype, "id", [_dec3], {
67
74
  configurable: true,
68
75
  enumerable: true,
@@ -95,6 +95,26 @@ let User = (_dec = (0, _typeorm.Entity)({
95
95
  this.last_name = lastName;
96
96
  }
97
97
 
98
+ getPublicData() {
99
+ return {
100
+ id: this.id,
101
+ email: this.email,
102
+ mobile: this.mobile,
103
+ status: this.status,
104
+ first_name: this.first_name,
105
+ last_name: this.last_name,
106
+ created_at: this.created_at,
107
+ updated_at: this.updated_at
108
+ };
109
+ }
110
+
111
+ getPublicCompactData() {
112
+ return {
113
+ id: this.id,
114
+ email: this.email
115
+ };
116
+ }
117
+
98
118
  }, (_descriptor = _applyDecoratedDescriptor(_class2.prototype, "id", [_dec2], {
99
119
  configurable: true,
100
120
  enumerable: true,
@@ -3,6 +3,12 @@
3
3
  Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
+ Object.defineProperty(exports, "UserPasswordChanged", {
7
+ enumerable: true,
8
+ get: function () {
9
+ return _changed.default;
10
+ }
11
+ });
6
12
  Object.defineProperty(exports, "UserRegistration", {
7
13
  enumerable: true,
8
14
  get: function () {
@@ -12,4 +18,6 @@ Object.defineProperty(exports, "UserRegistration", {
12
18
 
13
19
  var _registration = _interopRequireDefault(require("./user/registration"));
14
20
 
21
+ var _changed = _interopRequireDefault(require("./user/password/changed"));
22
+
15
23
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
@@ -0,0 +1,24 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.default = void 0;
7
+
8
+ var _baseEvent = _interopRequireDefault(require("../../../base-event"));
9
+
10
+ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
11
+
12
+ const EVENT_TYPE = 'user:password:changed';
13
+
14
+ class UserPasswordChanged extends _baseEvent.default {
15
+ constructor() {
16
+ super();
17
+ this.setDetailType(EVENT_TYPE);
18
+ this.setDetailParam('user', {});
19
+ }
20
+
21
+ }
22
+
23
+ var _default = UserPasswordChanged;
24
+ exports.default = _default;
@@ -16,7 +16,6 @@ class UserRegistrationEvent extends _baseEvent.default {
16
16
  super();
17
17
  this.setDetailType(EVENT_TYPE);
18
18
  this.setDetailParam('user', {});
19
- this.setDetailParam('organisation', {});
20
19
  }
21
20
 
22
21
  }
package/dist/index.js CHANGED
@@ -261,6 +261,12 @@ Object.defineProperty(exports, "UserEntity", {
261
261
  return _user.default;
262
262
  }
263
263
  });
264
+ Object.defineProperty(exports, "UserPasswordChangedEvent", {
265
+ enumerable: true,
266
+ get: function () {
267
+ return _changed.default;
268
+ }
269
+ });
264
270
  Object.defineProperty(exports, "UserRegistrationEvent", {
265
271
  enumerable: true,
266
272
  get: function () {
@@ -348,6 +354,8 @@ var _transaction2 = _interopRequireDefault(require("./entity/nuapay/transaction"
348
354
 
349
355
  var _registration = _interopRequireDefault(require("./event/user/registration"));
350
356
 
357
+ var _changed = _interopRequireDefault(require("./event/user/password/changed"));
358
+
351
359
  var _model = _interopRequireDefault(require("./model"));
352
360
 
353
361
  var _response = _interopRequireDefault(require("./model/response"));
@@ -3,10 +3,14 @@
3
3
  Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
- exports.default = exports.RESPONSE_HEADERS = exports.DEFAULT_MESSAGE = void 0;
6
+ exports.default = exports.RESPONSE_HEADERS = void 0;
7
+
8
+ var _uuid = require("uuid");
7
9
 
8
10
  var _ = _interopRequireDefault(require(".."));
9
11
 
12
+ var _statusCodes = _interopRequireDefault(require("./status-codes"));
13
+
10
14
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
11
15
 
12
16
  /**
@@ -20,19 +24,11 @@ const RESPONSE_HEADERS = {
20
24
  'Access-Control-Allow-Credentials': true // Required for cookies, authorization headers with HTTPS
21
25
 
22
26
  };
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
27
  /**
32
28
  * class ResponseModel
33
29
  */
34
30
 
35
- exports.DEFAULT_MESSAGE = DEFAULT_MESSAGE;
31
+ exports.RESPONSE_HEADERS = RESPONSE_HEADERS;
36
32
 
37
33
  class Index extends _.default {
38
34
  /**
@@ -40,13 +36,18 @@ class Index extends _.default {
40
36
  *
41
37
  * @param data
42
38
  * @param code
43
- * @param message
44
39
  */
45
- constructor(data = null, code = null, message = null) {
40
+ constructor(data = null, code = 200) {
46
41
  super();
47
42
  this.body = {
48
43
  data: data !== null ? data : {},
49
- message: message !== null ? message : DEFAULT_MESSAGE
44
+ errors: {},
45
+ meta: {
46
+ code: code !== null ? code : {},
47
+ reason: _statusCodes.default[code].reason,
48
+ message: _statusCodes.default[code].message,
49
+ request_id: (0, _uuid.v4)()
50
+ }
50
51
  };
51
52
  this.code = code !== null ? code : {};
52
53
  }
@@ -79,37 +80,30 @@ class Index extends _.default {
79
80
 
80
81
 
81
82
  setCode(code) {
83
+ this.body.meta.reason = _statusCodes.default[code].reason;
84
+ this.body.meta.message = _statusCodes.default[code].message;
82
85
  this.code = code;
86
+ this.body.meta.code = code;
83
87
  }
84
88
  /**
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
89
+ * Set a meta variable
90
+ * @param key
91
+ * @param value
98
92
  */
99
93
 
100
94
 
101
- setMessage(message) {
102
- this.body.message = message;
95
+ setMetaVariable(key, value) {
96
+ this.body.meta[key] = value;
103
97
  }
104
98
  /**
105
- * Get Message
99
+ * Get Status Code
106
100
  *
107
- * @returns {string|*}
101
+ * @returns {*}
108
102
  */
109
103
 
110
104
 
111
- getMessage() {
112
- return this.body.message;
105
+ getCode() {
106
+ return this.code;
113
107
  }
114
108
  /**
115
109
  * Geneate a response
@@ -0,0 +1,66 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.default = void 0;
7
+ const ERRORS = {
8
+ 200: {
9
+ reason: 'OK',
10
+ message: 'The request was successful'
11
+ },
12
+ 201: {
13
+ reason: 'Created',
14
+ message: 'The request was successful, and a new resource was created'
15
+ },
16
+ 204: {
17
+ reason: 'No Content',
18
+ message: 'The request was successful, but there is no response to send back'
19
+ },
20
+ 400: {
21
+ reason: 'Bad Request',
22
+ message: 'The request was invalid, for example due to missing headers'
23
+ },
24
+ 401: {
25
+ reason: 'Unauthorized',
26
+ message: 'An access token was not provided, or the provided token was invalid'
27
+ },
28
+ 403: {
29
+ reason: 'Forbidden',
30
+ message: 'A valid access token was provided, but it did not have sufficient permissions'
31
+ },
32
+ 404: {
33
+ reason: 'Not Found',
34
+ message: 'The requested resource does not exist'
35
+ },
36
+ 406: {
37
+ reason: 'Not Acceptable',
38
+ message: 'The response type you requested with your Accept header is not supported'
39
+ },
40
+ 422: {
41
+ reason: 'Unprocessable Entity',
42
+ message: 'A validation error occurred'
43
+ },
44
+ 429: {
45
+ reason: 'Too Many Requests',
46
+ message: 'You made too many requests to the API in a short period of time'
47
+ },
48
+ 500: {
49
+ reason: 'Internal Server Error',
50
+ message: 'Something went wrong on our side. Contact support or try again later.'
51
+ },
52
+ 502: {
53
+ reason: 'Bad Gateway',
54
+ message: 'The server, while acting as a gateway or proxy, received an invalid response from an inbound server it accessed while attempting to fulfill the request.'
55
+ },
56
+ 503: {
57
+ reason: 'Service Unavailable',
58
+ message: 'The server is currently unable to handle the request due to a temporary overload or scheduled maintenance, which will likely be alleviated after some delay. Try again later.'
59
+ },
60
+ 504: {
61
+ reason: 'Gateway Timeout',
62
+ message: 'The server, while acting as a gateway or proxy, did not receive a timely response from an upstream server it needed to access in order to complete the request. Try again later.'
63
+ }
64
+ };
65
+ var _default = ERRORS;
66
+ exports.default = _default;
@@ -7,6 +7,8 @@ exports.default = void 0;
7
7
 
8
8
  var _awsSdk = _interopRequireDefault(require("aws-sdk"));
9
9
 
10
+ var _dependencies = require("../config/dependencies");
11
+
10
12
  var _dependencyAware = _interopRequireDefault(require("../dependency-injection/dependency-aware"));
11
13
 
12
14
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
@@ -20,8 +22,15 @@ const Eventbridge = new _awsSdk.default.EventBridge({
20
22
 
21
23
  class EventBridge extends _dependencyAware.default {
22
24
  async put(eventModel) {
23
- const currentUser = JSON.parse(this.getContainer().getEvent().requestContext.authorizer.userEntity);
24
- eventModel.setUserBy(currentUser);
25
+ const Logger = this.getContainer().get(_dependencies.DEFINITIONS.LOGGER);
26
+
27
+ try {
28
+ const currentUser = JSON.parse(this.getContainer().getEvent().requestContext.authorizer.userEntity);
29
+ eventModel.setUserBy(currentUser);
30
+ } catch (error) {
31
+ Logger.info('no current user to event bridge event');
32
+ }
33
+
25
34
  await Eventbridge.putEvents({
26
35
  Entries: [eventModel.getBase()]
27
36
  }).promise();
@@ -24,7 +24,15 @@ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { de
24
24
  * @param outcome
25
25
  */
26
26
  const handleSuccess = (di, outcome) => {
27
- const logger = di.get(_dependencies.DEFINITIONS.LOGGER); // Outcome may be undefined as not all lambdas have a return value.
27
+ const logger = di.get(_dependencies.DEFINITIONS.LOGGER);
28
+
29
+ try {
30
+ const requestID = JSON.parse(outcome.body).meta.request_id;
31
+ logger.metric('lambda.request_id', requestID);
32
+ } catch (error) {
33
+ logger.info('unable to set request id');
34
+ } // Outcome may be undefined as not all lambdas have a return value.
35
+
28
36
 
29
37
  logger.metric('lambda.statusCode', outcome && outcome.statusCode || 200);
30
38
  return outcome;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@felloh-org/lambda-wrapper",
3
- "version": "1.0.13",
3
+ "version": "1.0.17",
4
4
  "description": "Lambda wrapper for all Felloh Serverless Projects",
5
5
  "main": "dist/index.js",
6
6
  "scripts": {