@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/Response.js
CHANGED
|
@@ -63,22 +63,16 @@ var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
|
63
63
|
};
|
|
64
64
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
65
65
|
var Globals_1 = require("../Globals");
|
|
66
|
-
//
|
|
67
66
|
/**
|
|
68
|
-
*
|
|
69
|
-
*
|
|
70
|
-
* @
|
|
71
|
-
* @
|
|
72
|
-
* @
|
|
67
|
+
* CustomError class that extends the built-in Error class.
|
|
68
|
+
* @class
|
|
69
|
+
* @extends Error
|
|
70
|
+
* @param {any} body - The body of the error, which can be an object or a string.
|
|
71
|
+
* @constructor
|
|
72
|
+
* @property {string} name - The name of the error.
|
|
73
73
|
*/
|
|
74
74
|
var CustomError = /** @class */ (function (_super) {
|
|
75
75
|
__extends(CustomError, _super);
|
|
76
|
-
/**
|
|
77
|
-
* Creates an instance of CustomError.
|
|
78
|
-
*
|
|
79
|
-
* @constructor
|
|
80
|
-
* @param {*} body
|
|
81
|
-
*/
|
|
82
76
|
function CustomError(body) {
|
|
83
77
|
var _this = _super.call(this, body.message || 'Unknown error!') || this;
|
|
84
78
|
_this.name = body.error || 'UnknownError';
|
|
@@ -86,42 +80,32 @@ var CustomError = /** @class */ (function (_super) {
|
|
|
86
80
|
}
|
|
87
81
|
return CustomError;
|
|
88
82
|
}(Error));
|
|
89
|
-
//
|
|
90
83
|
/**
|
|
91
|
-
*
|
|
92
|
-
*
|
|
93
|
-
* @export
|
|
94
|
-
* @class Response
|
|
95
|
-
* @typedef {Response}
|
|
96
|
-
* @template [BodyType=null]
|
|
84
|
+
* Represents a response object with various methods for building and manipulating the response.
|
|
85
|
+
* @template BodyType - The type of the response body.
|
|
97
86
|
*/
|
|
98
87
|
var Response = /** @class */ (function () {
|
|
99
|
-
//
|
|
100
88
|
/**
|
|
101
|
-
*
|
|
102
|
-
*
|
|
103
|
-
* @
|
|
104
|
-
* @param {
|
|
105
|
-
* @param {
|
|
106
|
-
* @param {
|
|
107
|
-
*
|
|
108
|
-
*
|
|
109
|
-
* throwOnErrors?: boolean
|
|
110
|
-
* disableTransactionID?: boolean
|
|
111
|
-
* }
|
|
112
|
-
* | undefined)\} [optBehaviour]
|
|
89
|
+
* Constructs a new Response object with the given status code, body, and optional behavior.
|
|
90
|
+
* @param {number} statusCode - The HTTP status code of the response.
|
|
91
|
+
* @param {BodyType} body - The body of the response.
|
|
92
|
+
* @param {Object} [optBehaviour] - Optional behavior configuration for the response.
|
|
93
|
+
* @param {boolean} [optBehaviour.shouldStream] - Indicates whether the response should be streamed.
|
|
94
|
+
* @param {boolean} [optBehaviour.rawBody] - Indicates whether the response body should be treated as raw data.
|
|
95
|
+
* @param {boolean} [optBehaviour.throwOnErrors] - Indicates whether errors should be thrown for non-successful status codes.
|
|
96
|
+
* @param {boolean} [optBehaviour
|
|
113
97
|
*/
|
|
114
98
|
function Response(statusCode, body, optBehaviour) {
|
|
115
99
|
// response
|
|
116
|
-
this.
|
|
117
|
-
this.
|
|
118
|
-
this.
|
|
100
|
+
this.statusCode = statusCode;
|
|
101
|
+
this.body = body;
|
|
102
|
+
this.headers = {
|
|
119
103
|
'Access-Control-Allow-Origin': '*',
|
|
120
104
|
'Access-Control-Allow-Credentials': true,
|
|
121
105
|
'Content-Type': 'application/json',
|
|
122
106
|
};
|
|
123
107
|
// behaviour
|
|
124
|
-
this.
|
|
108
|
+
this.isPipingOut = false; //internal -- flag to indicate streaming out has started and avoid double stream call
|
|
125
109
|
// options
|
|
126
110
|
this.shouldStream = !!(optBehaviour === null || optBehaviour === void 0 ? void 0 : optBehaviour.shouldStream); //
|
|
127
111
|
this.rawBody = !!(optBehaviour === null || optBehaviour === void 0 ? void 0 : optBehaviour.rawBody);
|
|
@@ -129,75 +113,66 @@ var Response = /** @class */ (function () {
|
|
|
129
113
|
this.disableTransactionID = !!(optBehaviour === null || optBehaviour === void 0 ? void 0 : optBehaviour.disableTransactionID);
|
|
130
114
|
}
|
|
131
115
|
/**
|
|
132
|
-
*
|
|
133
|
-
*
|
|
134
|
-
* @public
|
|
135
|
-
* @returns {number}
|
|
116
|
+
* Get the status code of the response.
|
|
117
|
+
* @returns {number} The status code.
|
|
136
118
|
*/
|
|
137
119
|
Response.prototype.getCode = function () {
|
|
138
|
-
return this.
|
|
120
|
+
return this.statusCode;
|
|
139
121
|
};
|
|
140
122
|
/**
|
|
141
|
-
*
|
|
142
|
-
*
|
|
143
|
-
* @public
|
|
144
|
-
* @returns {BodyType}
|
|
123
|
+
* Get the body of the object.
|
|
124
|
+
* @returns {BodyType} The body of the object.
|
|
145
125
|
*/
|
|
146
126
|
Response.prototype.getBody = function () {
|
|
147
|
-
return this.
|
|
127
|
+
return this.body;
|
|
148
128
|
};
|
|
149
129
|
/**
|
|
150
|
-
*
|
|
151
|
-
*
|
|
152
|
-
* @
|
|
153
|
-
* @
|
|
154
|
-
* @param {*} value
|
|
130
|
+
* Appends a key-value pair into the body object.
|
|
131
|
+
* @param {string} key - The key to append.
|
|
132
|
+
* @param {any} value - The value to append.
|
|
133
|
+
* @returns None
|
|
155
134
|
*/
|
|
156
135
|
Response.prototype.appendIntoBody = function (key, value) {
|
|
157
|
-
this.
|
|
136
|
+
this.body[key] = value;
|
|
158
137
|
};
|
|
159
138
|
/**
|
|
160
|
-
*
|
|
161
|
-
*
|
|
162
|
-
* @
|
|
163
|
-
* @
|
|
164
|
-
* @param {*} value
|
|
139
|
+
* Appends a header to the existing headers object.
|
|
140
|
+
* @param {string} key - The key of the header.
|
|
141
|
+
* @param {any} value - The value of the header.
|
|
142
|
+
* @returns None
|
|
165
143
|
*/
|
|
166
144
|
Response.prototype.appendHeader = function (key, value) {
|
|
167
|
-
this.
|
|
145
|
+
this.headers[key] = value;
|
|
168
146
|
};
|
|
169
147
|
/**
|
|
170
|
-
*
|
|
171
|
-
*
|
|
172
|
-
* @
|
|
173
|
-
* @
|
|
174
|
-
* @
|
|
175
|
-
* @param {Transaction<any, any, any>} transaction
|
|
176
|
-
* @param {boolean} _optDoNotCallContext
|
|
177
|
-
* @returns {Promise<void>}
|
|
148
|
+
* Builds the response for the given context and transaction.
|
|
149
|
+
* @param {Context} context - The context object.
|
|
150
|
+
* @param {Transaction<any, any, any>} transaction - The transaction object.
|
|
151
|
+
* @param {boolean} optDoNotCallContext - Optional flag to indicate whether to call the context or not.
|
|
152
|
+
* @returns {Promise<void>} - A promise that resolves when the response is built.
|
|
178
153
|
*/
|
|
179
|
-
Response.prototype.build = function (context, transaction,
|
|
154
|
+
Response.prototype.build = function (context, transaction, optDoNotCallContext) {
|
|
180
155
|
return __awaiter(this, void 0, void 0, function () {
|
|
181
156
|
var b;
|
|
182
157
|
return __generator(this, function (_a) {
|
|
183
158
|
switch (_a.label) {
|
|
184
159
|
case 0:
|
|
185
160
|
//Stream support
|
|
186
|
-
if (this.
|
|
161
|
+
if (this.isPipingOut)
|
|
187
162
|
return [2 /*return*/];
|
|
188
163
|
if (this.shouldStream)
|
|
189
|
-
return [2 /*return*/, this.
|
|
164
|
+
return [2 /*return*/, this.pipe(context)
|
|
190
165
|
//append default fields
|
|
191
166
|
];
|
|
192
167
|
//append default fields
|
|
193
|
-
if (transaction.request.getRequestID() && this.
|
|
168
|
+
if (transaction.request.getRequestID() && this.body && !this.disableTransactionID)
|
|
194
169
|
this.appendIntoBody('transactionID', transaction.request.getRequestID()); //append transaction ID
|
|
195
170
|
//Raw response support
|
|
196
171
|
if (this.rawBody)
|
|
197
|
-
return [2 /*return*/, this.
|
|
172
|
+
return [2 /*return*/, this.rawContext(context, transaction)
|
|
198
173
|
//build response
|
|
199
174
|
];
|
|
200
|
-
b = __assign({ statusCode: this.
|
|
175
|
+
b = __assign({ statusCode: this.statusCode, headers: this.headers }, (this.body ? { body: JSON.stringify(this.body) } : {}));
|
|
201
176
|
//log response and respond to context
|
|
202
177
|
transaction.logger.debug(b);
|
|
203
178
|
if (!transaction.responseProxy) return [3 /*break*/, 2];
|
|
@@ -209,7 +184,7 @@ var Response = /** @class */ (function () {
|
|
|
209
184
|
_a.label = 2;
|
|
210
185
|
case 2:
|
|
211
186
|
//Batch does not succeed directly just on upper transaction (which will should be a batch)
|
|
212
|
-
if (!
|
|
187
|
+
if (!optDoNotCallContext)
|
|
213
188
|
context.succeed(b);
|
|
214
189
|
return [2 /*return*/];
|
|
215
190
|
}
|
|
@@ -217,50 +192,44 @@ var Response = /** @class */ (function () {
|
|
|
217
192
|
});
|
|
218
193
|
};
|
|
219
194
|
/**
|
|
220
|
-
*
|
|
221
|
-
*
|
|
222
|
-
* @
|
|
223
|
-
* @param {Context} context
|
|
195
|
+
* Private method that pipes the response to the given context.
|
|
196
|
+
* @param {Context} context - The context object provided by AWS Lambda.
|
|
197
|
+
* @returns None
|
|
224
198
|
*/
|
|
225
|
-
Response.prototype.
|
|
199
|
+
Response.prototype.pipe = function (context) {
|
|
226
200
|
//Check if not streaming
|
|
227
|
-
this.
|
|
201
|
+
this.isPipingOut = true;
|
|
228
202
|
//build response
|
|
229
203
|
var b = {
|
|
230
|
-
statusCode: this.
|
|
231
|
-
body: this.
|
|
232
|
-
headers: this.
|
|
204
|
+
statusCode: this.statusCode,
|
|
205
|
+
body: this.body,
|
|
206
|
+
headers: this.headers,
|
|
233
207
|
};
|
|
234
208
|
//log response and respond to context
|
|
235
209
|
context.succeed(b);
|
|
236
210
|
};
|
|
237
211
|
/**
|
|
238
|
-
*
|
|
239
|
-
*
|
|
240
|
-
* @
|
|
241
|
-
* @
|
|
242
|
-
* @param {Transaction<null, BodyType>} transaction
|
|
212
|
+
* Private method that handles the raw context of a transaction.
|
|
213
|
+
* @param {Context} context - The context object.
|
|
214
|
+
* @param {Transaction<null, BodyType>} transaction - The transaction object.
|
|
215
|
+
* @returns None
|
|
243
216
|
*/
|
|
244
|
-
Response.prototype.
|
|
217
|
+
Response.prototype.rawContext = function (context, transaction) {
|
|
245
218
|
//log response and respond to context
|
|
246
|
-
transaction.logger.debug(this.
|
|
219
|
+
transaction.logger.debug(this.body);
|
|
247
220
|
if (this.getCode() <= 200 && this.getCode() <= 299)
|
|
248
|
-
context.succeed(this.
|
|
221
|
+
context.succeed(this.body);
|
|
249
222
|
else {
|
|
250
223
|
if (!this.throwOnErrors)
|
|
251
|
-
context.fail(new CustomError(this.
|
|
224
|
+
context.fail(new CustomError(this.body));
|
|
252
225
|
else
|
|
253
|
-
throw new CustomError(this.
|
|
226
|
+
throw new CustomError(this.body);
|
|
254
227
|
}
|
|
255
228
|
};
|
|
256
|
-
/* Shortcuts */
|
|
257
229
|
/**
|
|
258
|
-
*
|
|
259
|
-
*
|
|
260
|
-
* @
|
|
261
|
-
* @static
|
|
262
|
-
* @param {string} paramName
|
|
263
|
-
* @returns {Response<ResponseErrorType>}
|
|
230
|
+
* Generates a response object for a missing path parameter error.
|
|
231
|
+
* @param {string} paramName - The name of the missing path parameter.
|
|
232
|
+
* @returns {Response<ResponseErrorType>} - The response object with error details.
|
|
264
233
|
*/
|
|
265
234
|
Response.MissingParamResponse = function (paramName) {
|
|
266
235
|
console.warn("Invalid request - Path parameter ".concat(paramName, " is missing."));
|
|
@@ -270,12 +239,9 @@ var Response = /** @class */ (function () {
|
|
|
270
239
|
});
|
|
271
240
|
};
|
|
272
241
|
/**
|
|
273
|
-
*
|
|
274
|
-
*
|
|
275
|
-
* @
|
|
276
|
-
* @static
|
|
277
|
-
* @param {string} paramName
|
|
278
|
-
* @returns {Response<ResponseErrorType>}
|
|
242
|
+
* Creates a response object for a missing query parameter error.
|
|
243
|
+
* @param {string} paramName - The name of the missing query parameter.
|
|
244
|
+
* @returns {Response<ResponseErrorType>} - The response object with error details.
|
|
279
245
|
*/
|
|
280
246
|
Response.MissingQueryResponse = function (paramName) {
|
|
281
247
|
console.warn("Invalid request - Query parameter ".concat(paramName, " is missing."));
|
|
@@ -285,65 +251,49 @@ var Response = /** @class */ (function () {
|
|
|
285
251
|
});
|
|
286
252
|
};
|
|
287
253
|
/**
|
|
288
|
-
*
|
|
289
|
-
*
|
|
290
|
-
* @
|
|
291
|
-
* @
|
|
292
|
-
* @
|
|
293
|
-
* @param {?string} [errCode]
|
|
294
|
-
* @param {?*} [optBody]
|
|
295
|
-
* @returns {Response<ResponseErrorType>}
|
|
254
|
+
* Creates a BadRequestResponse object with the given parameters.
|
|
255
|
+
* @param {string} [msg] - The error message.
|
|
256
|
+
* @param {string} [errCode] - The error code.
|
|
257
|
+
* @param {any} [optBody] - Optional additional body data.
|
|
258
|
+
* @returns {Response<ResponseErrorType>} - The BadRequestResponse object.
|
|
296
259
|
*/
|
|
297
260
|
Response.BadRequestResponse = function (msg, errCode, optBody) {
|
|
298
261
|
console.warn("Bad request - ".concat(msg));
|
|
299
262
|
return new Response(400, __assign(__assign({ err: msg }, (errCode ? { errCode: errCode } : {})), (optBody || {})));
|
|
300
263
|
};
|
|
301
264
|
/**
|
|
302
|
-
*
|
|
303
|
-
*
|
|
304
|
-
* @
|
|
305
|
-
* @
|
|
306
|
-
* @
|
|
307
|
-
* @param {?string} [errCode]
|
|
308
|
-
* @param {?*} [optBody]
|
|
309
|
-
* @returns {Response<ResponseErrorType>}
|
|
265
|
+
* Creates a BadRequestResponse object with rollback option.
|
|
266
|
+
* @param {string} msg - The error message.
|
|
267
|
+
* @param {string} [errCode] - The error code.
|
|
268
|
+
* @param {any} [optBody] - Optional body to include in the response.
|
|
269
|
+
* @returns {Response<ResponseErrorType>} - The BadRequestResponse object.
|
|
310
270
|
*/
|
|
311
271
|
Response.BadRequestResponseWithRollback = function (msg, errCode, optBody) {
|
|
312
272
|
console.warn("Bad request - ".concat(msg));
|
|
313
273
|
return new Response(400, __assign(__assign({ err: msg, rollback: true }, (errCode ? { errCode: errCode } : {})), (optBody || {})));
|
|
314
274
|
};
|
|
315
275
|
/**
|
|
316
|
-
*
|
|
317
|
-
*
|
|
318
|
-
* @
|
|
319
|
-
* @
|
|
320
|
-
* @param {string} msg
|
|
321
|
-
* @param {?string} [errCode]
|
|
322
|
-
* @returns {Response<ResponseErrorType>}
|
|
276
|
+
* Creates an unauthorized response with the given error message and error code.
|
|
277
|
+
* @param {string} msg - The error message.
|
|
278
|
+
* @param {string} [errCode] - The error code (optional).
|
|
279
|
+
* @returns {Response<ResponseErrorType>} - The unauthorized response.
|
|
323
280
|
*/
|
|
324
281
|
Response.UnauthorizedResponse = function (msg, errCode) {
|
|
325
282
|
console.warn("Denying request - ".concat(msg));
|
|
326
283
|
return new Response(401, __assign({ err: msg }, (errCode ? { errCode: errCode } : {})));
|
|
327
284
|
};
|
|
328
285
|
/**
|
|
329
|
-
*
|
|
330
|
-
*
|
|
331
|
-
* @
|
|
332
|
-
* @static
|
|
333
|
-
* @template BodyType
|
|
334
|
-
* @param {BodyType} body
|
|
335
|
-
* @returns {Response<BodyType>}
|
|
286
|
+
* Creates a success response object with the given body.
|
|
287
|
+
* @param {BodyType} body - The body of the response.
|
|
288
|
+
* @returns {Response<BodyType>} - The success response object.
|
|
336
289
|
*/
|
|
337
290
|
Response.SuccessResponse = function (body) {
|
|
338
291
|
return new Response(200, (body ? body : {}));
|
|
339
292
|
};
|
|
340
293
|
/**
|
|
341
|
-
*
|
|
342
|
-
*
|
|
343
|
-
* @
|
|
344
|
-
* @static
|
|
345
|
-
* @param {string} url
|
|
346
|
-
* @returns {Response<null>}
|
|
294
|
+
* Creates a redirect response with the specified URL.
|
|
295
|
+
* @param {string} url - The URL to redirect to.
|
|
296
|
+
* @returns {Response<null>} - The redirect response.
|
|
347
297
|
*/
|
|
348
298
|
Response.RedirectResponse = function (url) {
|
|
349
299
|
var resp = new Response(302, null);
|
|
@@ -351,23 +301,17 @@ var Response = /** @class */ (function () {
|
|
|
351
301
|
return resp;
|
|
352
302
|
};
|
|
353
303
|
/**
|
|
354
|
-
*
|
|
355
|
-
*
|
|
356
|
-
* @public
|
|
357
|
-
* @static
|
|
358
|
-
* @returns {Response<null>}
|
|
304
|
+
* Creates a success response with no content.
|
|
305
|
+
* @returns {Response<null>} A response object with a status code of 204 and no content.
|
|
359
306
|
*/
|
|
360
307
|
Response.SuccessNoContentResponse = function () {
|
|
361
308
|
return new Response(204, null);
|
|
362
309
|
};
|
|
363
310
|
/**
|
|
364
|
-
*
|
|
365
|
-
*
|
|
366
|
-
* @
|
|
367
|
-
* @
|
|
368
|
-
* @param {*} stream
|
|
369
|
-
* @param {string} contentType
|
|
370
|
-
* @returns {Response}
|
|
311
|
+
* Creates a success response object with a streaming body and specified content type.
|
|
312
|
+
* @param {any} stream - The stream object to be used as the response body.
|
|
313
|
+
* @param {string} contentType - The content type of the response.
|
|
314
|
+
* @returns {Response} - The success response object.
|
|
371
315
|
*/
|
|
372
316
|
Response.SuccessStreamResponse = function (stream, contentType) {
|
|
373
317
|
var resp = new Response(200, stream, {
|
|
@@ -379,14 +323,10 @@ var Response = /** @class */ (function () {
|
|
|
379
323
|
return resp;
|
|
380
324
|
};
|
|
381
325
|
/**
|
|
382
|
-
*
|
|
383
|
-
*
|
|
384
|
-
* @
|
|
385
|
-
* @
|
|
386
|
-
* @template BodyType
|
|
387
|
-
* @param {BodyType} body
|
|
388
|
-
* @param {?number} [optionalCode]
|
|
389
|
-
* @returns {Response<BodyType>}
|
|
326
|
+
* Creates a simple HTTP response with the given body and optional status code.
|
|
327
|
+
* @param {BodyType} body - The body of the response.
|
|
328
|
+
* @param {number} [optionalCode] - The optional status code of the response. Defaults to 200.
|
|
329
|
+
* @returns {Response<BodyType>} - The created response object.
|
|
390
330
|
*/
|
|
391
331
|
Response.SimpleResponse = function (body, optionalCode) {
|
|
392
332
|
var resp = new Response(optionalCode || 200, body);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Response.js","sourceRoot":"","sources":["../../../src/API/Response.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAGA,sCAAgC;
|
|
1
|
+
{"version":3,"file":"Response.js","sourceRoot":"","sources":["../../../src/API/Response.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I,QAAQ,CAAW,YAAY,IAAI,GAAG,EAAE,IAAI,CAAC,CAAA;QAC9D,OAAO,IAAI,CAAA;IACb,CAAC;IACH,eAAC;AAAD,CAAC,AAtUD,IAsUC"}
|
package/dist/src/API/Utils.d.ts
CHANGED
|
@@ -1,63 +1,42 @@
|
|
|
1
1
|
/**
|
|
2
|
-
*
|
|
3
|
-
*
|
|
4
|
-
* @export
|
|
5
|
-
* @class Utils
|
|
6
|
-
* @typedef {Utils}
|
|
2
|
+
* Utility class containing various static methods for common operations.
|
|
7
3
|
*/
|
|
8
4
|
export default class Utils {
|
|
9
5
|
/**
|
|
10
|
-
*
|
|
11
|
-
*
|
|
12
|
-
* @public
|
|
13
|
-
* @static
|
|
14
|
-
* @returns {boolean}
|
|
6
|
+
* Checks if the application is running in a hybridless container.
|
|
7
|
+
* @returns {boolean} - True if the application is running in a hybridless container, false otherwise.
|
|
15
8
|
*/
|
|
16
9
|
static isHybridlessContainer(): boolean;
|
|
17
10
|
/**
|
|
18
|
-
*
|
|
19
|
-
*
|
|
20
|
-
* @
|
|
21
|
-
* @static
|
|
22
|
-
* @param {string} string
|
|
23
|
-
* @returns {boolean}
|
|
11
|
+
* Checks if a given string is valid.
|
|
12
|
+
* @param {string} string - The string to check.
|
|
13
|
+
* @returns {boolean} - True if the string is valid, false otherwise.
|
|
24
14
|
*/
|
|
25
15
|
static isValidString(string: string): boolean;
|
|
26
16
|
/**
|
|
27
|
-
*
|
|
28
|
-
*
|
|
29
|
-
* @
|
|
30
|
-
* @static
|
|
31
|
-
* @param {string} string
|
|
32
|
-
* @returns {(number | null)}
|
|
17
|
+
* Parses a string into an integer and returns null if the string is not a valid number.
|
|
18
|
+
* @param {string} string - The string to parse into an integer.
|
|
19
|
+
* @returns {number | null} - The parsed integer or null if the string is not a valid number.
|
|
33
20
|
*/
|
|
34
21
|
static parseIntNullIfNaN(string: string): number | null;
|
|
35
22
|
/**
|
|
36
|
-
*
|
|
37
|
-
*
|
|
38
|
-
* @
|
|
39
|
-
* @
|
|
40
|
-
* @param {string} string
|
|
41
|
-
* @returns {(any | null)}
|
|
23
|
+
* Parses a JSON string and returns the resulting object. If the string is empty or
|
|
24
|
+
* cannot be parsed, null is returned.
|
|
25
|
+
* @param {string} string - The JSON string to parse.
|
|
26
|
+
* @returns {any | null} - The parsed object or null if the string is empty or invalid.
|
|
42
27
|
*/
|
|
43
|
-
static parseObjectNullIfEmpty(string: string): any | null;
|
|
28
|
+
static parseObjectNullIfEmpty(string: string | undefined): any | null;
|
|
44
29
|
/**
|
|
45
|
-
*
|
|
46
|
-
*
|
|
47
|
-
* @
|
|
48
|
-
* @static
|
|
49
|
-
* @param {string} number
|
|
50
|
-
* @returns {boolean}
|
|
30
|
+
* Checks if a given value is a valid number.
|
|
31
|
+
* @param {string} number - The value to be checked.
|
|
32
|
+
* @returns {boolean} - True if the value is a valid number, false otherwise.
|
|
51
33
|
*/
|
|
52
34
|
static isValidNumber(number: string): boolean;
|
|
53
35
|
/**
|
|
54
|
-
*
|
|
55
|
-
*
|
|
56
|
-
* @
|
|
57
|
-
* @
|
|
58
|
-
* @param {*} obj
|
|
59
|
-
* @param {string} key
|
|
60
|
-
* @returns {(any | null)}
|
|
36
|
+
* Retrieves the value from an object using a case-insensitive key lookup.
|
|
37
|
+
* @param {any} obj - The object to search for the key.
|
|
38
|
+
* @param {string} key - The key to search for in the object.
|
|
39
|
+
* @returns {any | null} The value associated with the key, or null if the key is not found.
|
|
61
40
|
*/
|
|
62
41
|
static caseInsensitiveObjectForKey(obj: any, key: string): any | null;
|
|
63
42
|
}
|
package/dist/src/API/Utils.js
CHANGED
|
@@ -1,61 +1,46 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
/**
|
|
4
|
-
*
|
|
5
|
-
*
|
|
6
|
-
* @export
|
|
7
|
-
* @class Utils
|
|
8
|
-
* @typedef {Utils}
|
|
4
|
+
* Utility class containing various static methods for common operations.
|
|
9
5
|
*/
|
|
10
6
|
var Utils = /** @class */ (function () {
|
|
11
7
|
function Utils() {
|
|
12
8
|
}
|
|
13
9
|
/**
|
|
14
|
-
*
|
|
15
|
-
*
|
|
16
|
-
* @public
|
|
17
|
-
* @static
|
|
18
|
-
* @returns {boolean}
|
|
10
|
+
* Checks if the application is running in a hybridless container.
|
|
11
|
+
* @returns {boolean} - True if the application is running in a hybridless container, false otherwise.
|
|
19
12
|
*/
|
|
20
13
|
Utils.isHybridlessContainer = function () {
|
|
21
14
|
return process.env.HYBRIDLESS_RUNTIME == 'true';
|
|
22
15
|
};
|
|
23
16
|
/**
|
|
24
|
-
*
|
|
25
|
-
*
|
|
26
|
-
* @
|
|
27
|
-
* @static
|
|
28
|
-
* @param {string} string
|
|
29
|
-
* @returns {boolean}
|
|
17
|
+
* Checks if a given string is valid.
|
|
18
|
+
* @param {string} string - The string to check.
|
|
19
|
+
* @returns {boolean} - True if the string is valid, false otherwise.
|
|
30
20
|
*/
|
|
31
21
|
Utils.isValidString = function (string) {
|
|
32
22
|
return (string === null || string === void 0 ? void 0 : string.length) > 0 && !Array.isArray(string);
|
|
33
23
|
};
|
|
34
24
|
/**
|
|
35
|
-
*
|
|
36
|
-
*
|
|
37
|
-
* @
|
|
38
|
-
* @static
|
|
39
|
-
* @param {string} string
|
|
40
|
-
* @returns {(number | null)}
|
|
25
|
+
* Parses a string into an integer and returns null if the string is not a valid number.
|
|
26
|
+
* @param {string} string - The string to parse into an integer.
|
|
27
|
+
* @returns {number | null} - The parsed integer or null if the string is not a valid number.
|
|
41
28
|
*/
|
|
42
29
|
Utils.parseIntNullIfNaN = function (string) {
|
|
43
30
|
var n = parseInt(string);
|
|
44
31
|
return isNaN(n) ? null : n;
|
|
45
32
|
};
|
|
46
33
|
/**
|
|
47
|
-
*
|
|
48
|
-
*
|
|
49
|
-
* @
|
|
50
|
-
* @
|
|
51
|
-
* @param {string} string
|
|
52
|
-
* @returns {(any | null)}
|
|
34
|
+
* Parses a JSON string and returns the resulting object. If the string is empty or
|
|
35
|
+
* cannot be parsed, null is returned.
|
|
36
|
+
* @param {string} string - The JSON string to parse.
|
|
37
|
+
* @returns {any | null} - The parsed object or null if the string is empty or invalid.
|
|
53
38
|
*/
|
|
54
39
|
Utils.parseObjectNullIfEmpty = function (string) {
|
|
55
40
|
var o = null;
|
|
56
41
|
try {
|
|
57
|
-
o = JSON.parse(string);
|
|
58
|
-
if (Object.keys(o).length <= 0)
|
|
42
|
+
o = string ? JSON.parse(string) : null;
|
|
43
|
+
if (o && Object.keys(o).length <= 0)
|
|
59
44
|
o = null;
|
|
60
45
|
}
|
|
61
46
|
catch (e) {
|
|
@@ -64,12 +49,9 @@ var Utils = /** @class */ (function () {
|
|
|
64
49
|
return o;
|
|
65
50
|
};
|
|
66
51
|
/**
|
|
67
|
-
*
|
|
68
|
-
*
|
|
69
|
-
* @
|
|
70
|
-
* @static
|
|
71
|
-
* @param {string} number
|
|
72
|
-
* @returns {boolean}
|
|
52
|
+
* Checks if a given value is a valid number.
|
|
53
|
+
* @param {string} number - The value to be checked.
|
|
54
|
+
* @returns {boolean} - True if the value is a valid number, false otherwise.
|
|
73
55
|
*/
|
|
74
56
|
Utils.isValidNumber = function (number) {
|
|
75
57
|
var validNumb = NaN;
|
|
@@ -82,13 +64,10 @@ var Utils = /** @class */ (function () {
|
|
|
82
64
|
return !isNaN(validNumb) && !Array.isArray(number);
|
|
83
65
|
};
|
|
84
66
|
/**
|
|
85
|
-
*
|
|
86
|
-
*
|
|
87
|
-
* @
|
|
88
|
-
* @
|
|
89
|
-
* @param {*} obj
|
|
90
|
-
* @param {string} key
|
|
91
|
-
* @returns {(any | null)}
|
|
67
|
+
* Retrieves the value from an object using a case-insensitive key lookup.
|
|
68
|
+
* @param {any} obj - The object to search for the key.
|
|
69
|
+
* @param {string} key - The key to search for in the object.
|
|
70
|
+
* @returns {any | null} The value associated with the key, or null if the key is not found.
|
|
92
71
|
*/
|
|
93
72
|
Utils.caseInsensitiveObjectForKey = function (obj, key) {
|
|
94
73
|
if (!obj)
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Utils.js","sourceRoot":"","sources":["../../../src/API/Utils.ts"],"names":[],"mappings":";;AAAA
|
|
1
|
+
{"version":3,"file":"Utils.js","sourceRoot":"","sources":["../../../src/API/Utils.ts"],"names":[],"mappings":";;AAAA;;GAEG;AACH;IAAA;IAwEA,CAAC;IAvEC;;;OAGG;IACW,2BAAqB,GAAnC;QACE,OAAO,OAAO,CAAC,GAAG,CAAC,kBAAkB,IAAI,MAAM,CAAA;IACjD,CAAC;IAED;;;;OAIG;IACW,mBAAa,GAA3B,UAA4B,MAAc;QACxC,OAAO,CAAA,MAAM,aAAN,MAAM,uBAAN,MAAM,CAAE,MAAM,IAAG,CAAC,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,MAAM,CAAC,CAAA;IACrD,CAAC;IAED;;;;OAIG;IACW,uBAAiB,GAA/B,UAAgC,MAAc;QAC5C,IAAM,CAAC,GAAG,QAAQ,CAAC,MAAM,CAAC,CAAA;QAC1B,OAAO,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,CAAA;IAC5B,CAAC;IAED;;;;;OAKG;IACW,4BAAsB,GAApC,UAAqC,MAA0B;QAC7D,IAAI,CAAC,GAAG,IAAI,CAAA;QACZ,IAAI;YACF,CAAC,GAAG,MAAM,CAAC,CAAC,CAAC,IAAI,CAAC,KAAK,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,IAAI,CAAA;YACtC,IAAI,CAAC,IAAI,MAAM,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,MAAM,IAAI,CAAC;gBAAE,CAAC,GAAG,IAAI,CAAA;SAC9C;QAAC,OAAO,CAAC,EAAE;YACV,WAAW;SACZ;QACD,OAAO,CAAC,CAAA;IACV,CAAC;IAED;;;;OAIG;IACW,mBAAa,GAA3B,UAA4B,MAAc;QACxC,IAAI,SAAS,GAAG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