@creator.co/wapi 1.2.1-beta6 → 1.2.3
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/.eslintrc.cjs +29 -22
- package/.github/workflows/npmpublish.yml +11 -19
- package/.github/workflows/prs.yml +13 -0
- package/index.ts +12 -10
- package/jest.config.ts +39 -0
- package/package.json +15 -4
- package/src/API/Request.ts +136 -44
- package/src/API/Response.ts +256 -46
- package/src/API/Utils.ts +60 -7
- package/src/BaseEvent/EventProcessor.ts +93 -28
- package/src/BaseEvent/Process.ts +69 -13
- package/src/BaseEvent/Transaction.ts +29 -50
- package/src/Config/Configuration.ts +119 -19
- package/src/Config/EnvironmentVar.ts +100 -21
- package/src/Crypto/Crypto.ts +78 -19
- package/src/Crypto/JWT.ts +53 -13
- package/src/Globals.ts +159 -27
- package/src/Logger/Logger.ts +204 -65
- package/src/Mailer/Mailer.ts +114 -31
- package/src/Publisher/Publisher.ts +57 -16
- package/src/Server/RouteResolver.ts +141 -0
- package/src/Server/Router.ts +84 -12
- package/src/Server/lib/ContainerServer.ts +53 -6
- package/src/Server/lib/Server.ts +82 -54
- package/src/Server/lib/container/GenericHandler.ts +15 -18
- package/src/Server/lib/container/GenericHandlerEvent.ts +78 -50
- package/src/Server/lib/container/HealthHandler.ts +2 -2
- package/src/Server/lib/container/Proxy.ts +114 -45
- package/src/Server/lib/container/Utils.ts +18 -27
- package/src/Validation/Validator.ts +23 -7
- package/tests/API/Request.test.ts +259 -0
- package/tests/API/Response.test.ts +367 -0
- package/tests/API/Utils.test.ts +157 -0
- package/tests/BaseEvent/EventProcessor.test.ts +262 -0
- package/tests/BaseEvent/Process.test.ts +49 -0
- package/tests/BaseEvent/Transaction.test.ts +222 -0
- package/tests/Config/Config.test.ts +193 -0
- package/tests/Config/EnvironmentVar.test.ts +214 -0
- package/tests/Crypto/Crypto.test.ts +88 -0
- package/tests/Crypto/JWT.test.ts +92 -0
- package/tests/Logger/Logger.test.ts +96 -0
- package/tests/Mailer/Mailer.test.ts +59 -0
- package/tests/Publisher/Publisher.test.ts +60 -0
- package/tests/Server/RouteResolver.test.ts +103 -0
- package/tests/Server/Router.test.ts +38 -0
- package/tests/Server/lib/ContainerServer.test.ts +327 -0
- package/tests/Server/lib/Server.test.ts +12 -0
- package/tests/Server/lib/container/GenericHandler.test.ts +131 -0
- package/tests/Server/lib/container/GenericHandlerEvent.test.ts +102 -0
- package/tests/Server/lib/container/HealthHandler.test.ts +30 -0
- package/tests/Server/lib/container/Proxy.test.ts +265 -0
- package/tests/Server/lib/container/Utils.test.ts +47 -0
- package/tests/Test.utils.ts +95 -0
- package/tests/Validation/Validator.test.ts +76 -0
- package/tests/main.test.ts +15 -0
- package/tsconfig.json +1 -0
- package/dist/index.d.ts +0 -11
- package/dist/index.js +0 -24
- package/dist/index.js.map +0 -1
- package/dist/package.json +0 -53
- package/dist/src/API/Request.d.ts +0 -21
- package/dist/src/API/Request.js +0 -86
- package/dist/src/API/Request.js.map +0 -1
- package/dist/src/API/Response.d.ts +0 -39
- package/dist/src/API/Response.js +0 -232
- package/dist/src/API/Response.js.map +0 -1
- package/dist/src/API/Utils.d.ts +0 -8
- package/dist/src/API/Utils.js +0 -49
- package/dist/src/API/Utils.js.map +0 -1
- package/dist/src/BaseEvent/EventProcessor.d.ts +0 -13
- package/dist/src/BaseEvent/EventProcessor.js +0 -151
- package/dist/src/BaseEvent/EventProcessor.js.map +0 -1
- package/dist/src/BaseEvent/Process.d.ts +0 -12
- package/dist/src/BaseEvent/Process.js +0 -114
- package/dist/src/BaseEvent/Process.js.map +0 -1
- package/dist/src/BaseEvent/Transaction.d.ts +0 -29
- package/dist/src/BaseEvent/Transaction.js +0 -248
- package/dist/src/BaseEvent/Transaction.js.map +0 -1
- package/dist/src/Config/Configuration.d.ts +0 -34
- package/dist/src/Config/Configuration.js +0 -93
- package/dist/src/Config/Configuration.js.map +0 -1
- package/dist/src/Config/EnvironmentVar.d.ts +0 -17
- package/dist/src/Config/EnvironmentVar.js +0 -152
- package/dist/src/Config/EnvironmentVar.js.map +0 -1
- package/dist/src/Crypto/Crypto.d.ts +0 -8
- package/dist/src/Crypto/Crypto.js +0 -84
- package/dist/src/Crypto/Crypto.js.map +0 -1
- package/dist/src/Crypto/JWT.d.ts +0 -16
- package/dist/src/Crypto/JWT.js +0 -49
- package/dist/src/Crypto/JWT.js.map +0 -1
- package/dist/src/Globals.d.ts +0 -21
- package/dist/src/Globals.js +0 -35
- package/dist/src/Globals.js.map +0 -1
- package/dist/src/Logger/Logger.d.ts +0 -34
- package/dist/src/Logger/Logger.js +0 -345
- package/dist/src/Logger/Logger.js.map +0 -1
- package/dist/src/Mailer/Mailer.d.ts +0 -12
- package/dist/src/Mailer/Mailer.js +0 -234
- package/dist/src/Mailer/Mailer.js.map +0 -1
- package/dist/src/Publisher/Publisher.d.ts +0 -10
- package/dist/src/Publisher/Publisher.js +0 -109
- package/dist/src/Publisher/Publisher.js.map +0 -1
- package/dist/src/Server/Router.d.ts +0 -27
- package/dist/src/Server/Router.js +0 -22
- package/dist/src/Server/Router.js.map +0 -1
- package/dist/src/Server/lib/ContainerServer.d.ts +0 -11
- package/dist/src/Server/lib/ContainerServer.js +0 -103
- package/dist/src/Server/lib/ContainerServer.js.map +0 -1
- package/dist/src/Server/lib/Server.d.ts +0 -9
- package/dist/src/Server/lib/Server.js +0 -141
- package/dist/src/Server/lib/Server.js.map +0 -1
- package/dist/src/Server/lib/container/GenericHandler.d.ts +0 -4
- package/dist/src/Server/lib/container/GenericHandler.js +0 -136
- package/dist/src/Server/lib/container/GenericHandler.js.map +0 -1
- package/dist/src/Server/lib/container/GenericHandlerEvent.d.ts +0 -14
- package/dist/src/Server/lib/container/GenericHandlerEvent.js +0 -164
- package/dist/src/Server/lib/container/GenericHandlerEvent.js.map +0 -1
- package/dist/src/Server/lib/container/HealthHandler.d.ts +0 -3
- package/dist/src/Server/lib/container/HealthHandler.js +0 -44
- package/dist/src/Server/lib/container/HealthHandler.js.map +0 -1
- package/dist/src/Server/lib/container/Proxy.d.ts +0 -15
- package/dist/src/Server/lib/container/Proxy.js +0 -157
- package/dist/src/Server/lib/container/Proxy.js.map +0 -1
- package/dist/src/Server/lib/container/Utils.d.ts +0 -6
- package/dist/src/Server/lib/container/Utils.js +0 -109
- package/dist/src/Server/lib/container/Utils.js.map +0 -1
- package/dist/src/Validation/Validator.d.ts +0 -5
- package/dist/src/Validation/Validator.js +0 -31
- package/dist/src/Validation/Validator.js.map +0 -1
package/.eslintrc.cjs
CHANGED
|
@@ -1,42 +1,49 @@
|
|
|
1
1
|
/* eslint-env node */
|
|
2
2
|
module.exports = {
|
|
3
3
|
extends: [
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
4
|
+
'eslint:recommended',
|
|
5
|
+
'plugin:@typescript-eslint/recommended',
|
|
6
|
+
'plugin:prettier/recommended',
|
|
7
|
+
'plugin:import/recommended',
|
|
8
|
+
'plugin:import/typescript',
|
|
9
9
|
],
|
|
10
|
-
parser:
|
|
11
|
-
plugins: [
|
|
10
|
+
parser: '@typescript-eslint/parser',
|
|
11
|
+
plugins: ['@typescript-eslint', 'prettier'],
|
|
12
12
|
root: true,
|
|
13
13
|
rules: {
|
|
14
|
-
|
|
15
|
-
|
|
14
|
+
'prettier/prettier': [
|
|
15
|
+
'error',
|
|
16
16
|
{
|
|
17
17
|
semi: false,
|
|
18
|
+
printWidth: 100,
|
|
19
|
+
tabWidth: 2,
|
|
20
|
+
useTabs: false,
|
|
21
|
+
bracketSameLine: true,
|
|
22
|
+
arrowParens: 'avoid',
|
|
23
|
+
singleQuote: true,
|
|
24
|
+
trailingComma: 'es5',
|
|
18
25
|
},
|
|
19
26
|
],
|
|
20
|
-
|
|
21
|
-
|
|
27
|
+
'@typescript-eslint/ban-ts-comment': 0,
|
|
28
|
+
'@typescript-eslint/no-explicit-any': 0,
|
|
22
29
|
// turn on errors for missing imports
|
|
23
|
-
|
|
30
|
+
'import/no-unresolved': 'error',
|
|
24
31
|
// 'import/no-named-as-default-member': 'off',
|
|
25
|
-
|
|
26
|
-
|
|
32
|
+
'import/order': [
|
|
33
|
+
'error',
|
|
27
34
|
{
|
|
28
35
|
groups: [
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
[
|
|
33
|
-
|
|
34
|
-
|
|
36
|
+
'builtin', // Built-in imports (come from NodeJS native) go first
|
|
37
|
+
'external', // <- External imports
|
|
38
|
+
'internal', // <- Absolute imports
|
|
39
|
+
['sibling', 'parent'], // <- Relative imports, the sibling and parent types they can be mingled together
|
|
40
|
+
'index', // <- index imports
|
|
41
|
+
'unknown', // <- unknown
|
|
35
42
|
],
|
|
36
|
-
|
|
43
|
+
'newlines-between': 'always',
|
|
37
44
|
alphabetize: {
|
|
38
45
|
/* sort in ascending order. Options: ["ignore", "asc", "desc"] */
|
|
39
|
-
order:
|
|
46
|
+
order: 'asc',
|
|
40
47
|
/* ignore case. Options: [true, false] */
|
|
41
48
|
caseInsensitive: true,
|
|
42
49
|
},
|
|
@@ -1,22 +1,14 @@
|
|
|
1
|
-
|
|
2
|
-
# For more information see: https://help.github.com/actions/language-and-framework-guides/publishing-nodejs-packages
|
|
3
|
-
|
|
4
|
-
name: Node.js Package
|
|
5
|
-
|
|
1
|
+
name: NPM Publish
|
|
6
2
|
on:
|
|
7
|
-
|
|
8
|
-
|
|
3
|
+
push:
|
|
4
|
+
branches: [ "main" ]
|
|
9
5
|
|
|
10
6
|
jobs:
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
- run: npm ci
|
|
20
|
-
- run: npm publish --access='public'
|
|
21
|
-
env:
|
|
22
|
-
NODE_AUTH_TOKEN: ${{secrets.npm_token}}
|
|
7
|
+
Publish:
|
|
8
|
+
uses: Creator-co/tool-github-workflows/.github/workflows/npmpublish.yml@main
|
|
9
|
+
secrets: inherit
|
|
10
|
+
with:
|
|
11
|
+
disablieSASTFailure: false
|
|
12
|
+
disableLintFailure: false
|
|
13
|
+
disableUTestFailure: false
|
|
14
|
+
NODE_VERSION: "16.x"
|
package/index.ts
CHANGED
|
@@ -1,13 +1,13 @@
|
|
|
1
|
-
import Response from
|
|
2
|
-
import Utils from
|
|
3
|
-
import EventProcessor from
|
|
4
|
-
import Process from
|
|
5
|
-
import Transaction from
|
|
6
|
-
import Configuration from
|
|
7
|
-
import Crypto from
|
|
8
|
-
import JWT from
|
|
9
|
-
import Mailer from
|
|
10
|
-
import Router, { Route } from
|
|
1
|
+
import Response, { ResponseErrorType } from './src/API/Response'
|
|
2
|
+
import Utils from './src/API/Utils'
|
|
3
|
+
import EventProcessor from './src/BaseEvent/EventProcessor'
|
|
4
|
+
import Process from './src/BaseEvent/Process'
|
|
5
|
+
import Transaction from './src/BaseEvent/Transaction'
|
|
6
|
+
import Configuration from './src/Config/Configuration'
|
|
7
|
+
import Crypto from './src/Crypto/Crypto'
|
|
8
|
+
import JWT from './src/Crypto/JWT'
|
|
9
|
+
import Mailer from './src/Mailer/Mailer'
|
|
10
|
+
import Router, { Route } from './src/Server/Router'
|
|
11
11
|
|
|
12
12
|
export {
|
|
13
13
|
// Base Events
|
|
@@ -25,4 +25,6 @@ export {
|
|
|
25
25
|
// Helpers
|
|
26
26
|
Utils,
|
|
27
27
|
Route,
|
|
28
|
+
// Misc types
|
|
29
|
+
ResponseErrorType,
|
|
28
30
|
}
|
package/jest.config.ts
ADDED
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import type { Config } from '@jest/types'
|
|
2
|
+
/* eslint-env node */
|
|
3
|
+
const config: Config.InitialOptions = {
|
|
4
|
+
preset: 'ts-jest',
|
|
5
|
+
testEnvironment: 'node',
|
|
6
|
+
reporters: [
|
|
7
|
+
'default',
|
|
8
|
+
[
|
|
9
|
+
'jest-junit',
|
|
10
|
+
{
|
|
11
|
+
outputDirectory: 'coverage',
|
|
12
|
+
outputName: 'jest-junit.xml',
|
|
13
|
+
ancestorSeparator: ' › ',
|
|
14
|
+
uniqueOutputName: 'false',
|
|
15
|
+
suiteNameTemplate: '{filepath}',
|
|
16
|
+
classNameTemplate: '{classname}',
|
|
17
|
+
titleTemplate: '{title}',
|
|
18
|
+
},
|
|
19
|
+
],
|
|
20
|
+
],
|
|
21
|
+
coverageReporters: [
|
|
22
|
+
'clover',
|
|
23
|
+
'json',
|
|
24
|
+
'lcov',
|
|
25
|
+
'text',
|
|
26
|
+
['text', { file: 'coverage.txt' }],
|
|
27
|
+
'json-summary',
|
|
28
|
+
],
|
|
29
|
+
collectCoverageFrom: ['src/**/*.(t|j)s'],
|
|
30
|
+
coverageThreshold: {
|
|
31
|
+
global: {
|
|
32
|
+
branches: 80,
|
|
33
|
+
functions: 80,
|
|
34
|
+
lines: 80,
|
|
35
|
+
statements: 80,
|
|
36
|
+
},
|
|
37
|
+
},
|
|
38
|
+
}
|
|
39
|
+
export default config
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@creator.co/wapi",
|
|
3
|
-
"version": "1.2.
|
|
3
|
+
"version": "1.2.3",
|
|
4
4
|
"description": "",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"types": "dist/index.d.ts",
|
|
@@ -8,7 +8,10 @@
|
|
|
8
8
|
"scripts": {
|
|
9
9
|
"build": "npm run lint && tsc --build",
|
|
10
10
|
"clean": "tsc --build --clean",
|
|
11
|
-
"lint": "eslint . --ext .ts --fix"
|
|
11
|
+
"lint-fix": "eslint . --ext .ts --fix",
|
|
12
|
+
"lint": "eslint . --ext .ts",
|
|
13
|
+
"test": "jest --coverage --silent --runInBand",
|
|
14
|
+
"test-dev": "jest --coverage --runInBand"
|
|
12
15
|
},
|
|
13
16
|
"author": "",
|
|
14
17
|
"license": "ISC",
|
|
@@ -33,21 +36,29 @@
|
|
|
33
36
|
"parse-duration": "^1.1.0",
|
|
34
37
|
"sha1": "^1.1.1",
|
|
35
38
|
"stack-trace": "0.0.10",
|
|
36
|
-
"unflatten": "^1.0.4",
|
|
37
39
|
"zod": "^3.22.4"
|
|
38
40
|
},
|
|
39
41
|
"devDependencies": {
|
|
40
42
|
"@types/aws-lambda": "^8.10.119",
|
|
41
43
|
"@types/express": "^4.17.19",
|
|
44
|
+
"@types/jest": "^29.5.6",
|
|
42
45
|
"@types/jsonwebtoken": "^9.0.3",
|
|
43
46
|
"@types/node": "^20.5.7",
|
|
44
47
|
"@typescript-eslint/eslint-plugin": "^6.5.0",
|
|
45
48
|
"@typescript-eslint/parser": "^6.5.0",
|
|
46
49
|
"aws-lambda": "^1.0.7",
|
|
50
|
+
"aws-sdk-client-mock": "^3.0.0",
|
|
51
|
+
"chai": "^4.3.10",
|
|
47
52
|
"eslint": "^8.48.0",
|
|
48
53
|
"eslint-config-prettier": "^9.0.0",
|
|
49
54
|
"eslint-plugin-import": "^2.28.1",
|
|
50
55
|
"eslint-plugin-prettier": "^5.0.0",
|
|
51
|
-
"
|
|
56
|
+
"jest": "^29.7.0",
|
|
57
|
+
"jest-junit": "^16.0.0",
|
|
58
|
+
"prettier": "^3.0.3",
|
|
59
|
+
"supertest": "^6.3.3",
|
|
60
|
+
"ts-jest": "^29.1.1",
|
|
61
|
+
"ts-node": "^10.9.1",
|
|
62
|
+
"typescript": "^5.2.2"
|
|
52
63
|
}
|
|
53
64
|
}
|
package/src/API/Request.ts
CHANGED
|
@@ -1,97 +1,189 @@
|
|
|
1
|
-
import type { Context, APIGatewayEvent } from
|
|
1
|
+
import type { Context, APIGatewayEvent } from 'aws-lambda'
|
|
2
2
|
|
|
3
|
-
import Utils from
|
|
4
|
-
import Logger from
|
|
5
|
-
|
|
3
|
+
import Utils from './Utils'
|
|
4
|
+
import Logger from '../Logger/Logger'
|
|
5
|
+
/**
|
|
6
|
+
* ${1:Description placeholder}
|
|
7
|
+
*
|
|
8
|
+
* @export
|
|
9
|
+
* @class Request
|
|
10
|
+
* @typedef {Request}
|
|
11
|
+
* @template InputType
|
|
12
|
+
*/
|
|
6
13
|
export default class Request<InputType> {
|
|
14
|
+
/**
|
|
15
|
+
* ${1:Description placeholder}
|
|
16
|
+
*
|
|
17
|
+
* @private
|
|
18
|
+
* @type {APIGatewayEvent}
|
|
19
|
+
*/
|
|
7
20
|
private requestEvent: APIGatewayEvent
|
|
21
|
+
/**
|
|
22
|
+
* ${1:Description placeholder}
|
|
23
|
+
*
|
|
24
|
+
* @private
|
|
25
|
+
* @type {Context}
|
|
26
|
+
*/
|
|
8
27
|
private context: Context
|
|
28
|
+
/**
|
|
29
|
+
* Creates an instance of Request.
|
|
30
|
+
*
|
|
31
|
+
* @constructor
|
|
32
|
+
* @param {APIGatewayEvent} requestEvent
|
|
33
|
+
* @param {Context} context
|
|
34
|
+
* @param {Logger} logger
|
|
35
|
+
*/
|
|
9
36
|
constructor(requestEvent: APIGatewayEvent, context: Context, logger: Logger) {
|
|
10
37
|
this.requestEvent = requestEvent
|
|
11
38
|
this.context = context
|
|
12
|
-
logger.debug(
|
|
13
|
-
logger.debug(
|
|
39
|
+
logger.debug('Request info:', JSON.stringify(requestEvent))
|
|
40
|
+
logger.debug('Request context:', JSON.stringify(context))
|
|
14
41
|
}
|
|
15
|
-
|
|
42
|
+
/**
|
|
43
|
+
* ${1:Description placeholder}
|
|
44
|
+
*
|
|
45
|
+
* @public
|
|
46
|
+
* @param {string} paramName
|
|
47
|
+
* @returns {boolean}
|
|
48
|
+
*/
|
|
16
49
|
public containsQueryParam(paramName: string): boolean {
|
|
17
50
|
const val = this.getQueryParam(paramName)
|
|
18
51
|
return !!val && (Utils.isValidString(val) || Utils.isValidNumber(val))
|
|
19
52
|
}
|
|
53
|
+
/**
|
|
54
|
+
* ${1:Description placeholder}
|
|
55
|
+
*
|
|
56
|
+
* @public
|
|
57
|
+
* @param {string} paramName
|
|
58
|
+
* @returns {(string | null)}
|
|
59
|
+
*/
|
|
20
60
|
public getQueryParam(paramName: string): string | null {
|
|
21
|
-
return Utils.caseInsensitiveObjectForKey(
|
|
22
|
-
this.requestEvent.queryStringParameters,
|
|
23
|
-
paramName,
|
|
24
|
-
)
|
|
61
|
+
return Utils.caseInsensitiveObjectForKey(this.requestEvent.queryStringParameters, paramName)
|
|
25
62
|
}
|
|
26
|
-
|
|
63
|
+
/**
|
|
64
|
+
* ${1:Description placeholder}
|
|
65
|
+
*
|
|
66
|
+
* @public
|
|
67
|
+
* @param {string} headerName
|
|
68
|
+
* @returns {(string | null)}
|
|
69
|
+
*/
|
|
27
70
|
public getHeader(headerName: string): string | null {
|
|
28
|
-
return Utils.caseInsensitiveObjectForKey(
|
|
29
|
-
this.requestEvent.headers,
|
|
30
|
-
headerName,
|
|
31
|
-
)
|
|
71
|
+
return Utils.caseInsensitiveObjectForKey(this.requestEvent.headers, headerName)
|
|
32
72
|
}
|
|
33
73
|
//context params
|
|
74
|
+
/**
|
|
75
|
+
* ${1:Description placeholder}
|
|
76
|
+
*
|
|
77
|
+
* @public
|
|
78
|
+
* @param {string} cxtParam
|
|
79
|
+
* @returns {(any | null)}
|
|
80
|
+
*/
|
|
34
81
|
public getContextParam(cxtParam: string): any | null {
|
|
35
|
-
return Utils.caseInsensitiveObjectForKey(
|
|
36
|
-
this.requestEvent.requestContext,
|
|
37
|
-
cxtParam,
|
|
38
|
-
)
|
|
82
|
+
return Utils.caseInsensitiveObjectForKey(this.requestEvent.requestContext, cxtParam)
|
|
39
83
|
}
|
|
40
|
-
|
|
84
|
+
/**
|
|
85
|
+
* ${1:Description placeholder}
|
|
86
|
+
*
|
|
87
|
+
* @public
|
|
88
|
+
* @param {string} paramName
|
|
89
|
+
* @returns {boolean}
|
|
90
|
+
*/
|
|
41
91
|
public containsPathParam(paramName: string): boolean {
|
|
42
92
|
const val = this.getPathParam(paramName)
|
|
43
93
|
return !!val && (Utils.isValidString(val) || Utils.isValidNumber(val))
|
|
44
94
|
}
|
|
95
|
+
/**
|
|
96
|
+
* ${1:Description placeholder}
|
|
97
|
+
*
|
|
98
|
+
* @public
|
|
99
|
+
* @param {string} paramName
|
|
100
|
+
* @returns {(string | null)}
|
|
101
|
+
*/
|
|
45
102
|
public getPathParam(paramName: string): string | null {
|
|
46
|
-
return Utils.caseInsensitiveObjectForKey(
|
|
47
|
-
this.requestEvent.pathParameters,
|
|
48
|
-
paramName,
|
|
49
|
-
)
|
|
103
|
+
return Utils.caseInsensitiveObjectForKey(this.requestEvent.pathParameters, paramName)
|
|
50
104
|
}
|
|
51
|
-
|
|
105
|
+
/**
|
|
106
|
+
* ${1:Description placeholder}
|
|
107
|
+
*
|
|
108
|
+
* @public
|
|
109
|
+
* @returns {InputType}
|
|
110
|
+
*/
|
|
52
111
|
public getBody(): InputType {
|
|
53
112
|
let b: any = null
|
|
54
113
|
try {
|
|
55
114
|
b = this.requestEvent.body
|
|
56
|
-
if (typeof b ===
|
|
57
|
-
b = JSON.parse(b as string)
|
|
115
|
+
if (typeof b === 'string' || b instanceof String) b = JSON.parse(b as string)
|
|
58
116
|
} catch (e) {
|
|
59
|
-
console.error(
|
|
117
|
+
console.error('Error while getting request body!', e)
|
|
60
118
|
}
|
|
61
119
|
return b
|
|
62
120
|
}
|
|
121
|
+
/**
|
|
122
|
+
* ${1:Description placeholder}
|
|
123
|
+
*
|
|
124
|
+
* @public
|
|
125
|
+
* @returns {string}
|
|
126
|
+
*/
|
|
63
127
|
public getPath(): string {
|
|
64
128
|
return this.requestEvent.path
|
|
65
129
|
}
|
|
130
|
+
/**
|
|
131
|
+
* ${1:Description placeholder}
|
|
132
|
+
*
|
|
133
|
+
* @public
|
|
134
|
+
* @returns {string}
|
|
135
|
+
*/
|
|
66
136
|
public getMethod(): string {
|
|
67
137
|
return this.requestEvent.httpMethod
|
|
68
138
|
}
|
|
139
|
+
/**
|
|
140
|
+
* ${1:Description placeholder}
|
|
141
|
+
*
|
|
142
|
+
* @public
|
|
143
|
+
* @returns {(object | null)}
|
|
144
|
+
*/
|
|
69
145
|
public getPathParams(): object | null {
|
|
70
146
|
return this.requestEvent.pathParameters
|
|
71
147
|
}
|
|
72
|
-
|
|
73
|
-
|
|
148
|
+
/**
|
|
149
|
+
* ${1:Description placeholder}
|
|
150
|
+
*
|
|
151
|
+
* @public
|
|
152
|
+
* @returns {(string | null)}
|
|
153
|
+
*/
|
|
74
154
|
public getAuthorizationHeader(): string | null {
|
|
75
|
-
return this.getHeader(
|
|
155
|
+
return this.getHeader('Authorization')
|
|
76
156
|
}
|
|
157
|
+
/**
|
|
158
|
+
* ${1:Description placeholder}
|
|
159
|
+
*
|
|
160
|
+
* @public
|
|
161
|
+
* @returns {string}
|
|
162
|
+
*/
|
|
77
163
|
public getRequestID(): string {
|
|
78
164
|
if (this.context.awsRequestId) return this.context.awsRequestId
|
|
79
|
-
return this.requestEvent.requestContext
|
|
80
|
-
? this.requestEvent.requestContext.requestId
|
|
81
|
-
: "unknown"
|
|
165
|
+
return this.requestEvent.requestContext ? this.requestEvent.requestContext.requestId : 'unknown'
|
|
82
166
|
}
|
|
167
|
+
/**
|
|
168
|
+
* ${1:Description placeholder}
|
|
169
|
+
*
|
|
170
|
+
* @public
|
|
171
|
+
* @returns {string}
|
|
172
|
+
*/
|
|
83
173
|
public getOriginIP(): string {
|
|
84
|
-
const origin = this.getContextParam(
|
|
85
|
-
const hOrigin = this.getHeader(
|
|
86
|
-
return origin ? origin : hOrigin ? hOrigin :
|
|
174
|
+
const origin = this.getContextParam('identity')?.sourceIp
|
|
175
|
+
const hOrigin = this.getHeader('X-Forwarded-For')
|
|
176
|
+
return origin ? origin : hOrigin ? hOrigin : 'unknown'
|
|
87
177
|
}
|
|
88
|
-
|
|
89
|
-
|
|
178
|
+
/**
|
|
179
|
+
* ${1:Description placeholder}
|
|
180
|
+
*
|
|
181
|
+
* @public
|
|
182
|
+
* @param {any[]} keys
|
|
183
|
+
* @param {any[]} result
|
|
184
|
+
*/
|
|
90
185
|
public setFixedPathParams(keys: any[], result: any[]): void {
|
|
91
186
|
this.requestEvent.pathParameters = {}
|
|
92
|
-
keys.forEach(
|
|
93
|
-
(key, index) =>
|
|
94
|
-
(this.requestEvent.pathParameters[key.name] = result[index + 1]),
|
|
95
|
-
)
|
|
187
|
+
keys.forEach((key, index) => (this.requestEvent.pathParameters[key.name] = result[index + 1]))
|
|
96
188
|
}
|
|
97
189
|
}
|