@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
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import Proxy from './container/Proxy.js';
|
|
2
|
+
import Server from './Server.js';
|
|
3
|
+
import { RouterConfig } from '../Router.js';
|
|
4
|
+
/**
|
|
5
|
+
* Represents a server container that extends the Server class and handles serverless events.
|
|
6
|
+
*/
|
|
7
|
+
export default class ContainerServer extends Server {
|
|
8
|
+
/**
|
|
9
|
+
* The proxy object used for handling requests and responses.
|
|
10
|
+
* @type {Proxy}
|
|
11
|
+
* @protected
|
|
12
|
+
*/
|
|
13
|
+
protected readonly proxy: Proxy;
|
|
14
|
+
/**
|
|
15
|
+
* Constructs a new instance of the Router class.
|
|
16
|
+
* @param {RouterConfig} config - The configuration object for the router.
|
|
17
|
+
* @returns None
|
|
18
|
+
*/
|
|
19
|
+
constructor(config: RouterConfig);
|
|
20
|
+
/**
|
|
21
|
+
* Returns a callable function that can be used to export data.
|
|
22
|
+
* @returns {CallableFunction} - A callable function that can be used to export data.
|
|
23
|
+
*/
|
|
24
|
+
getExport(): CallableFunction;
|
|
25
|
+
/**
|
|
26
|
+
* Starts the application by loading the proxy.
|
|
27
|
+
* @returns {Promise<void>} - A promise that resolves when the proxy is loaded.
|
|
28
|
+
*/
|
|
29
|
+
start(): Promise<void>;
|
|
30
|
+
/**
|
|
31
|
+
* Stops the execution of the program and unloads the proxy.
|
|
32
|
+
* @param {any} [err] - Optional error object to pass to the unload method.
|
|
33
|
+
* @returns {Promise<void>} - A promise that resolves once the proxy is unloaded.
|
|
34
|
+
*/
|
|
35
|
+
stop(err?: any): Promise<void>;
|
|
36
|
+
/**
|
|
37
|
+
* Listens for process events and handles them accordingly.
|
|
38
|
+
* @private
|
|
39
|
+
* @returns None
|
|
40
|
+
*/
|
|
41
|
+
private listenProcessEvents;
|
|
42
|
+
}
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
2
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
3
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
4
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
5
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
6
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
7
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
8
|
+
});
|
|
9
|
+
};
|
|
10
|
+
import Proxy from './container/Proxy.js';
|
|
11
|
+
import Server from './Server.js';
|
|
12
|
+
/**
|
|
13
|
+
* Represents a server container that extends the Server class and handles serverless events.
|
|
14
|
+
*/
|
|
15
|
+
export default class ContainerServer extends Server {
|
|
16
|
+
/**
|
|
17
|
+
* Constructs a new instance of the Router class.
|
|
18
|
+
* @param {RouterConfig} config - The configuration object for the router.
|
|
19
|
+
* @returns None
|
|
20
|
+
*/
|
|
21
|
+
constructor(config) {
|
|
22
|
+
super(config);
|
|
23
|
+
this.proxy = new Proxy(config, this.handleServerlessEvent.bind(this));
|
|
24
|
+
this.listenProcessEvents();
|
|
25
|
+
}
|
|
26
|
+
/**
|
|
27
|
+
* Returns a callable function that can be used to export data.
|
|
28
|
+
* @returns {CallableFunction} - A callable function that can be used to export data.
|
|
29
|
+
*/
|
|
30
|
+
getExport() {
|
|
31
|
+
// start server socket
|
|
32
|
+
this.start();
|
|
33
|
+
// return empty function, we are all done
|
|
34
|
+
return () => { };
|
|
35
|
+
}
|
|
36
|
+
/**
|
|
37
|
+
* Starts the application by loading the proxy.
|
|
38
|
+
* @returns {Promise<void>} - A promise that resolves when the proxy is loaded.
|
|
39
|
+
*/
|
|
40
|
+
start() {
|
|
41
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
42
|
+
yield this.proxy.load();
|
|
43
|
+
});
|
|
44
|
+
}
|
|
45
|
+
/**
|
|
46
|
+
* Stops the execution of the program and unloads the proxy.
|
|
47
|
+
* @param {any} [err] - Optional error object to pass to the unload method.
|
|
48
|
+
* @returns {Promise<void>} - A promise that resolves once the proxy is unloaded.
|
|
49
|
+
*/
|
|
50
|
+
stop(err) {
|
|
51
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
52
|
+
yield this.proxy.unload(err);
|
|
53
|
+
});
|
|
54
|
+
}
|
|
55
|
+
/**
|
|
56
|
+
* Listens for process events and handles them accordingly.
|
|
57
|
+
* @private
|
|
58
|
+
* @returns None
|
|
59
|
+
*/
|
|
60
|
+
listenProcessEvents() {
|
|
61
|
+
// start process listeners
|
|
62
|
+
process.on('unhandledRejection', this.stop.bind(this)); // listen to exceptions
|
|
63
|
+
process.on('SIGINT', this.stop.bind(this)); // listen on SIGINT signal and gracefully stop the server
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
//# sourceMappingURL=ContainerServer.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ContainerServer.js","sourceRoot":"","sources":["../../../../src/Server/lib/ContainerServer.ts"],"names":[],"mappings":";;;;;;;;;AAAA,OAAO,KAAK,MAAM,sBAAsB,CAAA;AACxC,OAAO,MAAM,MAAM,aAAa,CAAA;AAGhC;;GAEG;AACH,MAAM,CAAC,OAAO,OAAO,eAAgB,SAAQ,MAAM;IAQjD;;;;OAIG;IACH,YAAY,MAAoB;QAC9B,KAAK,CAAC,MAAM,CAAC,CAAA;QACb,IAAI,CAAC,KAAK,GAAG,IAAI,KAAK,CAAC,MAAM,EAAE,IAAI,CAAC,qBAAqB,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC,CAAA;QACrE,IAAI,CAAC,mBAAmB,EAAE,CAAA;IAC5B,CAAC;IAED;;;OAGG;IACI,SAAS;QACd,sBAAsB;QACtB,IAAI,CAAC,KAAK,EAAE,CAAA;QACZ,yCAAyC;QACzC,OAAO,GAAG,EAAE,GAAE,CAAC,CAAA;IACjB,CAAC;IAED;;;OAGG;IACU,KAAK;;YAChB,MAAM,IAAI,CAAC,KAAK,CAAC,IAAI,EAAE,CAAA;QACzB,CAAC;KAAA;IAED;;;;OAIG;IACU,IAAI,CAAC,GAAS;;YACzB,MAAM,IAAI,CAAC,KAAK,CAAC,MAAM,CAAC,GAAG,CAAC,CAAA;QAC9B,CAAC;KAAA;IAED;;;;OAIG;IACK,mBAAmB;QACzB,0BAA0B;QAC1B,OAAO,CAAC,EAAE,CAAC,oBAAoB,EAAE,IAAI,CAAC,IAAI,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC,CAAA,CAAC,uBAAuB;QAC9E,OAAO,CAAC,EAAE,CAAC,QAAQ,EAAE,IAAI,CAAC,IAAI,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC,CAAA,CAAC,yDAAyD;IACtG,CAAC;CACF"}
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import { APIGatewayProxyEvent, Context } from 'aws-lambda';
|
|
2
|
+
import { RouterConfig } from '../Router.js';
|
|
3
|
+
import RouteResolver from '../RouteResolver.js';
|
|
4
|
+
/**
|
|
5
|
+
* Represents a server that handles serverless events and routes them to appropriate handlers.
|
|
6
|
+
*/
|
|
7
|
+
export default class Server {
|
|
8
|
+
/**
|
|
9
|
+
* The configuration object for the router.
|
|
10
|
+
* @readonly
|
|
11
|
+
* @type {RouterConfig}
|
|
12
|
+
*/
|
|
13
|
+
protected readonly config: RouterConfig;
|
|
14
|
+
/**
|
|
15
|
+
* A protected property that holds a RouteResolver object.
|
|
16
|
+
* The RouteResolver is responsible for resolving routes and returning the appropriate response.
|
|
17
|
+
* @type {RouteResolver}
|
|
18
|
+
*/
|
|
19
|
+
protected readonly routeResolver: RouteResolver;
|
|
20
|
+
/**
|
|
21
|
+
* Constructs a new instance of the Router class.
|
|
22
|
+
* @param {RouterConfig} config - The configuration object for the router.
|
|
23
|
+
* @returns None
|
|
24
|
+
*/
|
|
25
|
+
constructor(config: RouterConfig);
|
|
26
|
+
/**
|
|
27
|
+
* Returns a callable function that is bound to the `handleServerlessEvent` method of the current object.
|
|
28
|
+
* @returns {CallableFunction} - A callable function that is bound to the `handleServerlessEvent` method.
|
|
29
|
+
*/
|
|
30
|
+
getExport(): CallableFunction;
|
|
31
|
+
/**
|
|
32
|
+
* Handles a serverless event by executing a transaction and resolving the route based on the event.
|
|
33
|
+
* @param {APIGatewayProxyEvent} event - The serverless event object.
|
|
34
|
+
* @param {Context} context - The serverless context object.
|
|
35
|
+
* @returns None
|
|
36
|
+
*/
|
|
37
|
+
handleServerlessEvent(event: APIGatewayProxyEvent, context: Context): Promise<void>;
|
|
38
|
+
/**
|
|
39
|
+
* Parses the path parameters from the request URL based on the given route path.
|
|
40
|
+
* @param {Request<any>} req - The request object.
|
|
41
|
+
* @param {string} routePath - The route path pattern to match against.
|
|
42
|
+
* @returns None
|
|
43
|
+
*/
|
|
44
|
+
private parsePathParams;
|
|
45
|
+
}
|
|
@@ -0,0 +1,93 @@
|
|
|
1
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
2
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
3
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
4
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
5
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
6
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
7
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
8
|
+
});
|
|
9
|
+
};
|
|
10
|
+
import { pathToRegexp } from 'path-to-regexp';
|
|
11
|
+
import Response from '../../API/Response.js';
|
|
12
|
+
import Transaction from '../../BaseEvent/Transaction.js';
|
|
13
|
+
import Validator from '../../Validation/Validator.js';
|
|
14
|
+
import RouteResolver from '../RouteResolver.js';
|
|
15
|
+
/**
|
|
16
|
+
* Represents a server that handles serverless events and routes them to appropriate handlers.
|
|
17
|
+
*/
|
|
18
|
+
export default class Server {
|
|
19
|
+
/**
|
|
20
|
+
* Constructs a new instance of the Router class.
|
|
21
|
+
* @param {RouterConfig} config - The configuration object for the router.
|
|
22
|
+
* @returns None
|
|
23
|
+
*/
|
|
24
|
+
constructor(config) {
|
|
25
|
+
this.config = config;
|
|
26
|
+
this.routeResolver = new RouteResolver(config);
|
|
27
|
+
}
|
|
28
|
+
/**
|
|
29
|
+
* Returns a callable function that is bound to the `handleServerlessEvent` method of the current object.
|
|
30
|
+
* @returns {CallableFunction} - A callable function that is bound to the `handleServerlessEvent` method.
|
|
31
|
+
*/
|
|
32
|
+
getExport() {
|
|
33
|
+
return this.handleServerlessEvent.bind(this);
|
|
34
|
+
}
|
|
35
|
+
/**
|
|
36
|
+
* Handles a serverless event by executing a transaction and resolving the route based on the event.
|
|
37
|
+
* @param {APIGatewayProxyEvent} event - The serverless event object.
|
|
38
|
+
* @param {Context} context - The serverless context object.
|
|
39
|
+
* @returns None
|
|
40
|
+
*/
|
|
41
|
+
handleServerlessEvent(event, context) {
|
|
42
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
43
|
+
// init transaction
|
|
44
|
+
yield new Transaction(event, context, this.config).execute((transaction) => __awaiter(this, void 0, void 0, function* () {
|
|
45
|
+
const request = transaction.request;
|
|
46
|
+
const route = this.routeResolver.resolveRoute(request.getMethod(), request.getPath());
|
|
47
|
+
if (route) {
|
|
48
|
+
transaction.logger.log('Router accepted route:', route.path);
|
|
49
|
+
// Validate input
|
|
50
|
+
if (route.inputSchema) {
|
|
51
|
+
const validationResp = Validator.validateSchema(request.getBody(), route.inputSchema);
|
|
52
|
+
if (validationResp && validationResp instanceof Response)
|
|
53
|
+
return validationResp;
|
|
54
|
+
}
|
|
55
|
+
// Validate query
|
|
56
|
+
if (route.querySchema) {
|
|
57
|
+
const validationResp = Validator.validateSchema(request.getQueryParams(), route.querySchema);
|
|
58
|
+
if (validationResp && validationResp instanceof Response)
|
|
59
|
+
return validationResp;
|
|
60
|
+
}
|
|
61
|
+
// parse before validating
|
|
62
|
+
for (const path of Array.isArray(route.path) ? route.path : [route.path]) {
|
|
63
|
+
this.parsePathParams(request, path);
|
|
64
|
+
}
|
|
65
|
+
// Validate path
|
|
66
|
+
if (route.pathSchema) {
|
|
67
|
+
const validationResp = Validator.validateSchema(request.getPathParams(), route.pathSchema);
|
|
68
|
+
if (validationResp && validationResp instanceof Response)
|
|
69
|
+
return validationResp;
|
|
70
|
+
}
|
|
71
|
+
// Continue to route handler
|
|
72
|
+
return yield route.handler(transaction);
|
|
73
|
+
}
|
|
74
|
+
//No route found :/
|
|
75
|
+
return new Response(404, { err: 'Route not found!' });
|
|
76
|
+
}));
|
|
77
|
+
});
|
|
78
|
+
}
|
|
79
|
+
/**
|
|
80
|
+
* Parses the path parameters from the request URL based on the given route path.
|
|
81
|
+
* @param {Request<any>} req - The request object.
|
|
82
|
+
* @param {string} routePath - The route path pattern to match against.
|
|
83
|
+
* @returns None
|
|
84
|
+
*/
|
|
85
|
+
parsePathParams(req, routePath) {
|
|
86
|
+
const path = req.getPath();
|
|
87
|
+
const regex = pathToRegexp(routePath);
|
|
88
|
+
const result = regex.exec(path);
|
|
89
|
+
if (result)
|
|
90
|
+
req.setFixedPathParams(regex.keys, result);
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
//# sourceMappingURL=Server.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Server.js","sourceRoot":"","sources":["../../../../src/Server/lib/Server.ts"],"names":[],"mappings":";;;;;;;;;AACA,OAAO,EAAE,YAAY,EAAE,MAAM,gBAAgB,CAAA;AAG7C,OAAO,QAA+B,MAAM,uBAAuB,CAAA;AACnE,OAAO,WAA0B,MAAM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C,CAAA;IACxD,CAAC;CACF"}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { Request, Response } from 'express';
|
|
2
|
+
import Server from '../Server.js';
|
|
3
|
+
/**
|
|
4
|
+
* Creates an async function that handles serverless events and sends a response.
|
|
5
|
+
* @param {Server['handleServerlessEvent']} serverlessHandler - The serverless handler function.
|
|
6
|
+
* @returns {Function} - An async function that handles the request and sends a response.
|
|
7
|
+
*/
|
|
8
|
+
declare const _default: (serverlessHandler: Server["handleServerlessEvent"]) => (request: Request, res: Response) => Promise<void>;
|
|
9
|
+
export default _default;
|
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
2
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
3
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
4
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
5
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
6
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
7
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
8
|
+
});
|
|
9
|
+
};
|
|
10
|
+
import GenericHandlerEvent from './GenericHandlerEvent.js';
|
|
11
|
+
import Globals from '../../../Globals.js';
|
|
12
|
+
import Utils from '../../../Util/Utils.js';
|
|
13
|
+
/**
|
|
14
|
+
* Creates an async function that handles serverless events and sends a response.
|
|
15
|
+
* @param {Server['handleServerlessEvent']} serverlessHandler - The serverless handler function.
|
|
16
|
+
* @returns {Function} - An async function that handles the request and sends a response.
|
|
17
|
+
*/
|
|
18
|
+
export default (serverlessHandler) => {
|
|
19
|
+
/**
|
|
20
|
+
* Handles an HTTP request by invoking a serverless function and processing the response.
|
|
21
|
+
* @param {Request} request - The HTTP request object.
|
|
22
|
+
* @param {Response} res - The HTTP response object.
|
|
23
|
+
* @returns None
|
|
24
|
+
*/
|
|
25
|
+
return (request, res) => __awaiter(void 0, void 0, void 0, function* () {
|
|
26
|
+
const startTime = Date.now();
|
|
27
|
+
try {
|
|
28
|
+
// Generate event with request stuff (http to serverless translation)
|
|
29
|
+
const event = new GenericHandlerEvent(request, serverlessHandler);
|
|
30
|
+
// Invoke
|
|
31
|
+
const invokationResp = yield event.invoke();
|
|
32
|
+
// Respond
|
|
33
|
+
processServerlessResponse(invokationResp, res);
|
|
34
|
+
}
|
|
35
|
+
catch (e) {
|
|
36
|
+
console.error('[Proxy] - Exception during execution!', e);
|
|
37
|
+
console.error(e.stack);
|
|
38
|
+
res.status(Globals.Resp_STATUSCODE_EXCEPTION).json(Object.assign(Object.assign({}, e), { err: Globals.Resp_MSG_EXCEPTION, errCode: Globals.Resp_CODE_EXCEPTION }));
|
|
39
|
+
}
|
|
40
|
+
console.debug(`[Proxy] - Request took ${Date.now() - startTime}ms`);
|
|
41
|
+
});
|
|
42
|
+
};
|
|
43
|
+
/**
|
|
44
|
+
* Processes the response received from a serverless function invocation and sends the appropriate response back to the client.
|
|
45
|
+
* @param {GenericHandlerEventResponse} invokation - The response object received from the serverless function invocation.
|
|
46
|
+
* @param {Response} res - The response object to send back to the client.
|
|
47
|
+
* @returns The response object to send back to the client.
|
|
48
|
+
*/
|
|
49
|
+
const processServerlessResponse = (invokation, res) => {
|
|
50
|
+
var _a, _b;
|
|
51
|
+
// translate answer to http layer
|
|
52
|
+
if (invokation && invokation.err) {
|
|
53
|
+
// err came
|
|
54
|
+
return res.json({ err: invokation.err }).status(400);
|
|
55
|
+
}
|
|
56
|
+
else if (!invokation || !invokation.data) {
|
|
57
|
+
// invalid response came
|
|
58
|
+
return res.status(Globals.Resp_STATUSCODE_INVALIDRESP).json({
|
|
59
|
+
err: Globals.Resp_MSG_INVALIDRESP,
|
|
60
|
+
errCode: Globals.Resp_CODE_INVALIDRESP,
|
|
61
|
+
});
|
|
62
|
+
}
|
|
63
|
+
else {
|
|
64
|
+
// Check for headers
|
|
65
|
+
if (invokation.data.headers) {
|
|
66
|
+
for (const hKey of Object.keys(invokation.data.headers)) {
|
|
67
|
+
res.header(hKey, invokation.data.headers[hKey]);
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
//
|
|
71
|
+
let response = res.status(invokation.data.statusCode);
|
|
72
|
+
// check for stream
|
|
73
|
+
if ((_b = (_a = invokation.data) === null || _a === void 0 ? void 0 : _a.body) === null || _b === void 0 ? void 0 : _b.pipe) {
|
|
74
|
+
invokation.data.body.pipe(response);
|
|
75
|
+
}
|
|
76
|
+
else {
|
|
77
|
+
response = response.json(Utils.parseObjectNullIfEmpty(invokation.data.body) || {});
|
|
78
|
+
}
|
|
79
|
+
return response;
|
|
80
|
+
}
|
|
81
|
+
};
|
|
82
|
+
//# sourceMappingURL=GenericHandler.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"GenericHandler.js","sourceRoot":"","sources":["../../../../../src/Server/lib/container/GenericHandler.ts"],"names":[],"mappings":";;;;;;;;;AAEA,OAAO,mBAAoD,MAAM,0BAA0B,CAAA;AAC3F,OAAO,OAAO,MAAM,qBAAqB,CAAA;AACzC,OAAO,KAAK,MAAM,wBAAwB,CAAA;AAG1C;;;;GAIG;AACH,eAAe,CAAC,iBAAkD,EAAE,EAAE;IACpE;;;;;OAKG;IACH,OAAO,CAAO,OAAgB,EAAE,GAAa,EAAE,EAAE;QAC/C,MAAM,SAAS,GAAG,IAAI,CAAC,GAAG,EAAE,CAAA;QAC5B,IAAI,CAAC;YACH,qEAAqE;YACrE,MAAM,KAAK,GAAG,IAAI,mBAAmB,CAAC,OAAO,EAAE,iBAAiB,CAAC,CAAA;YACjE,SAAS;YACT,MAAM,cAAc,GAAG,MAAM,KAAK,CAAC,MAAM,EAAE,CAAA;YAC3C,UAAU;YACV,yBAAyB,CAAC,cAAc,EAAE,GAAG,CAAC,CAAA;QAChD,CAAC;QAAC,OAAO,CAAC,EAA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AAE,UAAU,CAAC,IAAI,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC,CAAA;YACjD,CAAC;QACH,CAAC;QACD,EAAE;QACF,IAAI,QAAQ,GAAG,GAAG,CAAC,MAAM,CAAC,UAAU,CAAC,IAAI,CAAC,UAAU,CAAC,CAAA;QACrD,mBAAmB;QACnB,IAAI,MAAA,MAAA,UAAU,CAAC,IAAI,0CAAE,IAAI,0CAAE,IAAI,EAAE,CAAC;YAChC,UAAU,CAAC,IAAI,CAAC,IAAI,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAA;QACrC,CAAC;aAAM,CAAC;YACN,QAAQ,GAAG,QAAQ,CAAC,IAAI,CAAC,KAAK,CAAC,sBAAsB,CAAC,UAAU,CAAC,IAAI,CAAC,IAAI,CAAC,IAAI,EAAE,CAAC,CAAA;QACpF,CAAC;QACD,OAAO,QAAQ,CAAA;IACjB,CAAC;AACH,CAAC,CAAA"}
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
import { Request } from 'express';
|
|
2
|
+
import Server from '../Server.js';
|
|
3
|
+
/**
|
|
4
|
+
* Represents the response object returned by a generic event handler.
|
|
5
|
+
* @typedef {Object} GenericHandlerEventResponse
|
|
6
|
+
* @property {Error | string} [err] - An optional error object or error message.
|
|
7
|
+
* @property {*} [data] - An optional data object.
|
|
8
|
+
*/
|
|
9
|
+
export type GenericHandlerEventResponse = {
|
|
10
|
+
err?: Error | string;
|
|
11
|
+
data?: any;
|
|
12
|
+
};
|
|
13
|
+
/**
|
|
14
|
+
* Represents a generic handler event for serverless functions.
|
|
15
|
+
*/
|
|
16
|
+
export default class GenericHandlerEvent {
|
|
17
|
+
/**
|
|
18
|
+
* Represents an HTTP request.
|
|
19
|
+
* @property {Request} request - The HTTP request object.
|
|
20
|
+
*/
|
|
21
|
+
request: Request;
|
|
22
|
+
/**
|
|
23
|
+
* The handler function for serverless events in a server.
|
|
24
|
+
* @param {Server['handleServerlessEvent']} serverlessHandler - The function that handles serverless events.
|
|
25
|
+
* @returns None
|
|
26
|
+
*/
|
|
27
|
+
serverlessHandler: Server['handleServerlessEvent'];
|
|
28
|
+
/**
|
|
29
|
+
* Constructs a new instance of the class.
|
|
30
|
+
* @param {Request} request - The request object.
|
|
31
|
+
* @param {Server['handleServerlessEvent']} serverlessHandler - The serverless handler function.
|
|
32
|
+
* @returns None
|
|
33
|
+
*/
|
|
34
|
+
constructor(request: Request, serverlessHandler: Server['handleServerlessEvent']);
|
|
35
|
+
/**
|
|
36
|
+
* Invokes the handler function asynchronously and returns a promise that resolves to a GenericHandlerEventResponse.
|
|
37
|
+
* @returns {Promise<GenericHandlerEventResponse>} A promise that resolves to a GenericHandlerEventResponse.
|
|
38
|
+
*/
|
|
39
|
+
invoke(): Promise<GenericHandlerEventResponse>;
|
|
40
|
+
/**
|
|
41
|
+
* Builds and returns an APIGatewayProxyEvent object based on the current request.
|
|
42
|
+
* @returns {APIGatewayProxyEvent} - The constructed APIGatewayProxyEvent object.
|
|
43
|
+
*/
|
|
44
|
+
private buildEvent;
|
|
45
|
+
/**
|
|
46
|
+
* Builds and returns a context object for an AWS Lambda function.
|
|
47
|
+
* @param {APIGatewayProxyEvent} event - The event object passed to the Lambda function.
|
|
48
|
+
* @param {(err?: Error | string, data?: any) => void} callback - The callback function to be called when the Lambda function completes.
|
|
49
|
+
* @returns {Context} - The context object for the Lambda function.
|
|
50
|
+
*/
|
|
51
|
+
private buildContext;
|
|
52
|
+
}
|
|
@@ -0,0 +1,132 @@
|
|
|
1
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
2
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
3
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
4
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
5
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
6
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
7
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
8
|
+
});
|
|
9
|
+
};
|
|
10
|
+
import cuid from 'cuid';
|
|
11
|
+
import { parseMultiValueQueryStringParameters, parseQueryStringParameters } from './Utils.js';
|
|
12
|
+
import Globals from '../../../Globals.js';
|
|
13
|
+
/**
|
|
14
|
+
* Represents a generic handler event for serverless functions.
|
|
15
|
+
*/
|
|
16
|
+
export default class GenericHandlerEvent {
|
|
17
|
+
/**
|
|
18
|
+
* Constructs a new instance of the class.
|
|
19
|
+
* @param {Request} request - The request object.
|
|
20
|
+
* @param {Server['handleServerlessEvent']} serverlessHandler - The serverless handler function.
|
|
21
|
+
* @returns None
|
|
22
|
+
*/
|
|
23
|
+
constructor(request, serverlessHandler) {
|
|
24
|
+
this.request = request;
|
|
25
|
+
this.serverlessHandler = serverlessHandler;
|
|
26
|
+
}
|
|
27
|
+
/**
|
|
28
|
+
* Invokes the handler function asynchronously and returns a promise that resolves to a GenericHandlerEventResponse.
|
|
29
|
+
* @returns {Promise<GenericHandlerEventResponse>} A promise that resolves to a GenericHandlerEventResponse.
|
|
30
|
+
*/
|
|
31
|
+
invoke() {
|
|
32
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
33
|
+
// eslint-disable-next-line no-async-promise-executor
|
|
34
|
+
return new Promise((resolve, reject) => __awaiter(this, void 0, void 0, function* () {
|
|
35
|
+
try {
|
|
36
|
+
// Build event and context
|
|
37
|
+
const event = this.buildEvent();
|
|
38
|
+
const context = this.buildContext(event, (err, data) => {
|
|
39
|
+
resolve({ err, data });
|
|
40
|
+
});
|
|
41
|
+
// Invoke
|
|
42
|
+
yield this.serverlessHandler(event, context);
|
|
43
|
+
}
|
|
44
|
+
catch (e) {
|
|
45
|
+
reject(e); // forward rejection
|
|
46
|
+
}
|
|
47
|
+
}));
|
|
48
|
+
});
|
|
49
|
+
}
|
|
50
|
+
/**
|
|
51
|
+
* Builds and returns an APIGatewayProxyEvent object based on the current request.
|
|
52
|
+
* @returns {APIGatewayProxyEvent} - The constructed APIGatewayProxyEvent object.
|
|
53
|
+
*/
|
|
54
|
+
buildEvent() {
|
|
55
|
+
var _a, _b, _c, _d;
|
|
56
|
+
return {
|
|
57
|
+
body: this.request.body || null, //enforce key
|
|
58
|
+
rawBody: this.request['rawBody'],
|
|
59
|
+
headers: (this.request.headers || {}),
|
|
60
|
+
httpMethod: (_a = this.request.method) === null || _a === void 0 ? void 0 : _a.toUpperCase(),
|
|
61
|
+
isBase64Encoded: false,
|
|
62
|
+
multiValueHeaders: (this.request.headers || {}),
|
|
63
|
+
multiValueQueryStringParameters: parseMultiValueQueryStringParameters(this.request.url),
|
|
64
|
+
path: this.request.path,
|
|
65
|
+
pathParameters: null,
|
|
66
|
+
queryStringParameters: this.request.url ? parseQueryStringParameters(this.request.url) : {},
|
|
67
|
+
requestContext: {
|
|
68
|
+
accountId: process.env.AWS_ACCOUNT_ID || 'undefined',
|
|
69
|
+
apiId: '',
|
|
70
|
+
authorizer: null,
|
|
71
|
+
domainName: undefined,
|
|
72
|
+
domainPrefix: undefined,
|
|
73
|
+
extendedRequestId: cuid(),
|
|
74
|
+
httpMethod: this.request.method ? this.request.method.toUpperCase() : '',
|
|
75
|
+
identity: {
|
|
76
|
+
accessKey: null,
|
|
77
|
+
accountId: process.env.AWS_ACCOUNT_ID || null,
|
|
78
|
+
caller: null,
|
|
79
|
+
apiKey: null,
|
|
80
|
+
apiKeyId: null,
|
|
81
|
+
clientCert: null,
|
|
82
|
+
cognitoAuthenticationProvider: null,
|
|
83
|
+
cognitoAuthenticationType: null,
|
|
84
|
+
cognitoIdentityId: null,
|
|
85
|
+
cognitoIdentityPoolId: null,
|
|
86
|
+
principalOrgId: null,
|
|
87
|
+
sourceIp: ((_b = this.request.headers) === null || _b === void 0 ? void 0 : _b['x-forwarded-for']) ||
|
|
88
|
+
((_c = this.request.socket) === null || _c === void 0 ? void 0 : _c.remoteAddress) ||
|
|
89
|
+
'',
|
|
90
|
+
user: null,
|
|
91
|
+
userAgent: ((_d = this.request.headers) === null || _d === void 0 ? void 0 : _d['user-agent']) || null,
|
|
92
|
+
userArn: null,
|
|
93
|
+
},
|
|
94
|
+
path: this.request.path,
|
|
95
|
+
protocol: 'HTTP/1.1',
|
|
96
|
+
requestId: `${cuid()}-${cuid()}`,
|
|
97
|
+
requestTime: new Date().toISOString(),
|
|
98
|
+
requestTimeEpoch: Date.now(),
|
|
99
|
+
resourceId: '',
|
|
100
|
+
resourcePath: Globals.Listener_HTTP_ProxyRoute,
|
|
101
|
+
stage: process.env.STAGE || '',
|
|
102
|
+
},
|
|
103
|
+
resource: Globals.Listener_HTTP_ProxyRoute,
|
|
104
|
+
stageVariables: null,
|
|
105
|
+
};
|
|
106
|
+
}
|
|
107
|
+
/**
|
|
108
|
+
* Builds and returns a context object for an AWS Lambda function.
|
|
109
|
+
* @param {APIGatewayProxyEvent} event - The event object passed to the Lambda function.
|
|
110
|
+
* @param {(err?: Error | string, data?: any) => void} callback - The callback function to be called when the Lambda function completes.
|
|
111
|
+
* @returns {Context} - The context object for the Lambda function.
|
|
112
|
+
*/
|
|
113
|
+
buildContext(event, callback) {
|
|
114
|
+
return {
|
|
115
|
+
awsRequestId: event.requestContext.requestId,
|
|
116
|
+
callbackWaitsForEmptyEventLoop: true,
|
|
117
|
+
getRemainingTimeInMillis: () => {
|
|
118
|
+
return 0;
|
|
119
|
+
},
|
|
120
|
+
done: (err, data) => callback(err, data),
|
|
121
|
+
fail: err => callback(err),
|
|
122
|
+
succeed: res => callback(undefined, res),
|
|
123
|
+
functionName: 'container-function',
|
|
124
|
+
functionVersion: 'LATEST',
|
|
125
|
+
invokedFunctionArn: 'none',
|
|
126
|
+
memoryLimitInMB: '-1',
|
|
127
|
+
logGroupName: 'undefined',
|
|
128
|
+
logStreamName: 'undefined',
|
|
129
|
+
};
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
//# sourceMappingURL=GenericHandlerEvent.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"GenericHandlerEvent.js","sourceRoot":"","sources":["../../../../../src/Server/lib/container/GenericHandlerEvent.ts"],"names":[],"mappings":";;;;;;;;;AACA,OAAO,IAAI,MAAM,MAAM,CAAA;AAGvB,OAAO,EAAE,oCAAoC,EAAE,0BAA0B,EAAE,MAAM,YAAY,CAAA;AAC7F,OAAO,OAAO,MAAM,qBAAqB,CAAA;AAezC;;GAEG;AACH,MAAM,CAAC,OAAO,OAAO,mBAAmB;IAatC;;;;;OAKG;IACH,YAAY,OAAgB,EAAE,iBAAkD;QAC9E,IAAI,CAAC,OAAO,GAAG,OAAO,CAAA;QACtB,IAAI,CAAC,iBAAiB,GAAG,iBAAiB,CAAA;IAC5C,CAAC;IAED;;;OAGG;IACU,MAAM;;YACjB,qDAAqD;YACrD,OAAO,IAAI,OAAO,CAAC,CAAO,OAAO,EAAE,MAAM,EAAE,EAAE;gBAC3C,IAAI,CAAC;oBACH,0BAA0B;oBAC1B,MAAM,KAAK,GAAG,IAAI,CAAC,UAAU,EAAE,CAAA;oBAC/B,MAAM,OAAO,GAAG,IAAI,CAAC,YAAY,CAAC,KAAK,EAAE,CAAC,GAAoB,EAAE,IAAU,EAAE,EAAE;wBAC5E,OAAO,CAAC,EAAE,GAAG,EAAE,IAAI,EAAE,CAAC,CAAA;oBACxB,CAAC,CAAC,CAAA;oBACF,SAAS;oBACT,MAAM,IAAI,CAAC,iBAAiB,CAAC,KAAK,EAAE,OAAO,CAAC,CAAA;gBAC9C,CAAC;gBAAC,OAAO,CAAC,EAAE,CAAC;oBACX,MAAM,CAAC,CAAC,CAAC,CAAA,CAAC,oBAAoB;gBAChC,CAAC;YACH,CAAC,CAAA,CAAC,CAAA;QACJ,CAAC;KAAA;IAED;;;OAGG;IACK,UAAU;;QAChB,OAAO;YACL,IAAI,EAAE,IAAI,CAAC,OAAO,CAAC,IAAI,IAAI,IAAI,EAAE,aAAa;YAC9C,OAAO,EA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AAC,SAAS,EAAE,GAAG,CAAC;YACxC,YAAY,EAAE,oBAAoB;YAClC,eAAe,EAAE,QAAQ;YACzB,kBAAkB,EAAE,MAAM;YAC1B,eAAe,EAAE,IAAI;YACrB,YAAY,EAAE,WAAW;YACzB,aAAa,EAAE,WAAW;SAC3B,CAAA;IACH,CAAC;CACF"}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { Request, Response } from 'express';
|
|
2
|
+
/**
|
|
3
|
+
* Handles a request and sends a response with the message 'Healthy!'.
|
|
4
|
+
* @param {Request} _request - The request object.
|
|
5
|
+
* @param {Response} res - The response object.
|
|
6
|
+
* @returns None
|
|
7
|
+
*/
|
|
8
|
+
declare const _default: (_request: Request, res: Response) => Promise<void>;
|
|
9
|
+
export default _default;
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
2
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
3
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
4
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
5
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
6
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
7
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
8
|
+
});
|
|
9
|
+
};
|
|
10
|
+
/**
|
|
11
|
+
* Handles a request and sends a response with the message 'Healthy!'.
|
|
12
|
+
* @param {Request} _request - The request object.
|
|
13
|
+
* @param {Response} res - The response object.
|
|
14
|
+
* @returns None
|
|
15
|
+
*/
|
|
16
|
+
export default (_request, res) => __awaiter(void 0, void 0, void 0, function* () {
|
|
17
|
+
res.send('Healthy!');
|
|
18
|
+
});
|
|
19
|
+
//# sourceMappingURL=HealthHandler.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"HealthHandler.js","sourceRoot":"","sources":["../../../../../src/Server/lib/container/HealthHandler.ts"],"names":[],"mappings":";;;;;;;;;AAEA;;;;;GAKG;AACH,eAAe,CAAO,QAAiB,EAAE,GAAa,EAAE,EAAE;IACxD,GAAG,CAAC,IAAI,CAAC,UAAU,CAAC,CAAA;AACtB,CAAC,CAAA,CAAA"}
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
import Server from './../Server.js';
|
|
2
|
+
import { RouterConfig } from '../../Router.js';
|
|
3
|
+
/**
|
|
4
|
+
* Represents a Proxy class that handles routing and server functionality.
|
|
5
|
+
*/
|
|
6
|
+
export default class Proxy {
|
|
7
|
+
/**
|
|
8
|
+
* A boolean flag indicating whether the process is currently stopping or not.
|
|
9
|
+
*/
|
|
10
|
+
private stopping;
|
|
11
|
+
/**
|
|
12
|
+
* The configuration object for the router.
|
|
13
|
+
*/
|
|
14
|
+
private readonly config;
|
|
15
|
+
/**
|
|
16
|
+
* The Express application instance for the server.
|
|
17
|
+
* @readonly
|
|
18
|
+
* @type {express.Express}
|
|
19
|
+
*/
|
|
20
|
+
private readonly app;
|
|
21
|
+
/**
|
|
22
|
+
* The handler function for serverless events in the Server class.
|
|
23
|
+
* @param {ServerlessEvent} event - The serverless event object.
|
|
24
|
+
* @returns None
|
|
25
|
+
*/
|
|
26
|
+
private readonly serverlessHandler;
|
|
27
|
+
/**
|
|
28
|
+
* Represents a listener for an HTTP server.
|
|
29
|
+
* @private
|
|
30
|
+
* @type {HTTPServer}
|
|
31
|
+
*/
|
|
32
|
+
private listener;
|
|
33
|
+
/**
|
|
34
|
+
* Constructs a new instance of the Router class.
|
|
35
|
+
* @param {RouterConfig} config - The configuration object for the router.
|
|
36
|
+
* @param {Server['handleServerlessEvent']} serverlessHandler - The handler function for serverless events.
|
|
37
|
+
* @returns None
|
|
38
|
+
*/
|
|
39
|
+
constructor(config: RouterConfig, serverlessHandler: Server['handleServerlessEvent']);
|
|
40
|
+
/**
|
|
41
|
+
* Loads the necessary components and initializes the application.
|
|
42
|
+
* @returns None
|
|
43
|
+
*/
|
|
44
|
+
load(): Promise<void>;
|
|
45
|
+
/**
|
|
46
|
+
* Unloads the current module, stopping any active listeners.
|
|
47
|
+
* @param {any} [err] - Optional error object to pass to the stopListeners method.
|
|
48
|
+
* @returns {Promise<void>} - A promise that resolves once the listeners have been stopped.
|
|
49
|
+
*/
|
|
50
|
+
unload(err?: any): Promise<void>;
|
|
51
|
+
/**
|
|
52
|
+
* Starts the listeners for the proxy server.
|
|
53
|
+
* @returns {Promise<void>} A promise that resolves when the listeners have started.
|
|
54
|
+
*/
|
|
55
|
+
private startListeners;
|
|
56
|
+
/**
|
|
57
|
+
* Stops the listeners and exits the process.
|
|
58
|
+
* @param {any} [err] - Optional error object.
|
|
59
|
+
* @returns {Promise<void>} - A promise that resolves when the listeners are stopped and the process is exited.
|
|
60
|
+
*/
|
|
61
|
+
private stopListeners;
|
|
62
|
+
/**
|
|
63
|
+
* Installs the routes for the proxy server.
|
|
64
|
+
* @returns None
|
|
65
|
+
*/
|
|
66
|
+
private installRoutes;
|
|
67
|
+
}
|