@felloh-org/lambda-wrapper 1.0.16 → 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.
@@ -3,12 +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
7
 
8
8
  var _uuid = require("uuid");
9
9
 
10
10
  var _ = _interopRequireDefault(require(".."));
11
11
 
12
+ var _statusCodes = _interopRequireDefault(require("./status-codes"));
13
+
12
14
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
13
15
 
14
16
  /**
@@ -22,19 +24,11 @@ const RESPONSE_HEADERS = {
22
24
  'Access-Control-Allow-Credentials': true // Required for cookies, authorization headers with HTTPS
23
25
 
24
26
  };
25
- /**
26
- * Default message provided as part of response
27
- *
28
- * @type {string}
29
- */
30
-
31
- exports.RESPONSE_HEADERS = RESPONSE_HEADERS;
32
- const DEFAULT_MESSAGE = 'success';
33
27
  /**
34
28
  * class ResponseModel
35
29
  */
36
30
 
37
- exports.DEFAULT_MESSAGE = DEFAULT_MESSAGE;
31
+ exports.RESPONSE_HEADERS = RESPONSE_HEADERS;
38
32
 
39
33
  class Index extends _.default {
40
34
  /**
@@ -42,16 +36,16 @@ class Index extends _.default {
42
36
  *
43
37
  * @param data
44
38
  * @param code
45
- * @param message
46
39
  */
47
- constructor(data = null, code = null, message = null) {
40
+ constructor(data = null, code = 200) {
48
41
  super();
49
42
  this.body = {
50
43
  data: data !== null ? data : {},
51
44
  errors: {},
52
45
  meta: {
53
46
  code: code !== null ? code : {},
54
- message: message !== null ? message : DEFAULT_MESSAGE,
47
+ reason: _statusCodes.default[code].reason,
48
+ message: _statusCodes.default[code].message,
55
49
  request_id: (0, _uuid.v4)()
56
50
  }
57
51
  };
@@ -86,6 +80,8 @@ class Index extends _.default {
86
80
 
87
81
 
88
82
  setCode(code) {
83
+ this.body.meta.reason = _statusCodes.default[code].reason;
84
+ this.body.meta.message = _statusCodes.default[code].message;
89
85
  this.code = code;
90
86
  this.body.meta.code = code;
91
87
  }
@@ -109,26 +105,6 @@ class Index extends _.default {
109
105
  getCode() {
110
106
  return this.code;
111
107
  }
112
- /**
113
- * Set message
114
- *
115
- * @param message
116
- */
117
-
118
-
119
- setMessage(message) {
120
- this.body.message = message;
121
- }
122
- /**
123
- * Get Message
124
- *
125
- * @returns {string|*}
126
- */
127
-
128
-
129
- getMessage() {
130
- return this.body.message;
131
- }
132
108
  /**
133
109
  * Geneate a response
134
110
  *
@@ -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;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@felloh-org/lambda-wrapper",
3
- "version": "1.0.16",
3
+ "version": "1.0.17",
4
4
  "description": "Lambda wrapper for all Felloh Serverless Projects",
5
5
  "main": "dist/index.js",
6
6
  "scripts": {