@ikonintegration/ikapi 4.0.0-alpha8 → 5.0.0-alpha1
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/.eslintignore +3 -0
- package/.eslintrc.cjs +81 -0
- package/.github/workflows/npmpublish.yml +8 -19
- package/.github/workflows/prs.yml +12 -0
- package/dist/index.d.ts +16 -0
- package/dist/index.js +27 -0
- package/dist/index.js.map +1 -0
- package/dist/package-lock.json +11886 -0
- package/dist/package.json +81 -0
- package/dist/src/API/Request.d.ts +125 -0
- package/dist/src/API/Request.js +185 -0
- package/dist/src/API/Request.js.map +1 -0
- package/dist/src/API/Response.d.ts +188 -0
- package/dist/src/API/Response.js +270 -0
- package/dist/src/API/Response.js.map +1 -0
- package/dist/src/BaseEvent/DynamoTransaction.d.ts +20 -0
- package/dist/src/BaseEvent/DynamoTransaction.js +81 -0
- package/dist/src/BaseEvent/DynamoTransaction.js.map +1 -0
- package/dist/src/BaseEvent/EventProcessor.d.ts +58 -0
- package/dist/src/BaseEvent/EventProcessor.js +101 -0
- package/dist/src/BaseEvent/EventProcessor.js.map +1 -0
- package/dist/src/BaseEvent/Process.d.ts +50 -0
- package/dist/src/BaseEvent/Process.js +64 -0
- package/dist/src/BaseEvent/Process.js.map +1 -0
- package/dist/src/BaseEvent/StepTransaction.d.ts +23 -0
- package/dist/src/BaseEvent/StepTransaction.js +27 -0
- package/dist/src/BaseEvent/StepTransaction.js.map +1 -0
- package/dist/src/BaseEvent/Transaction.d.ts +149 -0
- package/dist/src/BaseEvent/Transaction.js +224 -0
- package/dist/src/BaseEvent/Transaction.js.map +1 -0
- package/dist/src/Cache/Redis.d.ts +29 -0
- package/dist/src/Cache/Redis.js +80 -0
- package/dist/src/Cache/Redis.js.map +1 -0
- package/dist/src/Cache/types.d.ts +31 -0
- package/dist/src/Cache/types.js +2 -0
- package/dist/src/Cache/types.js.map +1 -0
- package/dist/src/Config/Configuration.d.ts +123 -0
- package/dist/src/Config/Configuration.js +109 -0
- package/dist/src/Config/Configuration.js.map +1 -0
- package/dist/src/Config/EnvironmentVar.d.ts +74 -0
- package/dist/src/Config/EnvironmentVar.js +138 -0
- package/dist/src/Config/EnvironmentVar.js.map +1 -0
- package/dist/src/Crypto/Crypto.d.ts +45 -0
- package/dist/src/Crypto/Crypto.js +72 -0
- package/dist/src/Crypto/Crypto.js.map +1 -0
- package/dist/src/Database/Database.d.ts +21 -0
- package/dist/src/Database/Database.js +15 -0
- package/dist/src/Database/Database.js.map +1 -0
- package/dist/src/Database/DatabaseManager.d.ts +47 -0
- package/dist/src/Database/DatabaseManager.js +60 -0
- package/dist/src/Database/DatabaseManager.js.map +1 -0
- package/dist/src/Database/DatabaseTransaction.d.ts +101 -0
- package/dist/src/Database/DatabaseTransaction.js +126 -0
- package/dist/src/Database/DatabaseTransaction.js.map +1 -0
- package/dist/src/Database/index.d.ts +10 -0
- package/dist/src/Database/index.js +15 -0
- package/dist/src/Database/index.js.map +1 -0
- package/dist/src/Database/integrations/dynamo/DynamoDatabase.d.ts +35 -0
- package/dist/src/Database/integrations/dynamo/DynamoDatabase.js +59 -0
- package/dist/src/Database/integrations/dynamo/DynamoDatabase.js.map +1 -0
- package/dist/src/Database/integrations/kysely/KyselyDatabase.d.ts +66 -0
- package/dist/src/Database/integrations/kysely/KyselyDatabase.js +86 -0
- package/dist/src/Database/integrations/kysely/KyselyDatabase.js.map +1 -0
- package/dist/src/Database/integrations/kysely/KyselyTransaction.d.ts +70 -0
- package/dist/src/Database/integrations/kysely/KyselyTransaction.js +118 -0
- package/dist/src/Database/integrations/kysely/KyselyTransaction.js.map +1 -0
- package/dist/src/Database/integrations/pgsql/PostgresDatabase.d.ts +36 -0
- package/dist/src/Database/integrations/pgsql/PostgresDatabase.js +54 -0
- package/dist/src/Database/integrations/pgsql/PostgresDatabase.js.map +1 -0
- package/dist/src/Database/integrations/pgsql/PostgresTransaction.d.ts +63 -0
- package/dist/src/Database/integrations/pgsql/PostgresTransaction.js +61 -0
- package/dist/src/Database/integrations/pgsql/PostgresTransaction.js.map +1 -0
- package/dist/src/Database/types.d.ts +76 -0
- package/dist/src/Database/types.js +2 -0
- package/dist/src/Database/types.js.map +1 -0
- package/dist/src/Globals.d.ts +93 -0
- package/dist/src/Globals.js +99 -0
- package/dist/src/Globals.js.map +1 -0
- package/dist/src/Logger/Logger.d.ts +161 -0
- package/dist/src/Logger/Logger.js +297 -0
- package/dist/src/Logger/Logger.js.map +1 -0
- package/dist/src/Mailer/Mailer.d.ts +78 -0
- package/dist/src/Mailer/Mailer.js +182 -0
- package/dist/src/Mailer/Mailer.js.map +1 -0
- package/dist/src/Publisher/Publisher.d.ts +39 -0
- package/dist/src/Publisher/Publisher.js +77 -0
- package/dist/src/Publisher/Publisher.js.map +1 -0
- package/dist/src/Server/RouteResolver.d.ts +33 -0
- package/dist/src/Server/RouteResolver.js +100 -0
- package/dist/src/Server/RouteResolver.js.map +1 -0
- package/dist/src/Server/Router.d.ts +157 -0
- package/dist/src/Server/Router.js +32 -0
- package/dist/src/Server/Router.js.map +1 -0
- package/dist/src/Server/lib/ContainerServer.d.ts +42 -0
- package/dist/src/Server/lib/ContainerServer.js +66 -0
- package/dist/src/Server/lib/ContainerServer.js.map +1 -0
- package/dist/src/Server/lib/Server.d.ts +45 -0
- package/dist/src/Server/lib/Server.js +93 -0
- package/dist/src/Server/lib/Server.js.map +1 -0
- package/dist/src/Server/lib/container/GenericHandler.d.ts +9 -0
- package/dist/src/Server/lib/container/GenericHandler.js +82 -0
- package/dist/src/Server/lib/container/GenericHandler.js.map +1 -0
- package/dist/src/Server/lib/container/GenericHandlerEvent.d.ts +52 -0
- package/dist/src/Server/lib/container/GenericHandlerEvent.js +132 -0
- package/dist/src/Server/lib/container/GenericHandlerEvent.js.map +1 -0
- package/dist/src/Server/lib/container/HealthHandler.d.ts +9 -0
- package/dist/src/Server/lib/container/HealthHandler.js +19 -0
- package/dist/src/Server/lib/container/HealthHandler.js.map +1 -0
- package/dist/src/Server/lib/container/Proxy.d.ts +67 -0
- package/dist/src/Server/lib/container/Proxy.js +143 -0
- package/dist/src/Server/lib/container/Proxy.js.map +1 -0
- package/dist/src/Server/lib/container/Utils.d.ts +14 -0
- package/dist/src/Server/lib/container/Utils.js +37 -0
- package/dist/src/Server/lib/container/Utils.js.map +1 -0
- package/dist/src/Util/AsyncSingleton.d.ts +31 -0
- package/dist/src/Util/AsyncSingleton.js +83 -0
- package/dist/src/Util/AsyncSingleton.js.map +1 -0
- package/dist/src/Util/Utils.d.ts +61 -0
- package/dist/src/Util/Utils.js +147 -0
- package/dist/src/Util/Utils.js.map +1 -0
- package/dist/src/Validation/Validator.d.ts +17 -0
- package/dist/src/Validation/Validator.js +39 -0
- package/dist/src/Validation/Validator.js.map +1 -0
- package/index.ts +41 -0
- package/jest.config.ts +37 -0
- package/jest.smoke.config.ts +34 -0
- package/package.json +66 -22
- package/src/API/Request.ts +214 -0
- package/src/API/Response.ts +370 -0
- package/src/BaseEvent/DynamoTransaction.ts +125 -0
- package/src/BaseEvent/EventProcessor.ts +140 -0
- package/src/BaseEvent/Process.ts +78 -0
- package/src/BaseEvent/StepTransaction.ts +35 -0
- package/src/BaseEvent/Transaction.ts +323 -0
- package/src/Cache/Redis.ts +89 -0
- package/src/Cache/types.ts +33 -0
- package/src/Config/Configuration.ts +199 -0
- package/src/Config/EnvironmentVar.ts +147 -0
- package/src/Crypto/Crypto.ts +89 -0
- package/src/Database/Database.ts +22 -0
- package/src/Database/DatabaseManager.ts +67 -0
- package/src/Database/DatabaseTransaction.ts +170 -0
- package/src/Database/index.ts +27 -0
- package/src/Database/integrations/dynamo/DynamoDatabase.ts +58 -0
- package/src/Database/integrations/kysely/KyselyDatabase.ts +99 -0
- package/src/Database/integrations/kysely/KyselyTransaction.ts +172 -0
- package/src/Database/integrations/pgsql/PostgresDatabase.ts +56 -0
- package/src/Database/integrations/pgsql/PostgresTransaction.ts +87 -0
- package/src/Database/types.ts +85 -0
- package/src/Globals.ts +103 -0
- package/src/Logger/Logger.ts +360 -0
- package/src/Mailer/Mailer.ts +217 -0
- package/src/Publisher/Publisher.ts +96 -0
- package/src/Server/RouteResolver.ts +124 -0
- package/src/Server/Router.ts +200 -0
- package/src/Server/lib/ContainerServer.ts +65 -0
- package/src/Server/lib/Server.ts +109 -0
- package/src/Server/lib/container/GenericHandler.ts +76 -0
- package/src/Server/lib/container/GenericHandlerEvent.ts +154 -0
- package/src/Server/lib/container/HealthHandler.ts +11 -0
- package/src/Server/lib/container/Proxy.ts +172 -0
- package/src/Server/lib/container/Utils.ts +33 -0
- package/src/Util/AsyncSingleton.ts +86 -0
- package/src/Util/Utils.ts +131 -0
- package/src/Validation/Validator.ts +45 -0
- package/tests/API/Request.test.ts +273 -0
- package/tests/API/Response.test.ts +367 -0
- package/tests/BaseEvent/DynamoTransaction.test.ts +272 -0
- package/tests/BaseEvent/EventProcessor.test.ts +263 -0
- package/tests/BaseEvent/Process.test.ts +47 -0
- package/tests/BaseEvent/StepTransaction.test.ts +44 -0
- package/tests/BaseEvent/Transaction.test.ts +402 -0
- package/tests/Cache/Redis-client.test.ts +90 -0
- package/tests/Cache/Redis-cluster.test.ts +100 -0
- package/tests/Config/Config.test.ts +205 -0
- package/tests/Config/EnvironmentVar.test.ts +251 -0
- package/tests/Crypto/Crypto.test.ts +88 -0
- package/tests/Database/DatabaseManager.test.ts +79 -0
- package/tests/Database/integrations/dynamo/DynamoDatabase.test.ts +44 -0
- package/tests/Database/integrations/kysely/KyselyDatabase.test.ts +113 -0
- package/tests/Database/integrations/kysely/KyselyTransaction.test.ts +119 -0
- package/tests/Database/integrations/pg/PostgresDatabase.test.ts +76 -0
- package/tests/Database/integrations/pg/PostgresTransaction.test.ts +118 -0
- package/tests/Logger/Logger.test.ts +215 -0
- package/tests/Mailer/Mailer.test.ts +59 -0
- package/tests/Publisher/Publisher.test.ts +60 -0
- package/tests/Server/RouteResolver.test.ts +116 -0
- package/tests/Server/Router.test.ts +39 -0
- package/tests/Server/lib/ContainerServer.test.ts +531 -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 +103 -0
- package/tests/Server/lib/container/HealthHandler.test.ts +30 -0
- package/tests/Server/lib/container/Proxy.test.ts +268 -0
- package/tests/Server/lib/container/Utils.test.ts +47 -0
- package/tests/Test.utils.ts +78 -0
- package/tests/Utils/Utils.test.ts +230 -0
- package/tests/Validation/Validator.test.ts +82 -0
- package/tsconfig.json +26 -0
- package/tsconfig.smoke.json +26 -0
- package/index.js +0 -88
- package/src/API/IKRequest.js +0 -52
- package/src/API/IKResponse.js +0 -119
- package/src/API/IKUtils.js +0 -51
- package/src/BaseEvent/IKProcess.js +0 -77
- package/src/BaseEvent/IKTransaction.js +0 -139
- package/src/Cache/Prototype/IKCache.js +0 -17
- package/src/Cache/Redis/IKRedis.js +0 -148
- package/src/Database/DDB/IKDB.js +0 -56
- package/src/Database/DDB/IKDBBaseExpression.js +0 -130
- package/src/Database/DDB/IKDBBaseQuery.js +0 -151
- package/src/Database/DDB/IKDBQueryBatchGet.js +0 -37
- package/src/Database/DDB/IKDBQueryBatchWrite.js +0 -64
- package/src/Database/DDB/IKDBQueryDelete.js +0 -34
- package/src/Database/DDB/IKDBQueryGet.js +0 -48
- package/src/Database/DDB/IKDBQueryPut.js +0 -87
- package/src/Database/DDB/IKDBQueryScan.js +0 -45
- package/src/Database/DDB/IKDBQueryTransactionalWrite.js +0 -69
- package/src/Database/DDB/IKDBQueryUpdate.js +0 -219
- package/src/Database/DDB/_IKDBQueryTransactionalRead.js +0 -46
- package/src/Database/PSQL/IKDB.js +0 -41
- package/src/Database/PSQL/IKDBBaseQuery.js +0 -26
- package/src/Database/Prototype/IKDB.js +0 -21
- package/src/Database/Prototype/IKDBBaseQuery.js +0 -14
- package/src/IKDynamoStream.js +0 -42
- package/src/IKEventProcessor.js +0 -42
- package/src/IKGlobals.js +0 -24
- package/src/IKRouter.js +0 -47
- package/src/IKStepTransaction.js +0 -14
- package/src/Logger/IKLogger.js +0 -136
- package/src/Mailer/IKMailer.js +0 -68
- package/src/Publisher/IKPublisher.js +0 -44
- package/src/Tracker/IKExecutionTracker.js +0 -79
- package/src/Validation/IKValidation.js +0 -77
package/jest.config.ts
ADDED
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import type { Config } from '@jest/types'
|
|
2
|
+
/* eslint-env node */
|
|
3
|
+
const config: Config.InitialOptions = {
|
|
4
|
+
preset: 'ts-jest/presets/default-esm',
|
|
5
|
+
testEnvironment: 'node',
|
|
6
|
+
modulePathIgnorePatterns: ['smoke-tests'],
|
|
7
|
+
reporters: [
|
|
8
|
+
'default',
|
|
9
|
+
[
|
|
10
|
+
'jest-junit',
|
|
11
|
+
{
|
|
12
|
+
outputDirectory: 'coverage',
|
|
13
|
+
outputName: 'jest-junit.xml',
|
|
14
|
+
ancestorSeparator: ' › ',
|
|
15
|
+
uniqueOutputName: 'false',
|
|
16
|
+
suiteNameTemplate: '{filepath}',
|
|
17
|
+
classNameTemplate: '{classname}',
|
|
18
|
+
titleTemplate: '{title}',
|
|
19
|
+
},
|
|
20
|
+
],
|
|
21
|
+
],
|
|
22
|
+
coverageReporters: ['clover', 'json', 'lcov', ['text', { file: 'coverage.txt' }], 'json-summary'],
|
|
23
|
+
collectCoverageFrom: ['src/**/*.(t|j)s', '!src/**/*.d.(t|j)s'],
|
|
24
|
+
coverageThreshold: {
|
|
25
|
+
global: {
|
|
26
|
+
branches: 80,
|
|
27
|
+
functions: 80,
|
|
28
|
+
lines: 80,
|
|
29
|
+
statements: 80,
|
|
30
|
+
},
|
|
31
|
+
},
|
|
32
|
+
// .js imports support
|
|
33
|
+
moduleNameMapper: {
|
|
34
|
+
'^(\\.\\.?\\/.+)\\.jsx?$': '$1',
|
|
35
|
+
},
|
|
36
|
+
}
|
|
37
|
+
export default config
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import type { Config } from '@jest/types'
|
|
2
|
+
/* eslint-env node */
|
|
3
|
+
const config: Config.InitialOptions = {
|
|
4
|
+
testEnvironment: 'node',
|
|
5
|
+
// ECMA suppport https://jestjs.io/docs/ecmascript-modules
|
|
6
|
+
transform: {},
|
|
7
|
+
//
|
|
8
|
+
reporters: [
|
|
9
|
+
'default',
|
|
10
|
+
[
|
|
11
|
+
'jest-junit',
|
|
12
|
+
{
|
|
13
|
+
outputDirectory: 'coverage',
|
|
14
|
+
outputName: 'jest-junit.xml',
|
|
15
|
+
ancestorSeparator: ' › ',
|
|
16
|
+
uniqueOutputName: 'false',
|
|
17
|
+
suiteNameTemplate: '{filepath}',
|
|
18
|
+
classNameTemplate: '{classname}',
|
|
19
|
+
titleTemplate: '{title}',
|
|
20
|
+
},
|
|
21
|
+
],
|
|
22
|
+
],
|
|
23
|
+
coverageReporters: ['clover', 'json', 'lcov', ['text', { file: 'coverage.txt' }], 'json-summary'],
|
|
24
|
+
collectCoverageFrom: ['src/**/*.(t|j)s', '!src/**/*.d.(t|j)s'],
|
|
25
|
+
coverageThreshold: {
|
|
26
|
+
global: {
|
|
27
|
+
branches: 70,
|
|
28
|
+
functions: 70,
|
|
29
|
+
lines: 70,
|
|
30
|
+
statements: 70,
|
|
31
|
+
},
|
|
32
|
+
},
|
|
33
|
+
}
|
|
34
|
+
export default config
|
package/package.json
CHANGED
|
@@ -1,37 +1,81 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ikonintegration/ikapi",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "5.0.0-alpha1",
|
|
4
4
|
"description": "",
|
|
5
|
-
"main": "index.js",
|
|
6
|
-
"
|
|
5
|
+
"main": "dist/index.js",
|
|
6
|
+
"types": "dist/index.d.ts",
|
|
7
7
|
"type": "module",
|
|
8
8
|
"scripts": {
|
|
9
|
-
"
|
|
10
|
-
"
|
|
9
|
+
"build": "tsc --build",
|
|
10
|
+
"clean": "tsc --build --clean",
|
|
11
|
+
"lint-fix": "eslint . --fix",
|
|
12
|
+
"lint": "eslint .",
|
|
13
|
+
"docs": "npx typedoc --tsconfig tsconfig.json index.ts src/**/* --includeVersion --entryPointStrategy expand",
|
|
14
|
+
"test": "npm run test-ts && npm run test-js",
|
|
15
|
+
"test-ts": "jest --coverage --silent --runInBand --logHeapUsage && cat coverage/coverage.txt",
|
|
16
|
+
"test-js": "rm -rf ./smoke-tests; tsc -p tsconfig.smoke.json && cd smoke-tests && npm i && NODE_OPTIONS=\"$NODE_OPTIONS --experimental-vm-modules\" jest --config=./jest.smoke.config.js --coverage --silent --runInBand --logHeapUsage && cat coverage/coverage.txt",
|
|
17
|
+
"test-dev": "jest --coverage --runInBand && cat coverage/coverage.txt"
|
|
11
18
|
},
|
|
12
19
|
"author": "",
|
|
13
20
|
"license": "ISC",
|
|
14
21
|
"dependencies": {
|
|
15
|
-
"@aws-sdk/client-dynamodb": "^3.
|
|
16
|
-
"@aws-sdk/client-
|
|
17
|
-
"@aws-sdk/client-
|
|
18
|
-
"@aws-sdk/
|
|
19
|
-
"@aws-sdk/
|
|
20
|
-
"@aws-sdk/
|
|
21
|
-
"@aws-sdk/
|
|
22
|
-
"@
|
|
22
|
+
"@aws-sdk/client-dynamodb": "^3.574.0",
|
|
23
|
+
"@aws-sdk/client-kms": "^3.556.0",
|
|
24
|
+
"@aws-sdk/client-secrets-manager": "^3.576.0",
|
|
25
|
+
"@aws-sdk/client-ses": "^3.576.0",
|
|
26
|
+
"@aws-sdk/client-sns": "^3.576.0",
|
|
27
|
+
"@aws-sdk/client-ssm": "^3.576.0",
|
|
28
|
+
"@aws-sdk/credential-provider-node": "^3.576.0",
|
|
29
|
+
"@aws-sdk/util-dynamodb": "^3.619.0",
|
|
30
|
+
"@smithy/node-http-handler": "^3.0.0",
|
|
31
|
+
"@types/email-templates": "^10.0.1",
|
|
32
|
+
"@types/nodemailer": "^6.4.10",
|
|
33
|
+
"@types/object-hash": "^3.0.4",
|
|
23
34
|
"abind": "^1.0.5",
|
|
24
|
-
"
|
|
25
|
-
"
|
|
26
|
-
"
|
|
27
|
-
"
|
|
35
|
+
"cors": "^2.8.5",
|
|
36
|
+
"cuid": "^3.0.0",
|
|
37
|
+
"dotenv": "^16.4.1",
|
|
38
|
+
"email-templates": "^12.0.1",
|
|
39
|
+
"express": "^4.18.2",
|
|
28
40
|
"json-stringify-safe": "^5.0.1",
|
|
29
|
-
"
|
|
30
|
-
"
|
|
31
|
-
"
|
|
32
|
-
"
|
|
41
|
+
"kysely": "^0.27.2",
|
|
42
|
+
"node-cache": "^5.1.2",
|
|
43
|
+
"object-hash": "^3.0.0",
|
|
44
|
+
"parse-duration": "^1.1.0",
|
|
45
|
+
"path-to-regexp": "^7.1.0",
|
|
46
|
+
"pg": "^8.11.3",
|
|
47
|
+
"redis": "^4.6.13",
|
|
33
48
|
"sha1": "^1.1.1",
|
|
34
49
|
"stack-trace": "0.0.10",
|
|
35
|
-
"
|
|
50
|
+
"zod": "^3.23.4"
|
|
51
|
+
},
|
|
52
|
+
"devDependencies": {
|
|
53
|
+
"@jest/globals": "^29.7.0",
|
|
54
|
+
"@types/aws-lambda": "^8.10.137",
|
|
55
|
+
"@types/chai": "^4.3.9",
|
|
56
|
+
"@types/cors": "^2.8.15",
|
|
57
|
+
"@types/express": "^4.17.19",
|
|
58
|
+
"@types/jest": "^29.5.12",
|
|
59
|
+
"@types/node": "^20.12.7",
|
|
60
|
+
"@types/path-to-regexp": "^1.7.0",
|
|
61
|
+
"@types/pg": "^8.11.5",
|
|
62
|
+
"@types/supertest": "^6.0.2",
|
|
63
|
+
"@typescript-eslint/eslint-plugin": "^7.7.1",
|
|
64
|
+
"@typescript-eslint/parser": "^7.7.1",
|
|
65
|
+
"aws-lambda": "^1.0.7",
|
|
66
|
+
"aws-sdk-client-mock": "^4.0.0",
|
|
67
|
+
"chai": "^4.4.1",
|
|
68
|
+
"eslint": "^8.48.0",
|
|
69
|
+
"eslint-config-prettier": "^9.0.0",
|
|
70
|
+
"eslint-plugin-import": "^2.28.1",
|
|
71
|
+
"eslint-plugin-prettier": "^5.0.0",
|
|
72
|
+
"eslint-plugin-require-extensions": "^0.1.3",
|
|
73
|
+
"jest": "^29.7.0",
|
|
74
|
+
"jest-junit": "^16.0.0",
|
|
75
|
+
"prettier": "^3.2.5",
|
|
76
|
+
"supertest": "^7.0.0",
|
|
77
|
+
"ts-jest": "^29.1.1",
|
|
78
|
+
"ts-node": "^10.9.1",
|
|
79
|
+
"typescript": "^5.4.5"
|
|
36
80
|
}
|
|
37
81
|
}
|
|
@@ -0,0 +1,214 @@
|
|
|
1
|
+
import type { Context, APIGatewayEvent } from 'aws-lambda'
|
|
2
|
+
|
|
3
|
+
import Logger from '../Logger/Logger.js'
|
|
4
|
+
import Utils from '../Util/Utils.js'
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* Represents a request object with generic types for input, query parameters, and path parameters.
|
|
8
|
+
* @class Request
|
|
9
|
+
* @template InputType - The type of the input data for the request.
|
|
10
|
+
* @template PathParamsType - The type of the path parameters for the request.
|
|
11
|
+
* @template QueryParamsType - The type of the query parameters for the request.
|
|
12
|
+
*/
|
|
13
|
+
export default class Request<InputType, PathParamsType, QueryParamsType> {
|
|
14
|
+
/**
|
|
15
|
+
* Represents an API Gateway event for a request.
|
|
16
|
+
* @type {APIGatewayEvent}
|
|
17
|
+
*/
|
|
18
|
+
private requestEvent: APIGatewayEvent
|
|
19
|
+
/**
|
|
20
|
+
* The context object for the current instance.
|
|
21
|
+
*/
|
|
22
|
+
private context: Context
|
|
23
|
+
|
|
24
|
+
/**
|
|
25
|
+
* Constructs a new instance of the class.
|
|
26
|
+
* @param {APIGatewayEvent} requestEvent - The API Gateway event object.
|
|
27
|
+
* @param {Context} context - The context object.
|
|
28
|
+
* @param {Logger} logger - The logger object.
|
|
29
|
+
* @returns None
|
|
30
|
+
*/
|
|
31
|
+
constructor(requestEvent: APIGatewayEvent, context: Context, logger: Logger) {
|
|
32
|
+
this.requestEvent = requestEvent
|
|
33
|
+
this.context = context
|
|
34
|
+
logger.debug('Request info:', requestEvent)
|
|
35
|
+
logger.debug('Request context:', context)
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
/**
|
|
39
|
+
* Checks if the specified query parameter exists and has a valid value.
|
|
40
|
+
* @param {keyof QueryParamsType} paramName - The name of the query parameter to check.
|
|
41
|
+
* @returns {boolean} - True if the query parameter exists and has a valid value, false otherwise.
|
|
42
|
+
*/
|
|
43
|
+
public containsQueryParam(paramName: keyof QueryParamsType): boolean {
|
|
44
|
+
const val = this.getQueryParam(paramName)
|
|
45
|
+
return !!val && (Utils.isValidString(val) || Utils.isValidNumber(val))
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
/**
|
|
49
|
+
* Retrieves the value of a query parameter from the URL.
|
|
50
|
+
* @param {keyof QueryParamsType} paramName - The name of the query parameter to retrieve.
|
|
51
|
+
* @returns {string | null} The value of the query parameter, or null if it does not exist.
|
|
52
|
+
*/
|
|
53
|
+
public getQueryParam(paramName: keyof QueryParamsType): string {
|
|
54
|
+
return Utils.caseInsensitiveObjectForKey(
|
|
55
|
+
this.requestEvent.queryStringParameters,
|
|
56
|
+
String(paramName)
|
|
57
|
+
)
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
/**
|
|
61
|
+
* Retrieves the value of the specified header from the request event headers.
|
|
62
|
+
* @param {string} headerName - The name of the header to retrieve.
|
|
63
|
+
* @returns {string | null} - The value of the header, or null if the header is not found.
|
|
64
|
+
*/
|
|
65
|
+
public getHeader(headerName: string): string | null {
|
|
66
|
+
return Utils.caseInsensitiveObjectForKey(this.requestEvent.headers, headerName)
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
/**
|
|
70
|
+
* Retrieves the value of a context parameter from the request context object.
|
|
71
|
+
* @param {string} cxtParam - The name of the context parameter to retrieve.
|
|
72
|
+
* @returns The value of the context parameter, or null if it does not exist.
|
|
73
|
+
*/
|
|
74
|
+
public getContextParam(cxtParam: string): any | null {
|
|
75
|
+
return Utils.caseInsensitiveObjectForKey(this.requestEvent.requestContext, cxtParam)
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
/**
|
|
79
|
+
* Checks if the given parameter name exists in the PathParamsType object.
|
|
80
|
+
* @param {keyof PathParamsType} paramName - The name of the parameter to check.
|
|
81
|
+
* @returns {boolean} - True if the parameter exists, false otherwise.
|
|
82
|
+
*/
|
|
83
|
+
public containsPathParam(paramName: keyof PathParamsType): boolean {
|
|
84
|
+
const val = this.getPathParam(paramName)
|
|
85
|
+
return !!val && (Utils.isValidString(val) || Utils.isValidNumber(val))
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
/**
|
|
89
|
+
* Retrieves the value of a specific path parameter from the URL.
|
|
90
|
+
* @param {keyof PathParamsType} paramName - The name of the path parameter to retrieve.
|
|
91
|
+
* @returns {string} The value of the path parameter, or null if it does not exist.
|
|
92
|
+
*/
|
|
93
|
+
public getPathParam(paramName: keyof PathParamsType): string {
|
|
94
|
+
return Utils.caseInsensitiveObjectForKey(this.requestEvent.pathParameters, String(paramName))
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
/**
|
|
98
|
+
* Retrieves the body of the request event and parses it if it is a string.
|
|
99
|
+
* @returns {InputType} The parsed body of the request event.
|
|
100
|
+
*/
|
|
101
|
+
public getBody(raw?: boolean): InputType {
|
|
102
|
+
const body: any = this.requestEvent.body
|
|
103
|
+
|
|
104
|
+
if (raw) return Utils.isHybridlessContainer() ? this.requestEvent['rawBody'] : body
|
|
105
|
+
|
|
106
|
+
if (typeof body === 'string' || body instanceof String) {
|
|
107
|
+
try {
|
|
108
|
+
return JSON.parse(body as string)
|
|
109
|
+
} catch (e) {
|
|
110
|
+
console.error('Error while getting request body!', e)
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
return body
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
/**
|
|
118
|
+
* Retrieves the path from the request event.
|
|
119
|
+
* @returns {string} The path of the request event.
|
|
120
|
+
*/
|
|
121
|
+
public getPath(): string {
|
|
122
|
+
return this.requestEvent.path
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
/**
|
|
126
|
+
* Retrieves the HTTP method of the current request.
|
|
127
|
+
* @returns {string} The HTTP method of the request.
|
|
128
|
+
*/
|
|
129
|
+
public getMethod(): HttpMethod {
|
|
130
|
+
if (this.requestEvent.httpMethod) {
|
|
131
|
+
const httpMethod = this.requestEvent.httpMethod.toUpperCase()
|
|
132
|
+
if (httpMethod in HttpMethod) {
|
|
133
|
+
return HttpMethod[httpMethod]
|
|
134
|
+
}
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
throw new Error(`Invalid HTTP method: ${this.requestEvent.httpMethod}`)
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
/**
|
|
141
|
+
* Retrieves the path parameters from the request event.
|
|
142
|
+
* @returns {PathParamsType | null} - The path parameters object, or null if not found.
|
|
143
|
+
*/
|
|
144
|
+
public getPathParams(): PathParamsType {
|
|
145
|
+
// type conversion guaranteed by validation
|
|
146
|
+
return this.requestEvent.pathParameters as PathParamsType
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
/**
|
|
150
|
+
* Retrieves the query parameters from the request event.
|
|
151
|
+
* @returns {QueryParamsType | null} - The query parameters object, or null if not found.
|
|
152
|
+
*/
|
|
153
|
+
public getQueryParams(): QueryParamsType {
|
|
154
|
+
// type conversion guaranteed by validation
|
|
155
|
+
return this.requestEvent.queryStringParameters as QueryParamsType
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
/**
|
|
159
|
+
* Retrieves the value of the 'Authorization' header from the request.
|
|
160
|
+
* @returns The value of the 'Authorization' header, or null if it is not present.
|
|
161
|
+
*/
|
|
162
|
+
public getAuthorizationHeader(): string | null {
|
|
163
|
+
return this.getHeader('Authorization')
|
|
164
|
+
}
|
|
165
|
+
|
|
166
|
+
/**
|
|
167
|
+
* Retrieves the request ID associated with the current execution context.
|
|
168
|
+
* @returns {string} The request ID.
|
|
169
|
+
*/
|
|
170
|
+
public getRequestID(): string {
|
|
171
|
+
if (this.context.awsRequestId) return this.context.awsRequestId
|
|
172
|
+
return this.requestEvent.requestContext ? this.requestEvent.requestContext.requestId : 'unknown'
|
|
173
|
+
}
|
|
174
|
+
|
|
175
|
+
/**
|
|
176
|
+
* Retrieves the origin IP address of the request.
|
|
177
|
+
* @returns {string} The origin IP address. If the IP address is not available, it returns 'unknown'.
|
|
178
|
+
*/
|
|
179
|
+
public getOriginIP(): string {
|
|
180
|
+
const origin = this.getContextParam('identity')?.sourceIp
|
|
181
|
+
const hOrigin = this.getHeader('X-Forwarded-For')
|
|
182
|
+
return origin ? origin : hOrigin ? hOrigin : 'unknown'
|
|
183
|
+
}
|
|
184
|
+
|
|
185
|
+
/**
|
|
186
|
+
* Sets the fixed path parameters in the request event object.
|
|
187
|
+
* @param {any[]} keys - An array of keys representing the path parameter names.
|
|
188
|
+
* @param {any[]} result - An array of values representing the path parameter values.
|
|
189
|
+
* @returns None
|
|
190
|
+
*/
|
|
191
|
+
public setFixedPathParams(keys: any[], result: any[]): void {
|
|
192
|
+
if (!this.requestEvent.pathParameters) this.requestEvent.pathParameters = {}
|
|
193
|
+
keys.forEach((key, index) => {
|
|
194
|
+
if (this.requestEvent?.pathParameters) {
|
|
195
|
+
this.requestEvent.pathParameters[key.name] = result[index + 1]
|
|
196
|
+
}
|
|
197
|
+
})
|
|
198
|
+
}
|
|
199
|
+
}
|
|
200
|
+
|
|
201
|
+
/**
|
|
202
|
+
* Enum representing the HTTP methods.
|
|
203
|
+
*/
|
|
204
|
+
export enum HttpMethod {
|
|
205
|
+
GET = 'GET',
|
|
206
|
+
HEAD = 'HEAD',
|
|
207
|
+
POST = 'POST',
|
|
208
|
+
PUT = 'PUT',
|
|
209
|
+
DELETE = 'DELETE',
|
|
210
|
+
CONNECT = 'CONNECT',
|
|
211
|
+
OPTIONS = 'OPTIONS',
|
|
212
|
+
TRACE = 'TRACE',
|
|
213
|
+
PATCH = 'PATCH',
|
|
214
|
+
}
|