@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
|
@@ -1,21 +1,17 @@
|
|
|
1
1
|
import { z } from 'zod';
|
|
2
2
|
import Response, { ResponseErrorType } from '../API/Response';
|
|
3
3
|
/**
|
|
4
|
-
*
|
|
5
|
-
*
|
|
6
|
-
* @
|
|
7
|
-
* @
|
|
8
|
-
* @typedef {Validator}
|
|
4
|
+
* Validates the given data against the provided schema.
|
|
5
|
+
* @param {any} data - The data to be validated.
|
|
6
|
+
* @param {z.ZodObject<any>} schema - The schema to validate against.
|
|
7
|
+
* @returns {boolean | Response<ResponseErrorType>} - Returns true if the data is valid, otherwise returns a response object with an error message.
|
|
9
8
|
*/
|
|
10
9
|
export default class Validator {
|
|
11
10
|
/**
|
|
12
|
-
*
|
|
13
|
-
*
|
|
14
|
-
* @
|
|
15
|
-
* @
|
|
16
|
-
* @param {*} data
|
|
17
|
-
* @param {z.ZodObject<any>} schema
|
|
18
|
-
* @returns {(boolean | Response<ResponseErrorType>)}
|
|
11
|
+
* Validates the given data against the provided schema.
|
|
12
|
+
* @param {any} data - The data to be validated.
|
|
13
|
+
* @param {z.ZodObject<any> | z.ZodUnion<any>} schema - The schema to validate against.
|
|
14
|
+
* @returns {boolean | Response<ResponseErrorType>} - Returns either true if the data is valid or a Response object with an error message if validation fails.
|
|
19
15
|
*/
|
|
20
|
-
static validateSchema(data: any, schema: z.ZodObject<any>): boolean | Response<ResponseErrorType>;
|
|
16
|
+
static validateSchema(data: any, schema: z.ZodObject<any> | z.ZodUnion<any>): boolean | Response<ResponseErrorType>;
|
|
21
17
|
}
|
|
@@ -4,23 +4,19 @@ var zod_1 = require("zod");
|
|
|
4
4
|
var Response_1 = require("../API/Response");
|
|
5
5
|
var Globals_1 = require("../Globals");
|
|
6
6
|
/**
|
|
7
|
-
*
|
|
8
|
-
*
|
|
9
|
-
* @
|
|
10
|
-
* @
|
|
11
|
-
* @typedef {Validator}
|
|
7
|
+
* Validates the given data against the provided schema.
|
|
8
|
+
* @param {any} data - The data to be validated.
|
|
9
|
+
* @param {z.ZodObject<any>} schema - The schema to validate against.
|
|
10
|
+
* @returns {boolean | Response<ResponseErrorType>} - Returns true if the data is valid, otherwise returns a response object with an error message.
|
|
12
11
|
*/
|
|
13
12
|
var Validator = /** @class */ (function () {
|
|
14
13
|
function Validator() {
|
|
15
14
|
}
|
|
16
15
|
/**
|
|
17
|
-
*
|
|
18
|
-
*
|
|
19
|
-
* @
|
|
20
|
-
* @
|
|
21
|
-
* @param {*} data
|
|
22
|
-
* @param {z.ZodObject<any>} schema
|
|
23
|
-
* @returns {(boolean | Response<ResponseErrorType>)}
|
|
16
|
+
* Validates the given data against the provided schema.
|
|
17
|
+
* @param {any} data - The data to be validated.
|
|
18
|
+
* @param {z.ZodObject<any> | z.ZodUnion<any>} schema - The schema to validate against.
|
|
19
|
+
* @returns {boolean | Response<ResponseErrorType>} - Returns either true if the data is valid or a Response object with an error message if validation fails.
|
|
24
20
|
*/
|
|
25
21
|
Validator.validateSchema = function (data, schema) {
|
|
26
22
|
var error, validatedInput;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Validator.js","sourceRoot":"","sources":["../../../src/Validation/Validator.ts"],"names":[],"mappings":";;AAAA,2BAAuB;AAEvB,4CAA6D;AAC7D,sCAAgC;AAEhC
|
|
1
|
+
{"version":3,"file":"Validator.js","sourceRoot":"","sources":["../../../src/Validation/Validator.ts"],"names":[],"mappings":";;AAAA,2BAAuB;AAEvB,4CAA6D;AAC7D,sCAAgC;AAEhC;;;;;GAKG;AACH;IAAA;IAgCA,CAAC;IA/BC;;;;;OAKG;IACW,wBAAc,GAA5B,UACE,IAAS,EACT,MAA0C;QAE1C,IAAI,KAAK,EAAE,cAAc,CAAA;QAEzB,yCAAyC;QACzC,IAAI;YACF,cAAc,GAAG,MAAM,CAAC,KAAK,CAAC,IAAI,CAAkB,CAAA;SACrD;QAAC,OAAO,GAAqB,EAAE;YAC9B,IAAI,GAAG,YAAY,OAAC,CAAC,QAAQ;gBAAE,KAAK,GAAG,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,OAAO,CAAC,CAAA;;gBACzD,KAAK,GAAG,2BAA2B,CAAA,CAAC,8BAA8B;SACxE;QAED,mBAAmB;QACnB,IAAI,CAAC,cAAc,IAAI,KAAK,EAAE;YAC5B,OAAO,kBAAQ,CAAC,kBAAkB,CAChC,iBAAO,CAAC,2BAA2B,EACnC,iBAAO,CAAC,sBAAsB,EAC9B,EAAE,iBAAiB,EAAE,KAAK,EAAE,CAC7B,CAAA;SACF;aAAM;YACL,OAAO,IAAI,CAAA;SACZ;IACH,CAAC;IACH,gBAAC;AAAD,CAAC,AAhCD,IAgCC"}
|
package/index.ts
CHANGED
|
@@ -9,6 +9,21 @@ import JWT from './src/Crypto/JWT'
|
|
|
9
9
|
import Mailer from './src/Mailer/Mailer'
|
|
10
10
|
import Router, { Route } from './src/Server/Router'
|
|
11
11
|
|
|
12
|
+
/**
|
|
13
|
+
* Exported modules:
|
|
14
|
+
* - Transaction: A module for handling transactions.
|
|
15
|
+
* - Process: A module for managing processes.
|
|
16
|
+
* - EventProcessor: A module for processing events.
|
|
17
|
+
* - Router: A module for routing requests.
|
|
18
|
+
* - Mailer: A module for sending emails.
|
|
19
|
+
* - Crypto: A module for cryptographic operations.
|
|
20
|
+
* - JWT: A module for handling JSON Web Tokens.
|
|
21
|
+
* - Configuration: A module for managing configuration settings.
|
|
22
|
+
* - Response: A module for constructing HTTP responses.
|
|
23
|
+
* - Utils: A module containing utility functions.
|
|
24
|
+
* - Route: A module for defining routes.
|
|
25
|
+
* - ResponseErrorType: An enumeration of possible response error types.
|
|
26
|
+
*/
|
|
12
27
|
export {
|
|
13
28
|
// Base Events
|
|
14
29
|
Transaction,
|
package/jest.config.ts
CHANGED
|
@@ -19,7 +19,7 @@ const config: Config.InitialOptions = {
|
|
|
19
19
|
],
|
|
20
20
|
],
|
|
21
21
|
coverageReporters: ['clover', 'json', 'lcov', ['text', { file: 'coverage.txt' }], 'json-summary'],
|
|
22
|
-
collectCoverageFrom: ['src/**/*.(t|j)s'],
|
|
22
|
+
collectCoverageFrom: ['src/**/*.(t|j)s', '!src/**/*.d.(t|j)s'],
|
|
23
23
|
coverageThreshold: {
|
|
24
24
|
global: {
|
|
25
25
|
branches: 80,
|
package/package.json
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@creator.co/wapi",
|
|
3
|
-
"version": "1.2.
|
|
3
|
+
"version": "1.2.6",
|
|
4
4
|
"description": "",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"types": "dist/index.d.ts",
|
|
7
7
|
"type": "commonjs",
|
|
8
8
|
"scripts": {
|
|
9
|
-
"build": "
|
|
9
|
+
"build": "tsc --build",
|
|
10
10
|
"clean": "tsc --build --clean",
|
|
11
11
|
"lint-fix": "eslint . --ext .ts --fix",
|
|
12
12
|
"lint": "eslint . --ext .ts",
|
|
@@ -24,6 +24,7 @@
|
|
|
24
24
|
"@aws-sdk/credential-provider-node": "^3.414.0",
|
|
25
25
|
"@types/email-templates": "^10.0.1",
|
|
26
26
|
"@types/nodemailer": "^6.4.10",
|
|
27
|
+
"@types/object-hash": "^3.0.4",
|
|
27
28
|
"abind": "^1.0.5",
|
|
28
29
|
"cors": "^2.8.5",
|
|
29
30
|
"cuid": "^3.0.0",
|
|
@@ -32,18 +33,28 @@
|
|
|
32
33
|
"express": "^4.18.2",
|
|
33
34
|
"json-stringify-safe": "^5.0.1",
|
|
34
35
|
"jsonwebtoken": "^9.0.2",
|
|
36
|
+
"knex": "^3.0.1",
|
|
35
37
|
"node-cache": "^5.1.2",
|
|
38
|
+
"object-hash": "^3.0.0",
|
|
36
39
|
"parse-duration": "^1.1.0",
|
|
40
|
+
"path-to-regexp": "^6.2.1",
|
|
41
|
+
"pg": "^8.11.3",
|
|
37
42
|
"sha1": "^1.1.1",
|
|
38
43
|
"stack-trace": "0.0.10",
|
|
39
44
|
"zod": "^3.22.4"
|
|
40
45
|
},
|
|
41
46
|
"devDependencies": {
|
|
47
|
+
"@jest/globals": "^29.7.0",
|
|
42
48
|
"@types/aws-lambda": "^8.10.119",
|
|
49
|
+
"@types/chai": "^4.3.9",
|
|
50
|
+
"@types/cors": "^2.8.15",
|
|
43
51
|
"@types/express": "^4.17.19",
|
|
44
52
|
"@types/jest": "^29.5.6",
|
|
45
53
|
"@types/jsonwebtoken": "^9.0.3",
|
|
46
54
|
"@types/node": "^20.5.7",
|
|
55
|
+
"@types/path-to-regexp": "^1.7.0",
|
|
56
|
+
"@types/pg": "^8.10.5",
|
|
57
|
+
"@types/supertest": "^2.0.15",
|
|
47
58
|
"@typescript-eslint/eslint-plugin": "^6.5.0",
|
|
48
59
|
"@typescript-eslint/parser": "^6.5.0",
|
|
49
60
|
"aws-lambda": "^1.0.7",
|
package/src/API/Request.ts
CHANGED
|
@@ -2,36 +2,28 @@ import type { Context, APIGatewayEvent } from 'aws-lambda'
|
|
|
2
2
|
|
|
3
3
|
import Utils from './Utils'
|
|
4
4
|
import Logger from '../Logger/Logger'
|
|
5
|
+
|
|
5
6
|
/**
|
|
6
|
-
*
|
|
7
|
-
*
|
|
8
|
-
* @export
|
|
9
|
-
* @class Request
|
|
10
|
-
* @typedef {Request}
|
|
11
|
-
* @template InputType
|
|
7
|
+
* Represents a request object with utility methods for accessing request information.
|
|
8
|
+
* @template InputType - The type of the request body.
|
|
12
9
|
*/
|
|
13
10
|
export default class Request<InputType> {
|
|
14
11
|
/**
|
|
15
|
-
*
|
|
16
|
-
*
|
|
17
|
-
* @private
|
|
12
|
+
* Represents an API Gateway event for a request.
|
|
18
13
|
* @type {APIGatewayEvent}
|
|
19
14
|
*/
|
|
20
15
|
private requestEvent: APIGatewayEvent
|
|
21
16
|
/**
|
|
22
|
-
*
|
|
23
|
-
*
|
|
24
|
-
* @private
|
|
25
|
-
* @type {Context}
|
|
17
|
+
* The context object for the current instance.
|
|
26
18
|
*/
|
|
27
19
|
private context: Context
|
|
20
|
+
|
|
28
21
|
/**
|
|
29
|
-
*
|
|
30
|
-
*
|
|
31
|
-
* @
|
|
32
|
-
* @param {
|
|
33
|
-
* @
|
|
34
|
-
* @param {Logger} logger
|
|
22
|
+
* Constructs a new instance of the class.
|
|
23
|
+
* @param {APIGatewayEvent} requestEvent - The API Gateway event object.
|
|
24
|
+
* @param {Context} context - The context object.
|
|
25
|
+
* @param {Logger} logger - The logger object.
|
|
26
|
+
* @returns None
|
|
35
27
|
*/
|
|
36
28
|
constructor(requestEvent: APIGatewayEvent, context: Context, logger: Logger) {
|
|
37
29
|
this.requestEvent = requestEvent
|
|
@@ -39,74 +31,66 @@ export default class Request<InputType> {
|
|
|
39
31
|
logger.debug('Request info:', JSON.stringify(requestEvent))
|
|
40
32
|
logger.debug('Request context:', JSON.stringify(context))
|
|
41
33
|
}
|
|
34
|
+
|
|
42
35
|
/**
|
|
43
|
-
*
|
|
44
|
-
*
|
|
45
|
-
* @
|
|
46
|
-
* @param {string} paramName
|
|
47
|
-
* @returns {boolean}
|
|
36
|
+
* Checks if the given query parameter exists and has a valid value.
|
|
37
|
+
* @param {string} paramName - The name of the query parameter to check.
|
|
38
|
+
* @returns {boolean} - True if the query parameter exists and has a valid value, false otherwise.
|
|
48
39
|
*/
|
|
49
40
|
public containsQueryParam(paramName: string): boolean {
|
|
50
41
|
const val = this.getQueryParam(paramName)
|
|
51
42
|
return !!val && (Utils.isValidString(val) || Utils.isValidNumber(val))
|
|
52
43
|
}
|
|
44
|
+
|
|
53
45
|
/**
|
|
54
|
-
*
|
|
55
|
-
*
|
|
56
|
-
* @
|
|
57
|
-
* @param {string} paramName
|
|
58
|
-
* @returns {(string | null)}
|
|
46
|
+
* Retrieves the value of a query parameter from the request event's query string parameters.
|
|
47
|
+
* @param {string} paramName - The name of the query parameter to retrieve.
|
|
48
|
+
* @returns {string | null} The value of the query parameter, or null if it does not exist.
|
|
59
49
|
*/
|
|
60
50
|
public getQueryParam(paramName: string): string | null {
|
|
61
51
|
return Utils.caseInsensitiveObjectForKey(this.requestEvent.queryStringParameters, paramName)
|
|
62
52
|
}
|
|
53
|
+
|
|
63
54
|
/**
|
|
64
|
-
*
|
|
65
|
-
*
|
|
66
|
-
* @
|
|
67
|
-
* @param {string} headerName
|
|
68
|
-
* @returns {(string | null)}
|
|
55
|
+
* Retrieves the value of the specified header from the request event headers.
|
|
56
|
+
* @param {string} headerName - The name of the header to retrieve.
|
|
57
|
+
* @returns {string | null} - The value of the header, or null if the header is not found.
|
|
69
58
|
*/
|
|
70
59
|
public getHeader(headerName: string): string | null {
|
|
71
60
|
return Utils.caseInsensitiveObjectForKey(this.requestEvent.headers, headerName)
|
|
72
61
|
}
|
|
73
|
-
|
|
62
|
+
|
|
74
63
|
/**
|
|
75
|
-
*
|
|
76
|
-
*
|
|
77
|
-
* @
|
|
78
|
-
* @param {string} cxtParam
|
|
79
|
-
* @returns {(any | null)}
|
|
64
|
+
* Retrieves the value of a context parameter from the request context object.
|
|
65
|
+
* @param {string} cxtParam - The name of the context parameter to retrieve.
|
|
66
|
+
* @returns The value of the context parameter, or null if it does not exist.
|
|
80
67
|
*/
|
|
81
68
|
public getContextParam(cxtParam: string): any | null {
|
|
82
69
|
return Utils.caseInsensitiveObjectForKey(this.requestEvent.requestContext, cxtParam)
|
|
83
70
|
}
|
|
71
|
+
|
|
84
72
|
/**
|
|
85
|
-
*
|
|
86
|
-
*
|
|
87
|
-
* @
|
|
88
|
-
* @param {string} paramName
|
|
89
|
-
* @returns {boolean}
|
|
73
|
+
* Checks if the given parameter name exists in the path parameters and if its value is a valid string or number.
|
|
74
|
+
* @param {string} paramName - The name of the parameter to check.
|
|
75
|
+
* @returns {boolean} - True if the parameter exists and its value is a valid string or number, false otherwise.
|
|
90
76
|
*/
|
|
91
77
|
public containsPathParam(paramName: string): boolean {
|
|
92
78
|
const val = this.getPathParam(paramName)
|
|
93
79
|
return !!val && (Utils.isValidString(val) || Utils.isValidNumber(val))
|
|
94
80
|
}
|
|
81
|
+
|
|
95
82
|
/**
|
|
96
|
-
*
|
|
97
|
-
*
|
|
98
|
-
* @
|
|
99
|
-
* @param {string} paramName
|
|
100
|
-
* @returns {(string | null)}
|
|
83
|
+
* Retrieves the value of a path parameter from the request event.
|
|
84
|
+
* @param {string} paramName - The name of the path parameter to retrieve.
|
|
85
|
+
* @returns {string | null} The value of the path parameter, or null if it does not exist.
|
|
101
86
|
*/
|
|
102
87
|
public getPathParam(paramName: string): string | null {
|
|
103
88
|
return Utils.caseInsensitiveObjectForKey(this.requestEvent.pathParameters, paramName)
|
|
104
89
|
}
|
|
90
|
+
|
|
105
91
|
/**
|
|
106
|
-
*
|
|
107
|
-
*
|
|
108
|
-
* @public
|
|
109
|
-
* @returns {InputType}
|
|
92
|
+
* Retrieves the body of the request event and parses it if it is a string.
|
|
93
|
+
* @returns {InputType} The parsed body of the request event.
|
|
110
94
|
*/
|
|
111
95
|
public getBody(): InputType {
|
|
112
96
|
let b: any = null
|
|
@@ -118,72 +102,70 @@ export default class Request<InputType> {
|
|
|
118
102
|
}
|
|
119
103
|
return b
|
|
120
104
|
}
|
|
105
|
+
|
|
121
106
|
/**
|
|
122
|
-
*
|
|
123
|
-
*
|
|
124
|
-
* @public
|
|
125
|
-
* @returns {string}
|
|
107
|
+
* Retrieves the path from the request event.
|
|
108
|
+
* @returns {string} The path of the request event.
|
|
126
109
|
*/
|
|
127
110
|
public getPath(): string {
|
|
128
111
|
return this.requestEvent.path
|
|
129
112
|
}
|
|
113
|
+
|
|
130
114
|
/**
|
|
131
|
-
*
|
|
132
|
-
*
|
|
133
|
-
* @public
|
|
134
|
-
* @returns {string}
|
|
115
|
+
* Retrieves the HTTP method of the current request.
|
|
116
|
+
* @returns {string} The HTTP method of the request.
|
|
135
117
|
*/
|
|
136
118
|
public getMethod(): string {
|
|
137
119
|
return this.requestEvent.httpMethod
|
|
138
120
|
}
|
|
121
|
+
|
|
139
122
|
/**
|
|
140
|
-
*
|
|
141
|
-
*
|
|
142
|
-
* @public
|
|
143
|
-
* @returns {(object | null)}
|
|
123
|
+
* Retrieves the path parameters from the request event.
|
|
124
|
+
* @returns {object | null} - The path parameters object, or null if not found.
|
|
144
125
|
*/
|
|
145
126
|
public getPathParams(): object | null {
|
|
146
127
|
return this.requestEvent.pathParameters
|
|
147
128
|
}
|
|
129
|
+
|
|
148
130
|
/**
|
|
149
|
-
*
|
|
150
|
-
*
|
|
151
|
-
* @public
|
|
152
|
-
* @returns {(string | null)}
|
|
131
|
+
* Retrieves the value of the 'Authorization' header from the request.
|
|
132
|
+
* @returns The value of the 'Authorization' header, or null if it is not present.
|
|
153
133
|
*/
|
|
154
134
|
public getAuthorizationHeader(): string | null {
|
|
155
135
|
return this.getHeader('Authorization')
|
|
156
136
|
}
|
|
137
|
+
|
|
157
138
|
/**
|
|
158
|
-
*
|
|
159
|
-
*
|
|
160
|
-
* @public
|
|
161
|
-
* @returns {string}
|
|
139
|
+
* Retrieves the request ID associated with the current execution context.
|
|
140
|
+
* @returns {string} The request ID.
|
|
162
141
|
*/
|
|
163
142
|
public getRequestID(): string {
|
|
164
143
|
if (this.context.awsRequestId) return this.context.awsRequestId
|
|
165
144
|
return this.requestEvent.requestContext ? this.requestEvent.requestContext.requestId : 'unknown'
|
|
166
145
|
}
|
|
146
|
+
|
|
167
147
|
/**
|
|
168
|
-
*
|
|
169
|
-
*
|
|
170
|
-
* @public
|
|
171
|
-
* @returns {string}
|
|
148
|
+
* Retrieves the origin IP address of the request.
|
|
149
|
+
* @returns {string} The origin IP address. If the IP address is not available, it returns 'unknown'.
|
|
172
150
|
*/
|
|
173
151
|
public getOriginIP(): string {
|
|
174
152
|
const origin = this.getContextParam('identity')?.sourceIp
|
|
175
153
|
const hOrigin = this.getHeader('X-Forwarded-For')
|
|
176
154
|
return origin ? origin : hOrigin ? hOrigin : 'unknown'
|
|
177
155
|
}
|
|
156
|
+
|
|
178
157
|
/**
|
|
179
|
-
*
|
|
180
|
-
*
|
|
181
|
-
* @
|
|
182
|
-
* @
|
|
183
|
-
* @param {any[]} result
|
|
158
|
+
* Sets the fixed path parameters in the request event object.
|
|
159
|
+
* @param {any[]} keys - An array of keys representing the path parameter names.
|
|
160
|
+
* @param {any[]} result - An array of values representing the path parameter values.
|
|
161
|
+
* @returns None
|
|
184
162
|
*/
|
|
185
163
|
public setFixedPathParams(keys: any[], result: any[]): void {
|
|
186
164
|
this.requestEvent.pathParameters = {}
|
|
187
|
-
keys.forEach((key, index) =>
|
|
165
|
+
keys.forEach((key, index) => {
|
|
166
|
+
if (this.requestEvent?.pathParameters) {
|
|
167
|
+
this.requestEvent.pathParameters[key.name] = result[index + 1]
|
|
168
|
+
}
|
|
169
|
+
})
|
|
188
170
|
}
|
|
189
171
|
}
|