@creator.co/wapi 1.6.0 → 2.0.0-alpha.1
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/.github/workflows/prs.yml +1 -1
- package/dist/index.js +45 -31
- package/dist/index.js.map +1 -1
- package/dist/jest.config.js +2 -4
- package/dist/jest.config.js.map +1 -1
- package/dist/package.json +12 -12
- package/dist/src/API/Request.js +53 -59
- package/dist/src/API/Request.js.map +1 -1
- package/dist/src/API/Response.js +81 -156
- package/dist/src/API/Response.js.map +1 -1
- package/dist/src/BaseEvent/EventProcessor.js +54 -132
- package/dist/src/BaseEvent/EventProcessor.js.map +1 -1
- package/dist/src/BaseEvent/Process.js +40 -98
- package/dist/src/BaseEvent/Process.js.map +1 -1
- package/dist/src/BaseEvent/Transaction.js +122 -310
- package/dist/src/BaseEvent/Transaction.js.map +1 -1
- package/dist/src/Cache/Redis.js +55 -119
- package/dist/src/Cache/Redis.js.map +1 -1
- package/dist/src/Cache/types.js +1 -2
- package/dist/src/Config/Configuration.js +46 -86
- package/dist/src/Config/Configuration.js.map +1 -1
- package/dist/src/Config/EnvironmentVar.js +57 -119
- package/dist/src/Config/EnvironmentVar.js.map +1 -1
- package/dist/src/Crypto/Crypto.js +35 -82
- package/dist/src/Crypto/Crypto.js.map +1 -1
- package/dist/src/Crypto/JWT.js +12 -27
- package/dist/src/Crypto/JWT.js.map +1 -1
- package/dist/src/Database/Database.js +3 -8
- package/dist/src/Database/Database.js.map +1 -1
- package/dist/src/Database/DatabaseManager.js +23 -28
- package/dist/src/Database/DatabaseManager.js.map +1 -1
- package/dist/src/Database/DatabaseTransaction.js +50 -166
- package/dist/src/Database/DatabaseTransaction.js.map +1 -1
- package/dist/src/Database/index.js +11 -15
- package/dist/src/Database/index.js.map +1 -1
- package/dist/src/Database/integrations/knex/KnexDatabase.js +22 -76
- package/dist/src/Database/integrations/knex/KnexDatabase.js.map +1 -1
- package/dist/src/Database/integrations/knex/KnexTransaction.js +19 -85
- package/dist/src/Database/integrations/knex/KnexTransaction.js.map +1 -1
- package/dist/src/Database/integrations/kysely/KyselyDatabase.js +37 -88
- package/dist/src/Database/integrations/kysely/KyselyDatabase.js.map +1 -1
- package/dist/src/Database/integrations/kysely/KyselyTransaction.js +46 -114
- package/dist/src/Database/integrations/kysely/KyselyTransaction.js.map +1 -1
- package/dist/src/Database/integrations/pgsql/PostgresDatabase.js +20 -71
- package/dist/src/Database/integrations/pgsql/PostgresDatabase.js.map +1 -1
- package/dist/src/Database/integrations/pgsql/PostgresTransaction.js +19 -85
- package/dist/src/Database/integrations/pgsql/PostgresTransaction.js.map +1 -1
- package/dist/src/Database/types.js +1 -2
- package/dist/src/Globals.js +93 -98
- package/dist/src/Globals.js.map +1 -1
- package/dist/src/Logger/Logger.js +88 -222
- package/dist/src/Logger/Logger.js.map +1 -1
- package/dist/src/Mailer/Mailer.js +83 -204
- package/dist/src/Mailer/Mailer.js.map +1 -1
- package/dist/src/Publisher/Publisher.js +43 -107
- package/dist/src/Publisher/Publisher.js.map +1 -1
- package/dist/src/Server/RouteResolver.js +22 -49
- package/dist/src/Server/RouteResolver.js.map +1 -1
- package/dist/src/Server/Router.js +12 -16
- package/dist/src/Server/Router.js.map +1 -1
- package/dist/src/Server/lib/ContainerServer.js +21 -83
- package/dist/src/Server/lib/ContainerServer.js.map +1 -1
- package/dist/src/Server/lib/Server.js +50 -99
- package/dist/src/Server/lib/Server.js.map +1 -1
- package/dist/src/Server/lib/container/GenericHandler.js +32 -107
- package/dist/src/Server/lib/container/GenericHandler.js.map +1 -1
- package/dist/src/Server/lib/container/GenericHandlerEvent.js +37 -81
- package/dist/src/Server/lib/container/GenericHandlerEvent.js.map +1 -1
- package/dist/src/Server/lib/container/HealthHandler.js +3 -35
- package/dist/src/Server/lib/container/HealthHandler.js.map +1 -1
- package/dist/src/Server/lib/container/Proxy.js +64 -127
- package/dist/src/Server/lib/container/Proxy.js.map +1 -1
- package/dist/src/Server/lib/container/Utils.js +12 -55
- package/dist/src/Server/lib/container/Utils.js.map +1 -1
- package/dist/src/Util/AsyncSingleton.js +40 -164
- package/dist/src/Util/AsyncSingleton.js.map +1 -1
- package/dist/src/Util/Utils.js +18 -24
- package/dist/src/Util/Utils.js.map +1 -1
- package/dist/src/Validation/Validator.js +10 -16
- package/dist/src/Validation/Validator.js.map +1 -1
- package/package.json +12 -12
- package/src/Logger/Logger.ts +2 -2
- package/tests/Logger/Logger.test.ts +6 -4
- package/tsconfig.json +3 -1
package/dist/index.js
CHANGED
|
@@ -1,32 +1,46 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
exports
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
1
|
+
import { HttpMethod } from './src/API/Request';
|
|
2
|
+
import Response from './src/API/Response';
|
|
3
|
+
import EventProcessor from './src/BaseEvent/EventProcessor';
|
|
4
|
+
import Process from './src/BaseEvent/Process';
|
|
5
|
+
import Transaction from './src/BaseEvent/Transaction';
|
|
6
|
+
import Redis from './src/Cache/Redis';
|
|
7
|
+
import Configuration from './src/Config/Configuration';
|
|
8
|
+
import Crypto from './src/Crypto/Crypto';
|
|
9
|
+
import JWT from './src/Crypto/JWT';
|
|
10
|
+
import * as Database from './src/Database';
|
|
11
|
+
import Mailer from './src/Mailer/Mailer';
|
|
12
|
+
import Router from './src/Server/Router';
|
|
13
|
+
import AsyncSingleton from './src/Util/AsyncSingleton';
|
|
14
|
+
import Utils from './src/Util/Utils';
|
|
15
|
+
/**
|
|
16
|
+
* This module exports various classes and utilities for handling transactions, processes, events, routing,
|
|
17
|
+
* mailing, cryptography, JWT, configuration, Redis, responses, utilities, routes, response error types,
|
|
18
|
+
* HTTP methods, and databases.
|
|
19
|
+
* @exports {
|
|
20
|
+
* Transaction,
|
|
21
|
+
* Process,
|
|
22
|
+
* EventProcessor,
|
|
23
|
+
* Router,
|
|
24
|
+
* Mailer,
|
|
25
|
+
* Crypto,
|
|
26
|
+
* JWT,
|
|
27
|
+
* Configuration,
|
|
28
|
+
* Redis,
|
|
29
|
+
* Response,
|
|
30
|
+
* Utils,
|
|
31
|
+
* Route,
|
|
32
|
+
* ResponseErrorType,
|
|
33
|
+
* HttpMethod,
|
|
34
|
+
* Database,
|
|
35
|
+
* }
|
|
36
|
+
*/
|
|
37
|
+
export {
|
|
38
|
+
// Base Events
|
|
39
|
+
Transaction, Process, EventProcessor, Router,
|
|
40
|
+
// Externally initialized clients
|
|
41
|
+
Mailer, Crypto, JWT, Configuration, Redis,
|
|
42
|
+
// API
|
|
43
|
+
Response,
|
|
44
|
+
// Helpers
|
|
45
|
+
Utils, AsyncSingleton, HttpMethod, Database, };
|
|
32
46
|
//# sourceMappingURL=index.js.map
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../index.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,mBAAmB,CAAA;AAC9C,OAAO,QAA+B,MAAM,oBAAoB,CAAA;AAChE,OAAO,cAAc,MAAM,gCAAgC,CAAA;AAC3D,OAAO,OAAO,MAAM,yBAAyB,CAAA;AAC7C,OAAO,WAAW,MAAM,6BAA6B,CAAA;AACrD,OAAO,KAAK,MAAM,mBAAmB,CAAA;AACrC,OAAO,aAAa,MAAM,4BAA4B,CAAA;AACtD,OAAO,MAAM,MAAM,qBAAqB,CAAA;AACxC,OAAO,GAAG,MAAM,kBAAkB,CAAA;AAClC,OAAO,KAAK,QAAQ,MAAM,gBAAgB,CAAA;AAC1C,OAAO,MAAM,MAAM,qBAAqB,CAAA;AACxC,OAAO,MAAiB,MAAM,qBAAqB,CAAA;AACnD,OAAO,cAAc,MAAM,2BAA2B,CAAA;AACtD,OAAO,KAAK,MAAM,kBAAkB,CAAA;AAEpC;;;;;;;;;;;;;;;;;;;;;GAqBG;AACH,OAAO;AACL,cAAc;AACd,WAAW,EACX,OAAO,EACP,cAAc,EACd,MAAM;AACN,iCAAiC;AACjC,MAAM,EACN,MAAM,EACN,GAAG,EACH,aAAa,EACb,KAAK;AACL,MAAM;AACN,QAAQ;AACR,UAAU;AACV,KAAK,EACL,cAAc,EAId,UAAU,EACV,QAAQ,GACT,CAAA"}
|
package/dist/jest.config.js
CHANGED
|
@@ -1,7 +1,5 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
1
|
/* eslint-env node */
|
|
4
|
-
|
|
2
|
+
const config = {
|
|
5
3
|
preset: 'ts-jest',
|
|
6
4
|
testEnvironment: 'node',
|
|
7
5
|
reporters: [
|
|
@@ -30,5 +28,5 @@ var config = {
|
|
|
30
28
|
},
|
|
31
29
|
},
|
|
32
30
|
};
|
|
33
|
-
|
|
31
|
+
export default config;
|
|
34
32
|
//# sourceMappingURL=jest.config.js.map
|
package/dist/jest.config.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"jest.config.js","sourceRoot":"","sources":["../jest.config.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"jest.config.js","sourceRoot":"","sources":["../jest.config.ts"],"names":[],"mappings":"AACA,qBAAqB;AACrB,MAAM,MAAM,GAA0B;IACpC,MAAM,EAAE,SAAS;IACjB,eAAe,EAAE,MAAM;IACvB,SAAS,EAAE;QACT,SAAS;QACT;YACE,YAAY;YACZ;gBACE,eAAe,EAAE,UAAU;gBAC3B,UAAU,EAAE,gBAAgB;gBAC5B,iBAAiB,EAAE,KAAK;gBACxB,gBAAgB,EAAE,OAAO;gBACzB,iBAAiB,EAAE,YAAY;gBAC/B,iBAAiB,EAAE,aAAa;gBAChC,aAAa,EAAE,SAAS;aACzB;SACF;KACF;IACD,iBAAiB,EAAE,CAAC,QAAQ,EAAE,MAAM,EAAE,MAAM,EAAE,CAAC,MAAM,EAAE,EAAE,IAAI,EAAE,cAAc,EAAE,CAAC,EAAE,cAAc,CAAC;IACjG,mBAAmB,EAAE,CAAC,iBAAiB,EAAE,oBAAoB,CAAC;IAC9D,iBAAiB,EAAE;QACjB,MAAM,EAAE;YACN,QAAQ,EAAE,EAAE;YACZ,SAAS,EAAE,EAAE;YACb,KAAK,EAAE,EAAE;YACT,UAAU,EAAE,EAAE;SACf;KACF;CACF,CAAA;AACD,eAAe,MAAM,CAAA"}
|
package/dist/package.json
CHANGED
|
@@ -1,27 +1,27 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@creator.co/wapi",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "2.0.0-alpha.1",
|
|
4
4
|
"description": "",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"types": "dist/index.d.ts",
|
|
7
|
-
"type": "
|
|
7
|
+
"type": "module",
|
|
8
8
|
"scripts": {
|
|
9
9
|
"build": "tsc --build",
|
|
10
10
|
"clean": "tsc --build --clean",
|
|
11
11
|
"lint-fix": "eslint . --ext .ts --fix",
|
|
12
12
|
"lint": "eslint . --ext .ts",
|
|
13
|
-
"test": "jest --coverage --silent --runInBand && cat coverage/coverage.txt",
|
|
13
|
+
"test": "jest --coverage --silent --runInBand --logHeapUsage && cat coverage/coverage.txt",
|
|
14
14
|
"test-dev": "jest --coverage --runInBand && cat coverage/coverage.txt"
|
|
15
15
|
},
|
|
16
16
|
"author": "",
|
|
17
17
|
"license": "ISC",
|
|
18
18
|
"dependencies": {
|
|
19
|
-
"@aws-sdk/client-kms": "^3.
|
|
20
|
-
"@aws-sdk/client-secrets-manager": "
|
|
21
|
-
"@aws-sdk/client-ses": "
|
|
22
|
-
"@aws-sdk/client-sns": "
|
|
23
|
-
"@aws-sdk/client-ssm": "
|
|
24
|
-
"@aws-sdk/credential-provider-node": "
|
|
19
|
+
"@aws-sdk/client-kms": "^3.556.0",
|
|
20
|
+
"@aws-sdk/client-secrets-manager": "3.556",
|
|
21
|
+
"@aws-sdk/client-ses": "3.556",
|
|
22
|
+
"@aws-sdk/client-sns": "3.556",
|
|
23
|
+
"@aws-sdk/client-ssm": "3.556",
|
|
24
|
+
"@aws-sdk/credential-provider-node": "3.556",
|
|
25
25
|
"@types/email-templates": "^10.0.1",
|
|
26
26
|
"@types/nodemailer": "^6.4.10",
|
|
27
27
|
"@types/object-hash": "^3.0.4",
|
|
@@ -39,12 +39,12 @@
|
|
|
39
39
|
"node-cache": "^5.1.2",
|
|
40
40
|
"object-hash": "^3.0.0",
|
|
41
41
|
"parse-duration": "^1.1.0",
|
|
42
|
-
"path-to-regexp": "^6.2.
|
|
42
|
+
"path-to-regexp": "^6.2.2",
|
|
43
43
|
"pg": "^8.11.3",
|
|
44
44
|
"redis": "^4.6.13",
|
|
45
45
|
"sha1": "^1.1.1",
|
|
46
46
|
"stack-trace": "0.0.10",
|
|
47
|
-
"zod": "^3.
|
|
47
|
+
"zod": "^3.23.0"
|
|
48
48
|
},
|
|
49
49
|
"devDependencies": {
|
|
50
50
|
"@jest/globals": "^29.7.0",
|
|
@@ -62,7 +62,7 @@
|
|
|
62
62
|
"@typescript-eslint/parser": "^6.21.0",
|
|
63
63
|
"aws-lambda": "^1.0.7",
|
|
64
64
|
"aws-sdk-client-mock": "^3.0.0",
|
|
65
|
-
"chai": "^4.
|
|
65
|
+
"chai": "^4.4.1",
|
|
66
66
|
"eslint": "^8.48.0",
|
|
67
67
|
"eslint-config-prettier": "^9.0.0",
|
|
68
68
|
"eslint-plugin-import": "^2.28.1",
|
package/dist/src/API/Request.js
CHANGED
|
@@ -1,7 +1,4 @@
|
|
|
1
|
-
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.HttpMethod = void 0;
|
|
4
|
-
var Utils_1 = require("../Util/Utils");
|
|
1
|
+
import Utils from '../Util/Utils';
|
|
5
2
|
/**
|
|
6
3
|
* Represents a request object with generic types for input, query parameters, and path parameters.
|
|
7
4
|
* @class Request
|
|
@@ -9,7 +6,7 @@ var Utils_1 = require("../Util/Utils");
|
|
|
9
6
|
* @template PathParamsType - The type of the path parameters for the request.
|
|
10
7
|
* @template QueryParamsType - The type of the query parameters for the request.
|
|
11
8
|
*/
|
|
12
|
-
|
|
9
|
+
export default class Request {
|
|
13
10
|
/**
|
|
14
11
|
* Constructs a new instance of the class.
|
|
15
12
|
* @param {APIGatewayEvent} requestEvent - The API Gateway event object.
|
|
@@ -17,7 +14,7 @@ var Request = /** @class */ (function () {
|
|
|
17
14
|
* @param {Logger} logger - The logger object.
|
|
18
15
|
* @returns None
|
|
19
16
|
*/
|
|
20
|
-
|
|
17
|
+
constructor(requestEvent, context, logger) {
|
|
21
18
|
this.requestEvent = requestEvent;
|
|
22
19
|
this.context = context;
|
|
23
20
|
logger.debug('Request info:', requestEvent);
|
|
@@ -28,59 +25,59 @@ var Request = /** @class */ (function () {
|
|
|
28
25
|
* @param {keyof QueryParamsType} paramName - The name of the query parameter to check.
|
|
29
26
|
* @returns {boolean} - True if the query parameter exists and has a valid value, false otherwise.
|
|
30
27
|
*/
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
return !!val && (
|
|
34
|
-
}
|
|
28
|
+
containsQueryParam(paramName) {
|
|
29
|
+
const val = this.getQueryParam(paramName);
|
|
30
|
+
return !!val && (Utils.isValidString(val) || Utils.isValidNumber(val));
|
|
31
|
+
}
|
|
35
32
|
/**
|
|
36
33
|
* Retrieves the value of a query parameter from the URL.
|
|
37
34
|
* @param {keyof QueryParamsType} paramName - The name of the query parameter to retrieve.
|
|
38
35
|
* @returns {string | null} The value of the query parameter, or null if it does not exist.
|
|
39
36
|
*/
|
|
40
|
-
|
|
41
|
-
return
|
|
42
|
-
}
|
|
37
|
+
getQueryParam(paramName) {
|
|
38
|
+
return Utils.caseInsensitiveObjectForKey(this.requestEvent.queryStringParameters, String(paramName));
|
|
39
|
+
}
|
|
43
40
|
/**
|
|
44
41
|
* Retrieves the value of the specified header from the request event headers.
|
|
45
42
|
* @param {string} headerName - The name of the header to retrieve.
|
|
46
43
|
* @returns {string | null} - The value of the header, or null if the header is not found.
|
|
47
44
|
*/
|
|
48
|
-
|
|
49
|
-
return
|
|
50
|
-
}
|
|
45
|
+
getHeader(headerName) {
|
|
46
|
+
return Utils.caseInsensitiveObjectForKey(this.requestEvent.headers, headerName);
|
|
47
|
+
}
|
|
51
48
|
/**
|
|
52
49
|
* Retrieves the value of a context parameter from the request context object.
|
|
53
50
|
* @param {string} cxtParam - The name of the context parameter to retrieve.
|
|
54
51
|
* @returns The value of the context parameter, or null if it does not exist.
|
|
55
52
|
*/
|
|
56
|
-
|
|
57
|
-
return
|
|
58
|
-
}
|
|
53
|
+
getContextParam(cxtParam) {
|
|
54
|
+
return Utils.caseInsensitiveObjectForKey(this.requestEvent.requestContext, cxtParam);
|
|
55
|
+
}
|
|
59
56
|
/**
|
|
60
57
|
* Checks if the given parameter name exists in the PathParamsType object.
|
|
61
58
|
* @param {keyof PathParamsType} paramName - The name of the parameter to check.
|
|
62
59
|
* @returns {boolean} - True if the parameter exists, false otherwise.
|
|
63
60
|
*/
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
return !!val && (
|
|
67
|
-
}
|
|
61
|
+
containsPathParam(paramName) {
|
|
62
|
+
const val = this.getPathParam(paramName);
|
|
63
|
+
return !!val && (Utils.isValidString(val) || Utils.isValidNumber(val));
|
|
64
|
+
}
|
|
68
65
|
/**
|
|
69
66
|
* Retrieves the value of a specific path parameter from the URL.
|
|
70
67
|
* @param {keyof PathParamsType} paramName - The name of the path parameter to retrieve.
|
|
71
68
|
* @returns {string} The value of the path parameter, or null if it does not exist.
|
|
72
69
|
*/
|
|
73
|
-
|
|
74
|
-
return
|
|
75
|
-
}
|
|
70
|
+
getPathParam(paramName) {
|
|
71
|
+
return Utils.caseInsensitiveObjectForKey(this.requestEvent.pathParameters, String(paramName));
|
|
72
|
+
}
|
|
76
73
|
/**
|
|
77
74
|
* Retrieves the body of the request event and parses it if it is a string.
|
|
78
75
|
* @returns {InputType} The parsed body of the request event.
|
|
79
76
|
*/
|
|
80
|
-
|
|
81
|
-
|
|
77
|
+
getBody(raw) {
|
|
78
|
+
const body = this.requestEvent.body;
|
|
82
79
|
if (raw)
|
|
83
|
-
return
|
|
80
|
+
return Utils.isHybridlessContainer() ? this.requestEvent['rawBody'] : body;
|
|
84
81
|
if (typeof body === 'string' || body instanceof String) {
|
|
85
82
|
try {
|
|
86
83
|
return JSON.parse(body);
|
|
@@ -90,92 +87,89 @@ var Request = /** @class */ (function () {
|
|
|
90
87
|
}
|
|
91
88
|
}
|
|
92
89
|
return body;
|
|
93
|
-
}
|
|
90
|
+
}
|
|
94
91
|
/**
|
|
95
92
|
* Retrieves the path from the request event.
|
|
96
93
|
* @returns {string} The path of the request event.
|
|
97
94
|
*/
|
|
98
|
-
|
|
95
|
+
getPath() {
|
|
99
96
|
return this.requestEvent.path;
|
|
100
|
-
}
|
|
97
|
+
}
|
|
101
98
|
/**
|
|
102
99
|
* Retrieves the HTTP method of the current request.
|
|
103
100
|
* @returns {string} The HTTP method of the request.
|
|
104
101
|
*/
|
|
105
|
-
|
|
102
|
+
getMethod() {
|
|
106
103
|
if (this.requestEvent.httpMethod) {
|
|
107
|
-
|
|
104
|
+
const httpMethod = this.requestEvent.httpMethod.toUpperCase();
|
|
108
105
|
if (httpMethod in HttpMethod) {
|
|
109
106
|
return HttpMethod[httpMethod];
|
|
110
107
|
}
|
|
111
108
|
}
|
|
112
|
-
throw new Error(
|
|
113
|
-
}
|
|
109
|
+
throw new Error(`Invalid HTTP method: ${this.requestEvent.httpMethod}`);
|
|
110
|
+
}
|
|
114
111
|
/**
|
|
115
112
|
* Retrieves the path parameters from the request event.
|
|
116
113
|
* @returns {PathParamsType | null} - The path parameters object, or null if not found.
|
|
117
114
|
*/
|
|
118
|
-
|
|
115
|
+
getPathParams() {
|
|
119
116
|
// type conversion guaranteed by validation
|
|
120
117
|
return this.requestEvent.pathParameters;
|
|
121
|
-
}
|
|
118
|
+
}
|
|
122
119
|
/**
|
|
123
120
|
* Retrieves the query parameters from the request event.
|
|
124
121
|
* @returns {QueryParamsType | null} - The query parameters object, or null if not found.
|
|
125
122
|
*/
|
|
126
|
-
|
|
123
|
+
getQueryParams() {
|
|
127
124
|
// type conversion guaranteed by validation
|
|
128
125
|
return this.requestEvent.queryStringParameters;
|
|
129
|
-
}
|
|
126
|
+
}
|
|
130
127
|
/**
|
|
131
128
|
* Retrieves the value of the 'Authorization' header from the request.
|
|
132
129
|
* @returns The value of the 'Authorization' header, or null if it is not present.
|
|
133
130
|
*/
|
|
134
|
-
|
|
131
|
+
getAuthorizationHeader() {
|
|
135
132
|
return this.getHeader('Authorization');
|
|
136
|
-
}
|
|
133
|
+
}
|
|
137
134
|
/**
|
|
138
135
|
* Retrieves the request ID associated with the current execution context.
|
|
139
136
|
* @returns {string} The request ID.
|
|
140
137
|
*/
|
|
141
|
-
|
|
138
|
+
getRequestID() {
|
|
142
139
|
if (this.context.awsRequestId)
|
|
143
140
|
return this.context.awsRequestId;
|
|
144
141
|
return this.requestEvent.requestContext ? this.requestEvent.requestContext.requestId : 'unknown';
|
|
145
|
-
}
|
|
142
|
+
}
|
|
146
143
|
/**
|
|
147
144
|
* Retrieves the origin IP address of the request.
|
|
148
145
|
* @returns {string} The origin IP address. If the IP address is not available, it returns 'unknown'.
|
|
149
146
|
*/
|
|
150
|
-
|
|
147
|
+
getOriginIP() {
|
|
151
148
|
var _a;
|
|
152
|
-
|
|
153
|
-
|
|
149
|
+
const origin = (_a = this.getContextParam('identity')) === null || _a === void 0 ? void 0 : _a.sourceIp;
|
|
150
|
+
const hOrigin = this.getHeader('X-Forwarded-For');
|
|
154
151
|
return origin ? origin : hOrigin ? hOrigin : 'unknown';
|
|
155
|
-
}
|
|
152
|
+
}
|
|
156
153
|
/**
|
|
157
154
|
* Sets the fixed path parameters in the request event object.
|
|
158
155
|
* @param {any[]} keys - An array of keys representing the path parameter names.
|
|
159
156
|
* @param {any[]} result - An array of values representing the path parameter values.
|
|
160
157
|
* @returns None
|
|
161
158
|
*/
|
|
162
|
-
|
|
163
|
-
var _this = this;
|
|
159
|
+
setFixedPathParams(keys, result) {
|
|
164
160
|
this.requestEvent.pathParameters = {};
|
|
165
|
-
keys.forEach(
|
|
161
|
+
keys.forEach((key, index) => {
|
|
166
162
|
var _a;
|
|
167
|
-
if ((_a =
|
|
168
|
-
|
|
163
|
+
if ((_a = this.requestEvent) === null || _a === void 0 ? void 0 : _a.pathParameters) {
|
|
164
|
+
this.requestEvent.pathParameters[key.name] = result[index + 1];
|
|
169
165
|
}
|
|
170
166
|
});
|
|
171
|
-
}
|
|
172
|
-
|
|
173
|
-
}());
|
|
174
|
-
exports.default = Request;
|
|
167
|
+
}
|
|
168
|
+
}
|
|
175
169
|
/**
|
|
176
170
|
* Enum representing the HTTP methods.
|
|
177
171
|
*/
|
|
178
|
-
var HttpMethod;
|
|
172
|
+
export var HttpMethod;
|
|
179
173
|
(function (HttpMethod) {
|
|
180
174
|
HttpMethod["GET"] = "GET";
|
|
181
175
|
HttpMethod["HEAD"] = "HEAD";
|
|
@@ -186,5 +180,5 @@ var HttpMethod;
|
|
|
186
180
|
HttpMethod["OPTIONS"] = "OPTIONS";
|
|
187
181
|
HttpMethod["TRACE"] = "TRACE";
|
|
188
182
|
HttpMethod["PATCH"] = "PATCH";
|
|
189
|
-
})(HttpMethod || (
|
|
183
|
+
})(HttpMethod || (HttpMethod = {}));
|
|
190
184
|
//# sourceMappingURL=Request.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Request.js","sourceRoot":"","sources":["../../../src/API/Request.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"Request.js","sourceRoot":"","sources":["../../../src/API/Request.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,MAAM,eAAe,CAAA;AAEjC;;;;;;GAMG;AACH,MAAM,CAAC,OAAO,OAAO,OAAO;IAW1B;;;;;;OAMG;IACH,YAAY,YAA6B,EAAE,OAAgB,EAAE,MAAc;QACzE,IAAI,CAAC,YAAY,GAAG,YAAY,CAAA;QAChC,IAAI,CAAC,OAAO,GAAG,OAAO,CAAA;QACtB,MAAM,CAAC,KAAK,CAAC,eAAe,EAAE,YAAY,CAAC,CAAA;QAC3C,MAAM,CAAC,KAAK,CAAC,kBAAkB,EAAE,OAAO,CAAC,CAAA;IAC3C,CAAC;IAED;;;;OAIG;IACI,kBAAkB,CAAC,SAAgC;QACxD,MAAM,GAAG,GAAG,IAAI,CAAC,aAAa,CAAC,SAAS,CAAC,CAAA;QACzC,OAAO,CAAC,CAAC,GAAG,IAAI,CAAC,KAAK,CAAC,aAAa,CAAC,GAAG,CAAC,IAAI,KAAK,CAAC,aAAa,CAAC,GAAG,CAAC,CAAC,CAAA;IACxE,CAAC;IAED;;;;OAIG;IACI,aAAa,CAAC,SAAgC;QACnD,OAAO,KAAK,CAAC,2BAA2B,CACtC,IAAI,CAAC,YAAY,CAAC,qBAAqB,EACvC,MAAM,CAAC,SAAS,CAAC,CAClB,CAAA;IACH,CAAC;IAED;;;;OAIG;IACI,SAAS,CAAC,UAAkB;QACjC,OAAO,KAAK,CAAC,2BAA2B,CAAC,IAAI,CAAC,YAAY,CAAC,OAAO,EAAE,UAAU,CAAC,CAAA;IACjF,CAAC;IAED;;;;OAIG;IACI,eAAe,CAAC,QAAgB;QACrC,OAAO,KAAK,CAAC,2BAA2B,CAAC,IAAI,CAAC,YAAY,CAAC,cAAc,EAAE,QAAQ,CAAC,CAAA;IACtF,CAAC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