@creator.co/wapi 1.2.4 → 1.2.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/.github/workflows/npmpublish.yml +1 -1
- package/README.md +216 -5
- package/dist/index.d.ts +15 -0
- package/dist/index.js.map +1 -1
- package/dist/jest.config.js +1 -1
- package/dist/jest.config.js.map +1 -1
- package/dist/package.json +13 -2
- package/dist/src/API/Request.d.ts +45 -82
- package/dist/src/API/Request.js +49 -77
- package/dist/src/API/Request.js.map +1 -1
- package/dist/src/API/Response.d.ts +94 -163
- package/dist/src/API/Response.js +101 -161
- package/dist/src/API/Response.js.map +1 -1
- package/dist/src/API/Utils.d.ts +21 -42
- package/dist/src/API/Utils.js +22 -43
- package/dist/src/API/Utils.js.map +1 -1
- package/dist/src/BaseEvent/EventProcessor.d.ts +32 -55
- package/dist/src/BaseEvent/EventProcessor.js +30 -38
- package/dist/src/BaseEvent/EventProcessor.js.map +1 -1
- package/dist/src/BaseEvent/Process.d.ts +20 -43
- package/dist/src/BaseEvent/Process.js +16 -27
- package/dist/src/BaseEvent/Process.js.map +1 -1
- package/dist/src/BaseEvent/Transaction.d.ts +104 -2
- package/dist/src/BaseEvent/Transaction.js +196 -41
- package/dist/src/BaseEvent/Transaction.js.map +1 -1
- package/dist/src/Config/Configuration.d.ts +48 -66
- package/dist/src/Config/Configuration.js +25 -42
- package/dist/src/Config/Configuration.js.map +1 -1
- package/dist/src/Config/EnvironmentVar.d.ts +30 -57
- package/dist/src/Config/EnvironmentVar.js +28 -41
- package/dist/src/Config/EnvironmentVar.js.map +1 -1
- package/dist/src/Crypto/Crypto.d.ts +17 -35
- package/dist/src/Crypto/Crypto.js +12 -21
- package/dist/src/Crypto/Crypto.js.map +1 -1
- package/dist/src/Crypto/JWT.d.ts +21 -32
- package/dist/src/Crypto/JWT.js +14 -22
- package/dist/src/Crypto/JWT.js.map +1 -1
- package/dist/src/Database/Database.d.ts +18 -0
- package/dist/src/Database/Database.js +18 -0
- package/dist/src/Database/Database.js.map +1 -0
- package/dist/src/Database/DatabaseManager.d.ts +32 -0
- package/dist/src/Database/DatabaseManager.js +50 -0
- package/dist/src/Database/DatabaseManager.js.map +1 -0
- package/dist/src/Database/DatabaseTransaction.d.ts +65 -0
- package/dist/src/Database/DatabaseTransaction.js +183 -0
- package/dist/src/Database/DatabaseTransaction.js.map +1 -0
- package/dist/src/Database/integrations/knex/KnexDatabase.d.ts +22 -0
- package/dist/src/Database/integrations/knex/KnexDatabase.js +108 -0
- package/dist/src/Database/integrations/knex/KnexDatabase.js.map +1 -0
- package/dist/src/Database/integrations/knex/KnexTransaction.d.ts +37 -0
- package/dist/src/Database/integrations/knex/KnexTransaction.js +60 -0
- package/dist/src/Database/integrations/knex/KnexTransaction.js.map +1 -0
- package/dist/src/Database/integrations/pgsql/PostgresDatabase.d.ts +30 -0
- package/dist/src/Database/integrations/pgsql/PostgresDatabase.js +108 -0
- package/dist/src/Database/integrations/pgsql/PostgresDatabase.js.map +1 -0
- package/dist/src/Database/integrations/pgsql/PostgresTransaction.d.ts +37 -0
- package/dist/src/Database/integrations/pgsql/PostgresTransaction.js +60 -0
- package/dist/src/Database/integrations/pgsql/PostgresTransaction.js.map +1 -0
- package/dist/src/Globals.d.ts +26 -94
- package/dist/src/Globals.js +26 -95
- package/dist/src/Globals.js.map +1 -1
- package/dist/src/Logger/Logger.d.ts +82 -105
- package/dist/src/Logger/Logger.js +111 -136
- package/dist/src/Logger/Logger.js.map +1 -1
- package/dist/src/Mailer/Mailer.d.ts +39 -75
- package/dist/src/Mailer/Mailer.js +36 -65
- package/dist/src/Mailer/Mailer.js.map +1 -1
- package/dist/src/Publisher/Publisher.d.ts +17 -25
- package/dist/src/Publisher/Publisher.js +21 -32
- package/dist/src/Publisher/Publisher.js.map +1 -1
- package/dist/src/Server/RouteResolver.d.ts +14 -22
- package/dist/src/Server/RouteResolver.js +21 -34
- package/dist/src/Server/RouteResolver.js.map +1 -1
- package/dist/src/Server/Router.d.ts +72 -51
- package/dist/src/Server/Router.js +8 -17
- package/dist/src/Server/Router.js.map +1 -1
- package/dist/src/Server/lib/ContainerServer.d.ts +15 -31
- package/dist/src/Server/lib/ContainerServer.js +13 -28
- package/dist/src/Server/lib/ContainerServer.js.map +1 -1
- package/dist/src/Server/lib/Server.d.ts +17 -32
- package/dist/src/Server/lib/Server.js +18 -28
- package/dist/src/Server/lib/Server.js.map +1 -1
- package/dist/src/Server/lib/container/GenericHandler.d.ts +5 -0
- package/dist/src/Server/lib/container/GenericHandler.js +16 -3
- package/dist/src/Server/lib/container/GenericHandler.js.map +1 -1
- package/dist/src/Server/lib/container/GenericHandlerEvent.d.ts +22 -37
- package/dist/src/Server/lib/container/GenericHandlerEvent.js +29 -41
- package/dist/src/Server/lib/container/GenericHandlerEvent.js.map +1 -1
- package/dist/src/Server/lib/container/HealthHandler.d.ts +6 -0
- package/dist/src/Server/lib/container/HealthHandler.js +6 -0
- package/dist/src/Server/lib/container/HealthHandler.js.map +1 -1
- package/dist/src/Server/lib/container/Proxy.d.ts +24 -52
- package/dist/src/Server/lib/container/Proxy.js +52 -52
- package/dist/src/Server/lib/container/Proxy.js.map +1 -1
- package/dist/src/Server/lib/container/Utils.d.ts +6 -10
- package/dist/src/Server/lib/container/Utils.js +6 -10
- package/dist/src/Server/lib/container/Utils.js.map +1 -1
- package/dist/src/Validation/Validator.d.ts +9 -13
- package/dist/src/Validation/Validator.js +8 -12
- package/dist/src/Validation/Validator.js.map +1 -1
- package/index.ts +15 -0
- package/jest.config.ts +1 -1
- package/package.json +13 -2
- package/src/API/Request.ts +66 -84
- package/src/API/Response.ts +144 -203
- package/src/API/Utils.ts +28 -44
- package/src/BaseEvent/EventProcessor.ts +52 -77
- package/src/BaseEvent/Process.ts +27 -52
- package/src/BaseEvent/Transaction.ts +147 -27
- package/src/Config/Configuration.ts +59 -76
- package/src/Config/EnvironmentVar.ts +39 -62
- package/src/Crypto/Crypto.ts +20 -36
- package/src/Crypto/JWT.ts +31 -35
- package/src/Database/Database.ts +19 -0
- package/src/Database/DatabaseManager.ts +51 -0
- package/src/Database/DatabaseTransaction.ts +118 -0
- package/src/Database/integrations/knex/KnexDatabase.ts +47 -0
- package/src/Database/integrations/knex/KnexTransaction.ts +51 -0
- package/src/Database/integrations/pgsql/PostgresDatabase.ts +49 -0
- package/src/Database/integrations/pgsql/PostgresTransaction.ts +54 -0
- package/src/Database/types.d.ts +49 -0
- package/src/Globals.ts +28 -96
- package/src/Logger/Logger.ts +141 -160
- package/src/Mailer/Mailer.ts +43 -76
- package/src/Publisher/Publisher.ts +31 -40
- package/src/Server/RouteResolver.ts +31 -52
- package/src/Server/Router.ts +75 -54
- package/src/Server/lib/ContainerServer.ts +20 -32
- package/src/Server/lib/Server.ts +19 -34
- package/src/Server/lib/container/GenericHandler.ts +17 -3
- package/src/Server/lib/container/GenericHandlerEvent.ts +44 -54
- package/src/Server/lib/container/HealthHandler.ts +6 -0
- package/src/Server/lib/container/Proxy.ts +39 -58
- package/src/Server/lib/container/Utils.ts +7 -10
- package/src/Validation/Validator.ts +11 -13
- package/tests/API/Response.test.ts +55 -56
- package/tests/BaseEvent/EventProcessor.test.ts +49 -50
- package/tests/BaseEvent/Process.test.ts +2 -2
- package/tests/BaseEvent/Transaction.test.ts +102 -44
- package/tests/Config/Config.test.ts +27 -27
- package/tests/Config/EnvironmentVar.test.ts +54 -18
- package/tests/Database/DatabaseManager.test.ts +55 -0
- package/tests/Database/integrations/knex/KnexDatabase.test.ts +53 -0
- package/tests/Database/integrations/knex/KnexTransaction.test.ts +133 -0
- package/tests/Database/integrations/pg/PostgresDatabase.test.ts +50 -0
- package/tests/Database/integrations/pg/PostgresTransaction.test.ts +51 -0
- package/tests/Publisher/Publisher.test.ts +3 -3
- package/tests/Server/lib/ContainerServer.test.ts +21 -22
- package/tests/Server/lib/container/GenericHandler.test.ts +31 -32
- package/tests/Server/lib/container/GenericHandlerEvent.test.ts +2 -2
- package/tests/Server/lib/container/HealthHandler.test.ts +6 -7
- package/tests/Server/lib/container/Proxy.test.ts +37 -35
- package/tsconfig.json +6 -1
package/dist/src/API/Request.js
CHANGED
|
@@ -2,21 +2,16 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
var Utils_1 = require("./Utils");
|
|
4
4
|
/**
|
|
5
|
-
*
|
|
6
|
-
*
|
|
7
|
-
* @export
|
|
8
|
-
* @class Request
|
|
9
|
-
* @typedef {Request}
|
|
10
|
-
* @template InputType
|
|
5
|
+
* Represents a request object with utility methods for accessing request information.
|
|
6
|
+
* @template InputType - The type of the request body.
|
|
11
7
|
*/
|
|
12
8
|
var Request = /** @class */ (function () {
|
|
13
9
|
/**
|
|
14
|
-
*
|
|
15
|
-
*
|
|
16
|
-
* @
|
|
17
|
-
* @param {
|
|
18
|
-
* @
|
|
19
|
-
* @param {Logger} logger
|
|
10
|
+
* Constructs a new instance of the class.
|
|
11
|
+
* @param {APIGatewayEvent} requestEvent - The API Gateway event object.
|
|
12
|
+
* @param {Context} context - The context object.
|
|
13
|
+
* @param {Logger} logger - The logger object.
|
|
14
|
+
* @returns None
|
|
20
15
|
*/
|
|
21
16
|
function Request(requestEvent, context, logger) {
|
|
22
17
|
this.requestEvent = requestEvent;
|
|
@@ -25,73 +20,58 @@ var Request = /** @class */ (function () {
|
|
|
25
20
|
logger.debug('Request context:', JSON.stringify(context));
|
|
26
21
|
}
|
|
27
22
|
/**
|
|
28
|
-
*
|
|
29
|
-
*
|
|
30
|
-
* @
|
|
31
|
-
* @param {string} paramName
|
|
32
|
-
* @returns {boolean}
|
|
23
|
+
* Checks if the given query parameter exists and has a valid value.
|
|
24
|
+
* @param {string} paramName - The name of the query parameter to check.
|
|
25
|
+
* @returns {boolean} - True if the query parameter exists and has a valid value, false otherwise.
|
|
33
26
|
*/
|
|
34
27
|
Request.prototype.containsQueryParam = function (paramName) {
|
|
35
28
|
var val = this.getQueryParam(paramName);
|
|
36
29
|
return !!val && (Utils_1.default.isValidString(val) || Utils_1.default.isValidNumber(val));
|
|
37
30
|
};
|
|
38
31
|
/**
|
|
39
|
-
*
|
|
40
|
-
*
|
|
41
|
-
* @
|
|
42
|
-
* @param {string} paramName
|
|
43
|
-
* @returns {(string | null)}
|
|
32
|
+
* Retrieves the value of a query parameter from the request event's query string parameters.
|
|
33
|
+
* @param {string} paramName - The name of the query parameter to retrieve.
|
|
34
|
+
* @returns {string | null} The value of the query parameter, or null if it does not exist.
|
|
44
35
|
*/
|
|
45
36
|
Request.prototype.getQueryParam = function (paramName) {
|
|
46
37
|
return Utils_1.default.caseInsensitiveObjectForKey(this.requestEvent.queryStringParameters, paramName);
|
|
47
38
|
};
|
|
48
39
|
/**
|
|
49
|
-
*
|
|
50
|
-
*
|
|
51
|
-
* @
|
|
52
|
-
* @param {string} headerName
|
|
53
|
-
* @returns {(string | null)}
|
|
40
|
+
* Retrieves the value of the specified header from the request event headers.
|
|
41
|
+
* @param {string} headerName - The name of the header to retrieve.
|
|
42
|
+
* @returns {string | null} - The value of the header, or null if the header is not found.
|
|
54
43
|
*/
|
|
55
44
|
Request.prototype.getHeader = function (headerName) {
|
|
56
45
|
return Utils_1.default.caseInsensitiveObjectForKey(this.requestEvent.headers, headerName);
|
|
57
46
|
};
|
|
58
|
-
//context params
|
|
59
47
|
/**
|
|
60
|
-
*
|
|
61
|
-
*
|
|
62
|
-
* @
|
|
63
|
-
* @param {string} cxtParam
|
|
64
|
-
* @returns {(any | null)}
|
|
48
|
+
* Retrieves the value of a context parameter from the request context object.
|
|
49
|
+
* @param {string} cxtParam - The name of the context parameter to retrieve.
|
|
50
|
+
* @returns The value of the context parameter, or null if it does not exist.
|
|
65
51
|
*/
|
|
66
52
|
Request.prototype.getContextParam = function (cxtParam) {
|
|
67
53
|
return Utils_1.default.caseInsensitiveObjectForKey(this.requestEvent.requestContext, cxtParam);
|
|
68
54
|
};
|
|
69
55
|
/**
|
|
70
|
-
*
|
|
71
|
-
*
|
|
72
|
-
* @
|
|
73
|
-
* @param {string} paramName
|
|
74
|
-
* @returns {boolean}
|
|
56
|
+
* Checks if the given parameter name exists in the path parameters and if its value is a valid string or number.
|
|
57
|
+
* @param {string} paramName - The name of the parameter to check.
|
|
58
|
+
* @returns {boolean} - True if the parameter exists and its value is a valid string or number, false otherwise.
|
|
75
59
|
*/
|
|
76
60
|
Request.prototype.containsPathParam = function (paramName) {
|
|
77
61
|
var val = this.getPathParam(paramName);
|
|
78
62
|
return !!val && (Utils_1.default.isValidString(val) || Utils_1.default.isValidNumber(val));
|
|
79
63
|
};
|
|
80
64
|
/**
|
|
81
|
-
*
|
|
82
|
-
*
|
|
83
|
-
* @
|
|
84
|
-
* @param {string} paramName
|
|
85
|
-
* @returns {(string | null)}
|
|
65
|
+
* Retrieves the value of a path parameter from the request event.
|
|
66
|
+
* @param {string} paramName - The name of the path parameter to retrieve.
|
|
67
|
+
* @returns {string | null} The value of the path parameter, or null if it does not exist.
|
|
86
68
|
*/
|
|
87
69
|
Request.prototype.getPathParam = function (paramName) {
|
|
88
70
|
return Utils_1.default.caseInsensitiveObjectForKey(this.requestEvent.pathParameters, paramName);
|
|
89
71
|
};
|
|
90
72
|
/**
|
|
91
|
-
*
|
|
92
|
-
*
|
|
93
|
-
* @public
|
|
94
|
-
* @returns {InputType}
|
|
73
|
+
* Retrieves the body of the request event and parses it if it is a string.
|
|
74
|
+
* @returns {InputType} The parsed body of the request event.
|
|
95
75
|
*/
|
|
96
76
|
Request.prototype.getBody = function () {
|
|
97
77
|
var b = null;
|
|
@@ -106,46 +86,36 @@ var Request = /** @class */ (function () {
|
|
|
106
86
|
return b;
|
|
107
87
|
};
|
|
108
88
|
/**
|
|
109
|
-
*
|
|
110
|
-
*
|
|
111
|
-
* @public
|
|
112
|
-
* @returns {string}
|
|
89
|
+
* Retrieves the path from the request event.
|
|
90
|
+
* @returns {string} The path of the request event.
|
|
113
91
|
*/
|
|
114
92
|
Request.prototype.getPath = function () {
|
|
115
93
|
return this.requestEvent.path;
|
|
116
94
|
};
|
|
117
95
|
/**
|
|
118
|
-
*
|
|
119
|
-
*
|
|
120
|
-
* @public
|
|
121
|
-
* @returns {string}
|
|
96
|
+
* Retrieves the HTTP method of the current request.
|
|
97
|
+
* @returns {string} The HTTP method of the request.
|
|
122
98
|
*/
|
|
123
99
|
Request.prototype.getMethod = function () {
|
|
124
100
|
return this.requestEvent.httpMethod;
|
|
125
101
|
};
|
|
126
102
|
/**
|
|
127
|
-
*
|
|
128
|
-
*
|
|
129
|
-
* @public
|
|
130
|
-
* @returns {(object | null)}
|
|
103
|
+
* Retrieves the path parameters from the request event.
|
|
104
|
+
* @returns {object | null} - The path parameters object, or null if not found.
|
|
131
105
|
*/
|
|
132
106
|
Request.prototype.getPathParams = function () {
|
|
133
107
|
return this.requestEvent.pathParameters;
|
|
134
108
|
};
|
|
135
109
|
/**
|
|
136
|
-
*
|
|
137
|
-
*
|
|
138
|
-
* @public
|
|
139
|
-
* @returns {(string | null)}
|
|
110
|
+
* Retrieves the value of the 'Authorization' header from the request.
|
|
111
|
+
* @returns The value of the 'Authorization' header, or null if it is not present.
|
|
140
112
|
*/
|
|
141
113
|
Request.prototype.getAuthorizationHeader = function () {
|
|
142
114
|
return this.getHeader('Authorization');
|
|
143
115
|
};
|
|
144
116
|
/**
|
|
145
|
-
*
|
|
146
|
-
*
|
|
147
|
-
* @public
|
|
148
|
-
* @returns {string}
|
|
117
|
+
* Retrieves the request ID associated with the current execution context.
|
|
118
|
+
* @returns {string} The request ID.
|
|
149
119
|
*/
|
|
150
120
|
Request.prototype.getRequestID = function () {
|
|
151
121
|
if (this.context.awsRequestId)
|
|
@@ -153,10 +123,8 @@ var Request = /** @class */ (function () {
|
|
|
153
123
|
return this.requestEvent.requestContext ? this.requestEvent.requestContext.requestId : 'unknown';
|
|
154
124
|
};
|
|
155
125
|
/**
|
|
156
|
-
*
|
|
157
|
-
*
|
|
158
|
-
* @public
|
|
159
|
-
* @returns {string}
|
|
126
|
+
* Retrieves the origin IP address of the request.
|
|
127
|
+
* @returns {string} The origin IP address. If the IP address is not available, it returns 'unknown'.
|
|
160
128
|
*/
|
|
161
129
|
Request.prototype.getOriginIP = function () {
|
|
162
130
|
var _a;
|
|
@@ -165,16 +133,20 @@ var Request = /** @class */ (function () {
|
|
|
165
133
|
return origin ? origin : hOrigin ? hOrigin : 'unknown';
|
|
166
134
|
};
|
|
167
135
|
/**
|
|
168
|
-
*
|
|
169
|
-
*
|
|
170
|
-
* @
|
|
171
|
-
* @
|
|
172
|
-
* @param {any[]} result
|
|
136
|
+
* Sets the fixed path parameters in the request event object.
|
|
137
|
+
* @param {any[]} keys - An array of keys representing the path parameter names.
|
|
138
|
+
* @param {any[]} result - An array of values representing the path parameter values.
|
|
139
|
+
* @returns None
|
|
173
140
|
*/
|
|
174
141
|
Request.prototype.setFixedPathParams = function (keys, result) {
|
|
175
142
|
var _this = this;
|
|
176
143
|
this.requestEvent.pathParameters = {};
|
|
177
|
-
keys.forEach(function (key, index) {
|
|
144
|
+
keys.forEach(function (key, index) {
|
|
145
|
+
var _a;
|
|
146
|
+
if ((_a = _this.requestEvent) === null || _a === void 0 ? void 0 : _a.pathParameters) {
|
|
147
|
+
_this.requestEvent.pathParameters[key.name] = result[index + 1];
|
|
148
|
+
}
|
|
149
|
+
});
|
|
178
150
|
};
|
|
179
151
|
return Request;
|
|
180
152
|
}());
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Request.js","sourceRoot":"","sources":["../../../src/API/Request.ts"],"names":[],"mappings":";;AAEA,iCAA2B;
|
|
1
|
+
{"version":3,"file":"Request.js","sourceRoot":"","sources":["../../../src/API/Request.ts"],"names":[],"mappings":";;AAEA,iCAA2B;AAG3B;;;GAGG;AACH;IAWE;;;;;;OAMG;IACH,iBAAY,YAA6B,EAAE,OAAgB,EAAE,MAAc;QACzE,IAAI,CAAC,YAAY,GAAG,YAAY,CAAA;QAChC,IAAI,CAAC,OAAO,GAAG,OAAO,CAAA;QACtB,MAAM,CAAC,KAAK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AM,OAAO,GAAG,IAAI,CAAC,SAAS,CAAC,iBAAiB,CAAC,CAAA;QACjD,OAAO,MAAM,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,SAAS,CAAA;IACxD,CAAC;IAED;;;;;OAKG;IACI,oCAAkB,GAAzB,UAA0B,IAAW,EAAE,MAAa;QAApD,iBAOC;QANC,IAAI,CAAC,YAAY,CAAC,cAAc,GAAG,EAAE,CAAA;QACrC,IAAI,CAAC,OAAO,CAAC,UAAC,GAAG,EAAE,KAAK;;YACtB,IAAI,MAAA,KAAI,CAAC,YAAY,0CAAE,cAAc,EAAE;gBACrC,KAAI,CAAC,YAAY,CAAC,cAAc,CAAC,GAAG,CAAC,IAAI,CAAC,GAAG,MAAM,CAAC,KAAK,GAAG,CAAC,CAAC,CAAA;aAC/D;QACH,CAAC,CAAC,CAAA;IACJ,CAAC;IACH,cAAC;AAAD,CAAC,AAjKD,IAiKC"}
|
|
@@ -1,97 +1,71 @@
|
|
|
1
1
|
import type { Context } from 'aws-lambda';
|
|
2
2
|
import Transaction from '../BaseEvent/Transaction';
|
|
3
3
|
/**
|
|
4
|
-
*
|
|
5
|
-
*
|
|
6
|
-
* @
|
|
7
|
-
* @
|
|
4
|
+
* Represents an error response from an API.
|
|
5
|
+
* @typedef {Object} ResponseErrorType
|
|
6
|
+
* @property {string} err - The error message.
|
|
7
|
+
* @property {string} [errCode] - The error code, if available.
|
|
8
8
|
*/
|
|
9
9
|
export type ResponseErrorType = {
|
|
10
10
|
err: string;
|
|
11
11
|
errCode?: string;
|
|
12
12
|
};
|
|
13
13
|
/**
|
|
14
|
-
*
|
|
15
|
-
*
|
|
16
|
-
* @export
|
|
17
|
-
* @class Response
|
|
18
|
-
* @typedef {Response}
|
|
19
|
-
* @template [BodyType=null]
|
|
14
|
+
* Represents a response object with various methods for building and manipulating the response.
|
|
15
|
+
* @template BodyType - The type of the response body.
|
|
20
16
|
*/
|
|
21
17
|
export default class Response<BodyType = null> {
|
|
22
18
|
/**
|
|
23
|
-
*
|
|
24
|
-
*
|
|
25
|
-
* @private
|
|
19
|
+
* The private property that stores the status code.
|
|
26
20
|
* @type {number}
|
|
21
|
+
* @private
|
|
27
22
|
*/
|
|
28
|
-
private
|
|
23
|
+
private statusCode;
|
|
29
24
|
/**
|
|
30
|
-
*
|
|
31
|
-
*
|
|
25
|
+
* Private property representing the body of an object.
|
|
26
|
+
* @type {any}
|
|
32
27
|
* @private
|
|
33
|
-
* @type {*}
|
|
34
28
|
*/
|
|
35
|
-
private
|
|
29
|
+
private body;
|
|
36
30
|
/**
|
|
37
|
-
*
|
|
38
|
-
*
|
|
39
|
-
* @private
|
|
31
|
+
* Indicates whether the object is currently piping out.
|
|
40
32
|
* @type {boolean}
|
|
41
33
|
*/
|
|
42
|
-
private
|
|
34
|
+
private isPipingOut;
|
|
43
35
|
/**
|
|
44
|
-
*
|
|
45
|
-
*
|
|
46
|
-
* @private
|
|
47
|
-
* @type {object}
|
|
36
|
+
* Private property that stores the headers as an object.
|
|
48
37
|
*/
|
|
49
|
-
private
|
|
38
|
+
private headers;
|
|
50
39
|
/**
|
|
51
|
-
*
|
|
52
|
-
*
|
|
53
|
-
* @public
|
|
54
|
-
* @readonly
|
|
55
|
-
* @type {boolean}
|
|
40
|
+
* Determines whether streaming is enabled or not.
|
|
41
|
+
* @returns {boolean} - True if streaming is enabled, false otherwise.
|
|
56
42
|
*/
|
|
57
43
|
readonly shouldStream: boolean;
|
|
58
44
|
/**
|
|
59
|
-
*
|
|
60
|
-
*
|
|
61
|
-
* @public
|
|
62
|
-
* @readonly
|
|
45
|
+
* Indicates whether the request body should be treated as raw data.
|
|
63
46
|
* @type {boolean}
|
|
64
47
|
*/
|
|
65
48
|
readonly rawBody: boolean;
|
|
66
49
|
/**
|
|
67
|
-
*
|
|
68
|
-
*
|
|
69
|
-
*
|
|
70
|
-
* @readonly
|
|
71
|
-
* @type {boolean}
|
|
50
|
+
* A boolean flag indicating whether to throw an error when encountering errors.
|
|
51
|
+
* If set to true, any errors encountered will result in an exception being thrown.
|
|
52
|
+
* If set to false, errors will be logged but the program will continue execution.
|
|
72
53
|
*/
|
|
73
54
|
readonly throwOnErrors: boolean;
|
|
74
55
|
/**
|
|
75
|
-
*
|
|
76
|
-
*
|
|
77
|
-
* @public
|
|
78
|
-
* @readonly
|
|
56
|
+
* Indicates whether the transaction ID is disabled.
|
|
79
57
|
* @type {boolean}
|
|
80
58
|
*/
|
|
81
59
|
readonly disableTransactionID: boolean;
|
|
82
60
|
/**
|
|
83
|
-
*
|
|
84
|
-
*
|
|
85
|
-
* @
|
|
86
|
-
* @param {
|
|
87
|
-
* @param {
|
|
88
|
-
* @param {
|
|
89
|
-
*
|
|
90
|
-
*
|
|
91
|
-
* throwOnErrors?: boolean
|
|
92
|
-
* disableTransactionID?: boolean
|
|
93
|
-
* }
|
|
94
|
-
* | undefined)\} [optBehaviour]
|
|
61
|
+
* Constructs a new Response object with the given status code, body, and optional behavior.
|
|
62
|
+
* @param {number} statusCode - The HTTP status code of the response.
|
|
63
|
+
* @param {BodyType} body - The body of the response.
|
|
64
|
+
* @param {Object} [optBehaviour] - Optional behavior configuration for the response.
|
|
65
|
+
* @param {boolean} [optBehaviour.shouldStream] - Indicates whether the response should be streamed.
|
|
66
|
+
* @param {boolean} [optBehaviour.rawBody] - Indicates whether the response body should be treated as raw data.
|
|
67
|
+
* @param {boolean} [optBehaviour.throwOnErrors] - Indicates whether errors should be thrown for non-successful status codes.
|
|
68
|
+
* @param {boolean} [optBehaviour
|
|
95
69
|
*/
|
|
96
70
|
constructor(statusCode: number, body: BodyType, optBehaviour?: {
|
|
97
71
|
shouldStream?: boolean;
|
|
@@ -100,157 +74,114 @@ export default class Response<BodyType = null> {
|
|
|
100
74
|
disableTransactionID?: boolean;
|
|
101
75
|
} | undefined);
|
|
102
76
|
/**
|
|
103
|
-
*
|
|
104
|
-
*
|
|
105
|
-
* @public
|
|
106
|
-
* @returns {number}
|
|
77
|
+
* Get the status code of the response.
|
|
78
|
+
* @returns {number} The status code.
|
|
107
79
|
*/
|
|
108
80
|
getCode(): number;
|
|
109
81
|
/**
|
|
110
|
-
*
|
|
111
|
-
*
|
|
112
|
-
* @public
|
|
113
|
-
* @returns {BodyType}
|
|
82
|
+
* Get the body of the object.
|
|
83
|
+
* @returns {BodyType} The body of the object.
|
|
114
84
|
*/
|
|
115
85
|
getBody(): BodyType;
|
|
116
86
|
/**
|
|
117
|
-
*
|
|
118
|
-
*
|
|
119
|
-
* @
|
|
120
|
-
* @
|
|
121
|
-
* @param {*} value
|
|
87
|
+
* Appends a key-value pair into the body object.
|
|
88
|
+
* @param {string} key - The key to append.
|
|
89
|
+
* @param {any} value - The value to append.
|
|
90
|
+
* @returns None
|
|
122
91
|
*/
|
|
123
92
|
appendIntoBody(key: string, value: any): void;
|
|
124
93
|
/**
|
|
125
|
-
*
|
|
126
|
-
*
|
|
127
|
-
* @
|
|
128
|
-
* @
|
|
129
|
-
* @param {*} value
|
|
94
|
+
* Appends a header to the existing headers object.
|
|
95
|
+
* @param {string} key - The key of the header.
|
|
96
|
+
* @param {any} value - The value of the header.
|
|
97
|
+
* @returns None
|
|
130
98
|
*/
|
|
131
99
|
appendHeader(key: string, value: any): void;
|
|
132
100
|
/**
|
|
133
|
-
*
|
|
134
|
-
*
|
|
135
|
-
* @
|
|
136
|
-
* @
|
|
137
|
-
* @
|
|
138
|
-
* @param {Transaction<any, any, any>} transaction
|
|
139
|
-
* @param {boolean} _optDoNotCallContext
|
|
140
|
-
* @returns {Promise<void>}
|
|
101
|
+
* Builds the response for the given context and transaction.
|
|
102
|
+
* @param {Context} context - The context object.
|
|
103
|
+
* @param {Transaction<any, any, any>} transaction - The transaction object.
|
|
104
|
+
* @param {boolean} optDoNotCallContext - Optional flag to indicate whether to call the context or not.
|
|
105
|
+
* @returns {Promise<void>} - A promise that resolves when the response is built.
|
|
141
106
|
*/
|
|
142
|
-
build(context: Context, transaction: Transaction<any, any, any>,
|
|
107
|
+
build(context: Context, transaction: Transaction<any, any, any>, optDoNotCallContext: boolean): Promise<void>;
|
|
143
108
|
/**
|
|
144
|
-
*
|
|
145
|
-
*
|
|
146
|
-
* @
|
|
147
|
-
* @param {Context} context
|
|
109
|
+
* Private method that pipes the response to the given context.
|
|
110
|
+
* @param {Context} context - The context object provided by AWS Lambda.
|
|
111
|
+
* @returns None
|
|
148
112
|
*/
|
|
149
|
-
private
|
|
113
|
+
private pipe;
|
|
150
114
|
/**
|
|
151
|
-
*
|
|
152
|
-
*
|
|
153
|
-
* @
|
|
154
|
-
* @
|
|
155
|
-
* @param {Transaction<null, BodyType>} transaction
|
|
115
|
+
* Private method that handles the raw context of a transaction.
|
|
116
|
+
* @param {Context} context - The context object.
|
|
117
|
+
* @param {Transaction<null, BodyType>} transaction - The transaction object.
|
|
118
|
+
* @returns None
|
|
156
119
|
*/
|
|
157
|
-
private
|
|
120
|
+
private rawContext;
|
|
158
121
|
/**
|
|
159
|
-
*
|
|
160
|
-
*
|
|
161
|
-
* @
|
|
162
|
-
* @static
|
|
163
|
-
* @param {string} paramName
|
|
164
|
-
* @returns {Response<ResponseErrorType>}
|
|
122
|
+
* Generates a response object for a missing path parameter error.
|
|
123
|
+
* @param {string} paramName - The name of the missing path parameter.
|
|
124
|
+
* @returns {Response<ResponseErrorType>} - The response object with error details.
|
|
165
125
|
*/
|
|
166
126
|
static MissingParamResponse(paramName: string): Response<ResponseErrorType>;
|
|
167
127
|
/**
|
|
168
|
-
*
|
|
169
|
-
*
|
|
170
|
-
* @
|
|
171
|
-
* @static
|
|
172
|
-
* @param {string} paramName
|
|
173
|
-
* @returns {Response<ResponseErrorType>}
|
|
128
|
+
* Creates a response object for a missing query parameter error.
|
|
129
|
+
* @param {string} paramName - The name of the missing query parameter.
|
|
130
|
+
* @returns {Response<ResponseErrorType>} - The response object with error details.
|
|
174
131
|
*/
|
|
175
132
|
static MissingQueryResponse(paramName: string): Response<ResponseErrorType>;
|
|
176
133
|
/**
|
|
177
|
-
*
|
|
178
|
-
*
|
|
179
|
-
* @
|
|
180
|
-
* @
|
|
181
|
-
* @
|
|
182
|
-
* @param {?string} [errCode]
|
|
183
|
-
* @param {?*} [optBody]
|
|
184
|
-
* @returns {Response<ResponseErrorType>}
|
|
134
|
+
* Creates a BadRequestResponse object with the given parameters.
|
|
135
|
+
* @param {string} [msg] - The error message.
|
|
136
|
+
* @param {string} [errCode] - The error code.
|
|
137
|
+
* @param {any} [optBody] - Optional additional body data.
|
|
138
|
+
* @returns {Response<ResponseErrorType>} - The BadRequestResponse object.
|
|
185
139
|
*/
|
|
186
140
|
static BadRequestResponse(msg?: string, errCode?: string, optBody?: any): Response<ResponseErrorType>;
|
|
187
141
|
/**
|
|
188
|
-
*
|
|
189
|
-
*
|
|
190
|
-
* @
|
|
191
|
-
* @
|
|
192
|
-
* @
|
|
193
|
-
* @param {?string} [errCode]
|
|
194
|
-
* @param {?*} [optBody]
|
|
195
|
-
* @returns {Response<ResponseErrorType>}
|
|
142
|
+
* Creates a BadRequestResponse object with rollback option.
|
|
143
|
+
* @param {string} msg - The error message.
|
|
144
|
+
* @param {string} [errCode] - The error code.
|
|
145
|
+
* @param {any} [optBody] - Optional body to include in the response.
|
|
146
|
+
* @returns {Response<ResponseErrorType>} - The BadRequestResponse object.
|
|
196
147
|
*/
|
|
197
148
|
static BadRequestResponseWithRollback(msg: string, errCode?: string, optBody?: any): Response<ResponseErrorType>;
|
|
198
149
|
/**
|
|
199
|
-
*
|
|
200
|
-
*
|
|
201
|
-
* @
|
|
202
|
-
* @
|
|
203
|
-
* @param {string} msg
|
|
204
|
-
* @param {?string} [errCode]
|
|
205
|
-
* @returns {Response<ResponseErrorType>}
|
|
150
|
+
* Creates an unauthorized response with the given error message and error code.
|
|
151
|
+
* @param {string} msg - The error message.
|
|
152
|
+
* @param {string} [errCode] - The error code (optional).
|
|
153
|
+
* @returns {Response<ResponseErrorType>} - The unauthorized response.
|
|
206
154
|
*/
|
|
207
155
|
static UnauthorizedResponse(msg: string, errCode?: string): Response<ResponseErrorType>;
|
|
208
156
|
/**
|
|
209
|
-
*
|
|
210
|
-
*
|
|
211
|
-
* @
|
|
212
|
-
* @static
|
|
213
|
-
* @template BodyType
|
|
214
|
-
* @param {BodyType} body
|
|
215
|
-
* @returns {Response<BodyType>}
|
|
157
|
+
* Creates a success response object with the given body.
|
|
158
|
+
* @param {BodyType} body - The body of the response.
|
|
159
|
+
* @returns {Response<BodyType>} - The success response object.
|
|
216
160
|
*/
|
|
217
161
|
static SuccessResponse<BodyType>(body: BodyType): Response<BodyType>;
|
|
218
162
|
/**
|
|
219
|
-
*
|
|
220
|
-
*
|
|
221
|
-
* @
|
|
222
|
-
* @static
|
|
223
|
-
* @param {string} url
|
|
224
|
-
* @returns {Response<null>}
|
|
163
|
+
* Creates a redirect response with the specified URL.
|
|
164
|
+
* @param {string} url - The URL to redirect to.
|
|
165
|
+
* @returns {Response<null>} - The redirect response.
|
|
225
166
|
*/
|
|
226
167
|
static RedirectResponse(url: string): Response<null>;
|
|
227
168
|
/**
|
|
228
|
-
*
|
|
229
|
-
*
|
|
230
|
-
* @public
|
|
231
|
-
* @static
|
|
232
|
-
* @returns {Response<null>}
|
|
169
|
+
* Creates a success response with no content.
|
|
170
|
+
* @returns {Response<null>} A response object with a status code of 204 and no content.
|
|
233
171
|
*/
|
|
234
172
|
static SuccessNoContentResponse(): Response<null>;
|
|
235
173
|
/**
|
|
236
|
-
*
|
|
237
|
-
*
|
|
238
|
-
* @
|
|
239
|
-
* @
|
|
240
|
-
* @param {*} stream
|
|
241
|
-
* @param {string} contentType
|
|
242
|
-
* @returns {Response}
|
|
174
|
+
* Creates a success response object with a streaming body and specified content type.
|
|
175
|
+
* @param {any} stream - The stream object to be used as the response body.
|
|
176
|
+
* @param {string} contentType - The content type of the response.
|
|
177
|
+
* @returns {Response} - The success response object.
|
|
243
178
|
*/
|
|
244
179
|
static SuccessStreamResponse(stream: any, contentType: string): Response;
|
|
245
180
|
/**
|
|
246
|
-
*
|
|
247
|
-
*
|
|
248
|
-
* @
|
|
249
|
-
* @
|
|
250
|
-
* @template BodyType
|
|
251
|
-
* @param {BodyType} body
|
|
252
|
-
* @param {?number} [optionalCode]
|
|
253
|
-
* @returns {Response<BodyType>}
|
|
181
|
+
* Creates a simple HTTP response with the given body and optional status code.
|
|
182
|
+
* @param {BodyType} body - The body of the response.
|
|
183
|
+
* @param {number} [optionalCode] - The optional status code of the response. Defaults to 200.
|
|
184
|
+
* @returns {Response<BodyType>} - The created response object.
|
|
254
185
|
*/
|
|
255
186
|
static SimpleResponse<BodyType>(body: BodyType, optionalCode?: number): Response<BodyType>;
|
|
256
187
|
}
|