@creator.co/wapi 1.2.5 → 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.
Files changed (115) hide show
  1. package/README.md +216 -5
  2. package/dist/index.d.ts +15 -0
  3. package/dist/index.js.map +1 -1
  4. package/dist/package.json +6 -1
  5. package/dist/src/API/Request.d.ts +45 -82
  6. package/dist/src/API/Request.js +49 -77
  7. package/dist/src/API/Request.js.map +1 -1
  8. package/dist/src/API/Response.d.ts +94 -163
  9. package/dist/src/API/Response.js +101 -161
  10. package/dist/src/API/Response.js.map +1 -1
  11. package/dist/src/API/Utils.d.ts +21 -42
  12. package/dist/src/API/Utils.js +22 -43
  13. package/dist/src/API/Utils.js.map +1 -1
  14. package/dist/src/BaseEvent/EventProcessor.d.ts +32 -55
  15. package/dist/src/BaseEvent/EventProcessor.js +30 -38
  16. package/dist/src/BaseEvent/EventProcessor.js.map +1 -1
  17. package/dist/src/BaseEvent/Process.d.ts +20 -43
  18. package/dist/src/BaseEvent/Process.js +16 -27
  19. package/dist/src/BaseEvent/Process.js.map +1 -1
  20. package/dist/src/BaseEvent/Transaction.d.ts +94 -2
  21. package/dist/src/BaseEvent/Transaction.js +49 -4
  22. package/dist/src/BaseEvent/Transaction.js.map +1 -1
  23. package/dist/src/Config/Configuration.d.ts +48 -66
  24. package/dist/src/Config/Configuration.js +25 -42
  25. package/dist/src/Config/Configuration.js.map +1 -1
  26. package/dist/src/Config/EnvironmentVar.d.ts +30 -57
  27. package/dist/src/Config/EnvironmentVar.js +28 -41
  28. package/dist/src/Config/EnvironmentVar.js.map +1 -1
  29. package/dist/src/Crypto/Crypto.d.ts +17 -35
  30. package/dist/src/Crypto/Crypto.js +12 -21
  31. package/dist/src/Crypto/Crypto.js.map +1 -1
  32. package/dist/src/Crypto/JWT.d.ts +21 -32
  33. package/dist/src/Crypto/JWT.js +14 -22
  34. package/dist/src/Crypto/JWT.js.map +1 -1
  35. package/dist/src/Globals.d.ts +26 -94
  36. package/dist/src/Globals.js +26 -95
  37. package/dist/src/Globals.js.map +1 -1
  38. package/dist/src/Logger/Logger.d.ts +82 -105
  39. package/dist/src/Logger/Logger.js +111 -136
  40. package/dist/src/Logger/Logger.js.map +1 -1
  41. package/dist/src/Mailer/Mailer.d.ts +39 -75
  42. package/dist/src/Mailer/Mailer.js +36 -65
  43. package/dist/src/Mailer/Mailer.js.map +1 -1
  44. package/dist/src/Publisher/Publisher.d.ts +17 -25
  45. package/dist/src/Publisher/Publisher.js +21 -32
  46. package/dist/src/Publisher/Publisher.js.map +1 -1
  47. package/dist/src/Server/RouteResolver.d.ts +14 -22
  48. package/dist/src/Server/RouteResolver.js +21 -34
  49. package/dist/src/Server/RouteResolver.js.map +1 -1
  50. package/dist/src/Server/Router.d.ts +72 -51
  51. package/dist/src/Server/Router.js +8 -17
  52. package/dist/src/Server/Router.js.map +1 -1
  53. package/dist/src/Server/lib/ContainerServer.d.ts +15 -31
  54. package/dist/src/Server/lib/ContainerServer.js +13 -28
  55. package/dist/src/Server/lib/ContainerServer.js.map +1 -1
  56. package/dist/src/Server/lib/Server.d.ts +17 -32
  57. package/dist/src/Server/lib/Server.js +18 -28
  58. package/dist/src/Server/lib/Server.js.map +1 -1
  59. package/dist/src/Server/lib/container/GenericHandler.d.ts +5 -0
  60. package/dist/src/Server/lib/container/GenericHandler.js +16 -3
  61. package/dist/src/Server/lib/container/GenericHandler.js.map +1 -1
  62. package/dist/src/Server/lib/container/GenericHandlerEvent.d.ts +22 -37
  63. package/dist/src/Server/lib/container/GenericHandlerEvent.js +29 -41
  64. package/dist/src/Server/lib/container/GenericHandlerEvent.js.map +1 -1
  65. package/dist/src/Server/lib/container/HealthHandler.d.ts +6 -0
  66. package/dist/src/Server/lib/container/HealthHandler.js +6 -0
  67. package/dist/src/Server/lib/container/HealthHandler.js.map +1 -1
  68. package/dist/src/Server/lib/container/Proxy.d.ts +24 -52
  69. package/dist/src/Server/lib/container/Proxy.js +49 -50
  70. package/dist/src/Server/lib/container/Proxy.js.map +1 -1
  71. package/dist/src/Server/lib/container/Utils.d.ts +6 -10
  72. package/dist/src/Server/lib/container/Utils.js +6 -10
  73. package/dist/src/Server/lib/container/Utils.js.map +1 -1
  74. package/dist/src/Validation/Validator.d.ts +9 -13
  75. package/dist/src/Validation/Validator.js +8 -12
  76. package/dist/src/Validation/Validator.js.map +1 -1
  77. package/index.ts +15 -0
  78. package/package.json +6 -1
  79. package/src/API/Request.ts +66 -84
  80. package/src/API/Response.ts +144 -203
  81. package/src/API/Utils.ts +28 -44
  82. package/src/BaseEvent/EventProcessor.ts +52 -77
  83. package/src/BaseEvent/Process.ts +27 -52
  84. package/src/BaseEvent/Transaction.ts +100 -10
  85. package/src/Config/Configuration.ts +59 -76
  86. package/src/Config/EnvironmentVar.ts +39 -62
  87. package/src/Crypto/Crypto.ts +20 -36
  88. package/src/Crypto/JWT.ts +31 -35
  89. package/src/Globals.ts +28 -96
  90. package/src/Logger/Logger.ts +141 -160
  91. package/src/Mailer/Mailer.ts +43 -76
  92. package/src/Publisher/Publisher.ts +31 -40
  93. package/src/Server/RouteResolver.ts +31 -52
  94. package/src/Server/Router.ts +75 -54
  95. package/src/Server/lib/ContainerServer.ts +20 -32
  96. package/src/Server/lib/Server.ts +19 -34
  97. package/src/Server/lib/container/GenericHandler.ts +17 -3
  98. package/src/Server/lib/container/GenericHandlerEvent.ts +44 -54
  99. package/src/Server/lib/container/HealthHandler.ts +6 -0
  100. package/src/Server/lib/container/Proxy.ts +37 -57
  101. package/src/Server/lib/container/Utils.ts +7 -10
  102. package/src/Validation/Validator.ts +11 -13
  103. package/tests/API/Response.test.ts +55 -56
  104. package/tests/BaseEvent/EventProcessor.test.ts +49 -50
  105. package/tests/BaseEvent/Process.test.ts +2 -2
  106. package/tests/BaseEvent/Transaction.test.ts +48 -49
  107. package/tests/Config/Config.test.ts +27 -27
  108. package/tests/Config/EnvironmentVar.test.ts +54 -18
  109. package/tests/Publisher/Publisher.test.ts +3 -3
  110. package/tests/Server/lib/ContainerServer.test.ts +21 -22
  111. package/tests/Server/lib/container/GenericHandler.test.ts +31 -32
  112. package/tests/Server/lib/container/GenericHandlerEvent.test.ts +2 -2
  113. package/tests/Server/lib/container/HealthHandler.test.ts +6 -7
  114. package/tests/Server/lib/container/Proxy.test.ts +37 -35
  115. package/tsconfig.json +1 -1
@@ -2,21 +2,16 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  var Utils_1 = require("./Utils");
4
4
  /**
5
- * ${1:Description placeholder}
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
- * Creates an instance of Request.
15
- *
16
- * @constructor
17
- * @param {APIGatewayEvent} requestEvent
18
- * @param {Context} context
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
- * ${1:Description placeholder}
29
- *
30
- * @public
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
- * ${1:Description placeholder}
40
- *
41
- * @public
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
- * ${1:Description placeholder}
50
- *
51
- * @public
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
- * ${1:Description placeholder}
61
- *
62
- * @public
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
- * ${1:Description placeholder}
71
- *
72
- * @public
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
- * ${1:Description placeholder}
82
- *
83
- * @public
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
- * ${1:Description placeholder}
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
- * ${1:Description placeholder}
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
- * ${1:Description placeholder}
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
- * ${1:Description placeholder}
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
- * ${1:Description placeholder}
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
- * ${1:Description placeholder}
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
- * ${1:Description placeholder}
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
- * ${1:Description placeholder}
169
- *
170
- * @public
171
- * @param {any[]} keys
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) { return (_this.requestEvent.pathParameters[key.name] = result[index + 1]); });
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;AAE3B;;;;;;;GAOG;AACH;IAeE;;;;;;;OAOG;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,CAAC,eAAe,EAAE,IAAI,CAAC,SAA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E,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
- * ${1:Description placeholder}
5
- *
6
- * @export
7
- * @typedef {ResponseErrorType}
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
- * ${1:Description placeholder}
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
- * ${1:Description placeholder}
24
- *
25
- * @private
19
+ * The private property that stores the status code.
26
20
  * @type {number}
21
+ * @private
27
22
  */
28
- private _statusCode;
23
+ private statusCode;
29
24
  /**
30
- * ${1:Description placeholder}
31
- *
25
+ * Private property representing the body of an object.
26
+ * @type {any}
32
27
  * @private
33
- * @type {*}
34
28
  */
35
- private _body;
29
+ private body;
36
30
  /**
37
- * ${1:Description placeholder}
38
- *
39
- * @private
31
+ * Indicates whether the object is currently piping out.
40
32
  * @type {boolean}
41
33
  */
42
- private _isPipingOut;
34
+ private isPipingOut;
43
35
  /**
44
- * ${1:Description placeholder}
45
- *
46
- * @private
47
- * @type {object}
36
+ * Private property that stores the headers as an object.
48
37
  */
49
- private _headers;
38
+ private headers;
50
39
  /**
51
- * ${1:Description placeholder}
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
- * ${1:Description placeholder}
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
- * ${1:Description placeholder}
68
- *
69
- * @public
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
- * ${1:Description placeholder}
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
- * Creates an instance of Response.
84
- *
85
- * @constructor
86
- * @param {number} statusCode
87
- * @param {BodyType} body
88
- * @param {?(| {
89
- * shouldStream?: boolean
90
- * rawBody?: boolean
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
- * ${1:Description placeholder}
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
- * ${1:Description placeholder}
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
- * ${1:Description placeholder}
118
- *
119
- * @public
120
- * @param {string} key
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
- * ${1:Description placeholder}
126
- *
127
- * @public
128
- * @param {string} key
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
- * ${1:Description placeholder}
134
- *
135
- * @public
136
- * @async
137
- * @param {Context} context
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>, _optDoNotCallContext: boolean): Promise<void>;
107
+ build(context: Context, transaction: Transaction<any, any, any>, optDoNotCallContext: boolean): Promise<void>;
143
108
  /**
144
- * ${1:Description placeholder}
145
- *
146
- * @private
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 _pipe;
113
+ private pipe;
150
114
  /**
151
- * ${1:Description placeholder}
152
- *
153
- * @private
154
- * @param {Context} context
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 _rawContext;
120
+ private rawContext;
158
121
  /**
159
- * ${1:Description placeholder}
160
- *
161
- * @public
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
- * ${1:Description placeholder}
169
- *
170
- * @public
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
- * ${1:Description placeholder}
178
- *
179
- * @public
180
- * @static
181
- * @param {?string} [msg]
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
- * ${1:Description placeholder}
189
- *
190
- * @public
191
- * @static
192
- * @param {string} msg
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
- * ${1:Description placeholder}
200
- *
201
- * @public
202
- * @static
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
- * ${1:Description placeholder}
210
- *
211
- * @public
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
- * ${1:Description placeholder}
220
- *
221
- * @public
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
- * ${1:Description placeholder}
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
- * ${1:Description placeholder}
237
- *
238
- * @public
239
- * @static
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
- * ${1:Description placeholder}
247
- *
248
- * @public
249
- * @static
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
  }