@ikonintegration/ikapi 5.0.0 → 5.0.1-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/dist/index.d.ts CHANGED
@@ -2,6 +2,7 @@ import { HttpMethod } from './src/API/Request.js';
2
2
  import Response, { ResponseErrorType } from './src/API/Response.js';
3
3
  import DynamoTransaction from './src/BaseEvent/DynamoTransaction.js';
4
4
  import EventProcessor from './src/BaseEvent/EventProcessor.js';
5
+ import Launchable from './src/BaseEvent/Launchable/index.js';
5
6
  import Process from './src/BaseEvent/Process.js';
6
7
  import StepTransaction from './src/BaseEvent/StepTransaction.js';
7
8
  import Transaction, { TransactionConfig } from './src/BaseEvent/Transaction.js';
@@ -13,4 +14,4 @@ import Mailer from './src/Mailer/Mailer.js';
13
14
  import Router, { Route } from './src/Server/Router.js';
14
15
  import AsyncSingleton from './src/Util/AsyncSingleton.js';
15
16
  import Utils from './src/Util/Utils.js';
16
- export { Transaction, Process, EventProcessor, DynamoTransaction, StepTransaction, Router, Route, HttpMethod, Mailer, Crypto, Configuration, Redis, Database, Response, ResponseErrorType, Utils, AsyncSingleton, TransactionConfig, };
17
+ export { Transaction, Process, EventProcessor, DynamoTransaction, StepTransaction, Launchable, Router, Route, HttpMethod, Mailer, Crypto, Configuration, Redis, Database, Response, ResponseErrorType, Utils, AsyncSingleton, TransactionConfig, };
package/dist/index.js CHANGED
@@ -2,6 +2,7 @@ import { HttpMethod } from './src/API/Request.js';
2
2
  import Response from './src/API/Response.js';
3
3
  import DynamoTransaction from './src/BaseEvent/DynamoTransaction.js';
4
4
  import EventProcessor from './src/BaseEvent/EventProcessor.js';
5
+ import Launchable from './src/BaseEvent/Launchable/index.js';
5
6
  import Process from './src/BaseEvent/Process.js';
6
7
  import StepTransaction from './src/BaseEvent/StepTransaction.js';
7
8
  import Transaction from './src/BaseEvent/Transaction.js';
@@ -15,7 +16,7 @@ import AsyncSingleton from './src/Util/AsyncSingleton.js';
15
16
  import Utils from './src/Util/Utils.js';
16
17
  export {
17
18
  // Base Events
18
- Transaction, Process, EventProcessor, DynamoTransaction, StepTransaction,
19
+ Transaction, Process, EventProcessor, DynamoTransaction, StepTransaction, Launchable,
19
20
  // Http
20
21
  Router, HttpMethod,
21
22
  // Modules
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,sBAAsB,CAAA;AACjD,OAAO,QAA+B,MAAM,uBAAuB,CAAA;AACnE,OAAO,iBAAiB,MAAM,sCAAsC,CAAA;AACpE,OAAO,cAAc,MAAM,mCAAmC,CAAA;AAC9D,OAAO,OAAO,MAAM,4BAA4B,CAAA;AAChD,OAAO,eAAe,MAAM,oCAAoC,CAAA;AAChE,OAAO,WAAkC,MAAM,gCAAgC,CAAA;AAC/E,OAAO,KAAK,MAAM,sBAAsB,CAAA;AACxC,OAAO,aAAa,MAAM,+BAA+B,CAAA;AACzD,OAAO,MAAM,MAAM,wBAAwB,CAAA;AAC3C,OAAO,KAAK,QAAQ,MAAM,yBAAyB,CAAA;AACnD,OAAO,MAAM,MAAM,wBAAwB,CAAA;AAC3C,OAAO,MAAiB,MAAM,wBAAwB,CAAA;AACtD,OAAO,cAAc,MAAM,8BAA8B,CAAA;AACzD,OAAO,KAAK,MAAM,qBAAqB,CAAA;AAEvC,OAAO;AACL,cAAc;AACd,WAAW,EACX,OAAO,EACP,cAAc,EACd,iBAAiB,EACjB,eAAe;AACf,OAAO;AACP,MAAM,EAEN,UAAU;AACV,UAAU;AACV,MAAM,EACN,MAAM,EACN,aAAa,EACb,KAAK,EACL,QAAQ;AACR,MAAM;AACN,QAAQ;AAER,UAAU;AACV,KAAK,EACL,cAAc,GAEf,CAAA"}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,sBAAsB,CAAA;AACjD,OAAO,QAA+B,MAAM,uBAAuB,CAAA;AACnE,OAAO,iBAAiB,MAAM,sCAAsC,CAAA;AACpE,OAAO,cAAc,MAAM,mCAAmC,CAAA;AAC9D,OAAO,UAAU,MAAM,qCAAqC,CAAA;AAC5D,OAAO,OAAO,MAAM,4BAA4B,CAAA;AAChD,OAAO,eAAe,MAAM,oCAAoC,CAAA;AAChE,OAAO,WAAkC,MAAM,gCAAgC,CAAA;AAC/E,OAAO,KAAK,MAAM,sBAAsB,CAAA;AACxC,OAAO,aAAa,MAAM,+BAA+B,CAAA;AACzD,OAAO,MAAM,MAAM,wBAAwB,CAAA;AAC3C,OAAO,KAAK,QAAQ,MAAM,yBAAyB,CAAA;AACnD,OAAO,MAAM,MAAM,wBAAwB,CAAA;AAC3C,OAAO,MAAiB,MAAM,wBAAwB,CAAA;AACtD,OAAO,cAAc,MAAM,8BAA8B,CAAA;AACzD,OAAO,KAAK,MAAM,qBAAqB,CAAA;AAEvC,OAAO;AACL,cAAc;AACd,WAAW,EACX,OAAO,EACP,cAAc,EACd,iBAAiB,EACjB,eAAe,EACf,UAAU;AACV,OAAO;AACP,MAAM,EAEN,UAAU;AACV,UAAU;AACV,MAAM,EACN,MAAM,EACN,aAAa,EACb,KAAK,EACL,QAAQ;AACR,MAAM;AACN,QAAQ;AAER,UAAU;AACV,KAAK,EACL,cAAc,GAEf,CAAA"}
@@ -1,12 +1,12 @@
1
1
  {
2
2
  "name": "@ikonintegration/ikapi",
3
- "version": "5.0.0",
3
+ "version": "5.0.1-alpha.1",
4
4
  "lockfileVersion": 3,
5
5
  "requires": true,
6
6
  "packages": {
7
7
  "": {
8
8
  "name": "@ikonintegration/ikapi",
9
- "version": "5.0.0",
9
+ "version": "5.0.1-alpha.1",
10
10
  "license": "ISC",
11
11
  "dependencies": {
12
12
  "@aws-sdk/client-dynamodb": "^3.650.0",
@@ -40,6 +40,7 @@
40
40
  "zod": "^3.23.4"
41
41
  },
42
42
  "devDependencies": {
43
+ "@go-task/cli": "^3.39.0",
43
44
  "@jest/globals": "^29.7.0",
44
45
  "@types/aws-lambda": "^8.10.145",
45
46
  "@types/chai": "^4.3.19",
@@ -1711,6 +1712,25 @@
1711
1712
  "node": "^12.22.0 || ^14.17.0 || >=16.0.0"
1712
1713
  }
1713
1714
  },
1715
+ "node_modules/@go-task/cli": {
1716
+ "version": "3.39.0",
1717
+ "resolved": "https://registry.npmjs.org/@go-task/cli/-/cli-3.39.0.tgz",
1718
+ "integrity": "sha512-KhJ3Ao0ZR9JmmA5ad8ovFwr2mJmSLVqd0Y7hJBI130MZ9JXPmxavkoDc10d4oul/TCKG6nGwypru/OmFqkHTTw==",
1719
+ "dev": true,
1720
+ "hasInstallScript": true,
1721
+ "dependencies": {
1722
+ "@go-task/go-npm": "^0.2.0"
1723
+ }
1724
+ },
1725
+ "node_modules/@go-task/go-npm": {
1726
+ "version": "0.2.0",
1727
+ "resolved": "https://registry.npmjs.org/@go-task/go-npm/-/go-npm-0.2.0.tgz",
1728
+ "integrity": "sha512-vQbdtBvesHm8EUFHX8QKg4rbBodmu9VsAXH1ozpbiN5jdTMOYHTCMM31EurAYmY+rNNtxJQ4JGy6t383RPlqbw==",
1729
+ "dev": true,
1730
+ "bin": {
1731
+ "go-npm": "bin/index.js"
1732
+ }
1733
+ },
1714
1734
  "node_modules/@hapi/boom": {
1715
1735
  "version": "10.0.1",
1716
1736
  "resolved": "https://registry.npmjs.org/@hapi/boom/-/boom-10.0.1.tgz",
package/dist/package.json CHANGED
@@ -1,20 +1,20 @@
1
1
  {
2
2
  "name": "@ikonintegration/ikapi",
3
- "version": "5.0.0",
3
+ "version": "5.0.1-alpha.1",
4
4
  "description": "",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",
7
7
  "type": "module",
8
8
  "scripts": {
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"
9
+ "build": "task build",
10
+ "clean": "task clean",
11
+ "lint-fix": "task lint-fix",
12
+ "lint": "task lint",
13
+ "docs": "task docs",
14
+ "test": "task test",
15
+ "test-ts": "task test-ts",
16
+ "test-js": "task test-js",
17
+ "test-dev": "task test-dev"
18
18
  },
19
19
  "author": "",
20
20
  "license": "ISC",
@@ -50,6 +50,7 @@
50
50
  "zod": "^3.23.4"
51
51
  },
52
52
  "devDependencies": {
53
+ "@go-task/cli": "^3.39.0",
53
54
  "@jest/globals": "^29.7.0",
54
55
  "@types/aws-lambda": "^8.10.145",
55
56
  "@types/chai": "^4.3.19",
@@ -0,0 +1,42 @@
1
+ import { LaunchableHandlerType } from './types.js';
2
+ /**
3
+ * Represents a ContainerExecution class that handles the execution of a launchable handler.
4
+ * @template Input - The type of input expected by the launchable handler.
5
+ */
6
+ export default class ContainerExecution<Input> {
7
+ /**
8
+ * A private readonly property that holds a handler of LaunchableHandlerType with a given Input type.
9
+ */
10
+ private readonly handler;
11
+ /**
12
+ * Constructor for creating an instance of a class with a LaunchableHandlerType input.
13
+ * @param {LaunchableHandlerType<Input>} handler - The handler for the launchable type.
14
+ * @returns None
15
+ */
16
+ constructor(handler: LaunchableHandlerType<Input>);
17
+ /**
18
+ * Executes the function asynchronously, invoking the specified inputs and handling the response accordingly.
19
+ * If the response code is 200, the process exits with code 0; otherwise, it exits with code 1.
20
+ * @returns None
21
+ */
22
+ execute(): Promise<void>;
23
+ /**
24
+ * Retrieves inputs from the process arguments and parses them as JSON.
25
+ * @returns {any} The parsed input object from process arguments.
26
+ */
27
+ private getInputs;
28
+ /**
29
+ * Builds a context object for AWS Lambda function.
30
+ * @param {CallableFunction} callback - The callback function to be executed.
31
+ * @returns {Context} A context object with AWS Lambda properties.
32
+ */
33
+ private buildContext;
34
+ /**
35
+ * Asynchronously invokes a function with the given input and returns a promise that resolves
36
+ * with an object containing an error message or data response.
37
+ * @param {any} input - The input to be passed to the function.
38
+ * @returns {Promise<{ err?: string; data?: Response<any> }>} A promise that resolves with an object
39
+ * containing an error message or data response.
40
+ */
41
+ private invoke;
42
+ }
@@ -0,0 +1,102 @@
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
+ * Represents a ContainerExecution class that handles the execution of a launchable handler.
12
+ * @template Input - The type of input expected by the launchable handler.
13
+ */
14
+ export default class ContainerExecution {
15
+ /**
16
+ * Constructor for creating an instance of a class with a LaunchableHandlerType input.
17
+ * @param {LaunchableHandlerType<Input>} handler - The handler for the launchable type.
18
+ * @returns None
19
+ */
20
+ constructor(handler) {
21
+ this.handler = handler;
22
+ }
23
+ /**
24
+ * Executes the function asynchronously, invoking the specified inputs and handling the response accordingly.
25
+ * If the response code is 200, the process exits with code 0; otherwise, it exits with code 1.
26
+ * @returns None
27
+ */
28
+ execute() {
29
+ return __awaiter(this, void 0, void 0, function* () {
30
+ try {
31
+ // Invoke
32
+ const resp = yield this.invoke(this.getInputs());
33
+ // Return
34
+ console.debug(resp);
35
+ if (!resp.err && resp.data && resp.data.getCode() == 200)
36
+ process.exit(0);
37
+ else
38
+ process.exit(1);
39
+ }
40
+ catch (e) {
41
+ console.error(e);
42
+ process.exit(1);
43
+ }
44
+ });
45
+ }
46
+ /**
47
+ * Retrieves inputs from the process arguments and parses them as JSON.
48
+ * @returns {any} The parsed input object from process arguments.
49
+ */
50
+ getInputs() {
51
+ let input = {};
52
+ console.debug(process.argv);
53
+ try {
54
+ input = JSON.parse(process.argv[2]);
55
+ }
56
+ catch (e) {
57
+ console.log('[IKApi Launchable Runtime] - Error while decoding process arguments!', e);
58
+ }
59
+ return input;
60
+ }
61
+ /**
62
+ * Builds a context object for AWS Lambda function.
63
+ * @param {CallableFunction} callback - The callback function to be executed.
64
+ * @returns {Context} A context object with AWS Lambda properties.
65
+ */
66
+ buildContext(callback) {
67
+ return {
68
+ awsRequestId: `${Date.now()}-${Date.now()}`,
69
+ callbackWaitsForEmptyEventLoop: true,
70
+ getRemainingTimeInMillis: () => 0,
71
+ done: (err, data) => callback(err, data),
72
+ fail: err => callback(err),
73
+ succeed: res => callback(null, res),
74
+ };
75
+ }
76
+ /**
77
+ * Asynchronously invokes a function with the given input and returns a promise that resolves
78
+ * with an object containing an error message or data response.
79
+ * @param {any} input - The input to be passed to the function.
80
+ * @returns {Promise<{ err?: string; data?: Response<any> }>} A promise that resolves with an object
81
+ * containing an error message or data response.
82
+ */
83
+ invoke(input) {
84
+ return __awaiter(this, void 0, void 0, function* () {
85
+ // eslint-disable-next-line no-async-promise-executor
86
+ return new Promise((resolve, reject) => __awaiter(this, void 0, void 0, function* () {
87
+ try {
88
+ const context = this.buildContext((err, data) => {
89
+ resolve({ err, data });
90
+ });
91
+ const resp = yield this.handler(input, context);
92
+ if (resp)
93
+ resolve({ data: resp });
94
+ }
95
+ catch (e) {
96
+ reject(e);
97
+ }
98
+ }));
99
+ });
100
+ }
101
+ }
102
+ //# sourceMappingURL=ContainerExec.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ContainerExec.js","sourceRoot":"","sources":["../../../../src/BaseEvent/Launchable/ContainerExec.ts"],"names":[],"mappings":";;;;;;;;;AAKA;;;GAGG;AACH,MAAM,CAAC,OAAO,OAAO,kBAAkB;IAMrC;;;;OAIG;IACH,YAAY,OAAqC;QAC/C,IAAI,CAAC,OAAO,GAAG,OAAO,CAAA;IACxB,CAAC;IAED;;;;OAIG;IACU,OAAO;;YAClB,IAAI,CAAC;gBACH,SAAS;gBACT,MAAM,IAAI,GAAG,MAAM,IAAI,CAAC,MAAM,CAAC,IAAI,CAAC,SAAS,EAAE,CAAC,CAAA;gBAChD,SAAS;gBACT,OAAO,CAAC,KAAK,CAAC,IAAI,CAAC,CAAA;gBACnB,IAAI,CAAC,IAAI,CAAC,GAAG,IAAI,IAAI,CAAC,IAAI,IAAI,IAAI,CAAC,IAAI,CAAC,OAAO,EAAE,IAAI,GAAG;oBAAE,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAA;;oBACpE,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAA;YACtB,CAAC;YAAC,OAAO,CAAC,EAAE,CAAC;gBACX,OAAO,CAAC,KAAK,CAAC,CAAC,CAAC,CAAA;gBAChB,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAA;YACjB,CAAC;QACH,CAAC;KAAA;IAED;;;OAGG;IACK,SAAS;QACf,IAAI,KAAK,GAAQ,EAAE,CAAA;QACnB,OAAO,CAAC,KAAK,CAAC,OAAO,CAAC,IAAI,CAAC,CAAA;QAC3B,IAAI,CAAC;YACH,KAAK,GAAG,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,CAAA;QACrC,CAAC;QAAC,OAAO,CAAC,EAAE,CAAC;YACX,OAAO,CAAC,GAAG,CAAC,sEAAsE,EAAE,CAAC,CAAC,CAAA;QACxF,CAAC;QACD,OAAO,KAAK,CAAA;IACd,CAAC;IAED;;;;OAIG;IACK,YAAY,CAAC,QAA0B;QAC7C,OAAO;YACL,YAAY,EAAE,GAAG,IAAI,CAAC,GAAG,EAAE,IAAI,IAAI,CAAC,GAAG,EAAE,EAAE;YAC3C,8BAA8B,EAAE,IAAI;YACpC,wBAAwB,EAAE,GAAG,EAAE,CAAC,CAAC;YACjC,IAAI,EAAE,CAAC,GAAG,EAAE,IAAI,EAAE,EAAE,CAAC,QAAQ,CAAC,GAAG,EAAE,IAAI,CAAC;YACxC,IAAI,EAAE,GAAG,CAAC,EAAE,CAAC,QAAQ,CAAC,GAAG,CAAC;YAC1B,OAAO,EAAE,GAAG,CAAC,EAAE,CAAC,QAAQ,CAAC,IAAI,EAAE,GAAG,CAAC;SAClB,CAAA;IACrB,CAAC;IAED;;;;;;OAMG;IACW,MAAM,CAAC,KAAU;;YAC7B,qDAAqD;YACrD,OAAO,IAAI,OAAO,CAAyC,CAAO,OAAO,EAAE,MAAM,EAAE,EAAE;gBACnF,IAAI,CAAC;oBACH,MAAM,OAAO,GAAG,IAAI,CAAC,YAAY,CAAC,CAAC,GAAG,EAAE,IAAI,EAAE,EAAE;wBAC9C,OAAO,CAAC,EAAE,GAAG,EAAE,IAAI,EAAE,CAAC,CAAA;oBACxB,CAAC,CAAC,CAAA;oBACF,MAAM,IAAI,GAAG,MAAM,IAAI,CAAC,OAAO,CAAC,KAAK,EAAE,OAAO,CAAC,CAAA;oBAC/C,IAAI,IAAI;wBAAE,OAAO,CAAC,EAAE,IAAI,EAAE,IAAI,EAAE,CAAC,CAAA;gBACnC,CAAC;gBAAC,OAAO,CAAC,EAAE,CAAC;oBACX,MAAM,CAAC,CAAC,CAAC,CAAA;gBACX,CAAC;YACH,CAAC,CAAA,CAAC,CAAA;QACJ,CAAC;KAAA;CACF"}
@@ -0,0 +1,34 @@
1
+ import { LaunchableHandlerType } from './types.js';
2
+ /**
3
+ * Represents a Launchable class that can be used to handle launchable items.
4
+ * @template Input - The type of input expected by the LaunchableHandlerType.
5
+ */
6
+ export default class Launchable<Input = any> {
7
+ /**
8
+ * A private readonly property that holds a handler for launching with a specific input type.
9
+ * @type {LaunchableHandlerType<Input>}
10
+ */
11
+ private readonly handler;
12
+ /**
13
+ * Constructor for creating an instance of a class with a LaunchableHandlerType input.
14
+ * @param {LaunchableHandlerType<Input>} handler - The handler for the launchable type.
15
+ * @returns None
16
+ */
17
+ constructor(handler: LaunchableHandlerType<Input>);
18
+ /**
19
+ * Returns the export function based on whether the object is a container or not.
20
+ * If it is a container, it returns the container export function, otherwise it returns the handler function.
21
+ * @returns {CallableFunction} The export function to be used.
22
+ */
23
+ getExport(): CallableFunction;
24
+ /**
25
+ * Checks if the current element is a container by calling the isHybridlessContainer method from the Utils class.
26
+ * @returns {boolean} - true if the element is a container, false otherwise.
27
+ */
28
+ private isContainer;
29
+ /**
30
+ * Returns a callable function that executes a ContainerExecution instance and returns a promise.
31
+ * @returns {CallableFunction} A function that when called, executes a ContainerExecution instance.
32
+ */
33
+ private getContainerExport;
34
+ }
@@ -0,0 +1,43 @@
1
+ import ContainerExecution from './ContainerExec.js';
2
+ import Utils from '../../Util/Utils.js';
3
+ /**
4
+ * Represents a Launchable class that can be used to handle launchable items.
5
+ * @template Input - The type of input expected by the LaunchableHandlerType.
6
+ */
7
+ export default class Launchable {
8
+ /**
9
+ * Constructor for creating an instance of a class with a LaunchableHandlerType input.
10
+ * @param {LaunchableHandlerType<Input>} handler - The handler for the launchable type.
11
+ * @returns None
12
+ */
13
+ constructor(handler) {
14
+ this.handler = handler;
15
+ }
16
+ /**
17
+ * Returns the export function based on whether the object is a container or not.
18
+ * If it is a container, it returns the container export function, otherwise it returns the handler function.
19
+ * @returns {CallableFunction} The export function to be used.
20
+ */
21
+ getExport() {
22
+ return this.isContainer() ? this.getContainerExport() : this.handler;
23
+ }
24
+ /**
25
+ * Checks if the current element is a container by calling the isHybridlessContainer method from the Utils class.
26
+ * @returns {boolean} - true if the element is a container, false otherwise.
27
+ */
28
+ isContainer() {
29
+ return Utils.isHybridlessContainer();
30
+ }
31
+ /**
32
+ * Returns a callable function that executes a ContainerExecution instance and returns a promise.
33
+ * @returns {CallableFunction} A function that when called, executes a ContainerExecution instance.
34
+ */
35
+ getContainerExport() {
36
+ // emulate lambda invocation
37
+ const ce = new ContainerExecution(this.handler);
38
+ ce.execute().then(() => { });
39
+ // return empty function, we are all done
40
+ return () => { };
41
+ }
42
+ }
43
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../src/BaseEvent/Launchable/index.ts"],"names":[],"mappings":"AAAA,OAAO,kBAAkB,MAAM,oBAAoB,CAAA;AAEnD,OAAO,KAAK,MAAM,qBAAqB,CAAA;AAEvC;;;GAGG;AACH,MAAM,CAAC,OAAO,OAAO,UAAU;IAO7B;;;;OAIG;IACH,YAAY,OAAqC;QAC/C,IAAI,CAAC,OAAO,GAAG,OAAO,CAAA;IACxB,CAAC;IAED;;;;OAIG;IACI,SAAS;QACd,OAAO,IAAI,CAAC,WAAW,EAAE,CAAC,CAAC,CAAC,IAAI,CAAC,kBAAkB,EAAE,CAAC,CAAC,CAAC,IAAI,CAAC,OAAO,CAAA;IACtE,CAAC;IAED;;;OAGG;IACK,WAAW;QACjB,OAAO,KAAK,CAAC,qBAAqB,EAAE,CAAA;IACtC,CAAC;IAED;;;OAGG;IACK,kBAAkB;QACxB,4BAA4B;QAC5B,MAAM,EAAE,GAAG,IAAI,kBAAkB,CAAC,IAAI,CAAC,OAAO,CAAC,CAAA;QAC/C,EAAE,CAAC,OAAO,EAAE,CAAC,IAAI,CAAC,GAAG,EAAE,GAAE,CAAC,CAAC,CAAA;QAC3B,yCAAyC;QACzC,OAAO,GAAG,EAAE,GAAE,CAAC,CAAA;IACjB,CAAC;CACF"}
@@ -0,0 +1,10 @@
1
+ import { Context } from 'aws-lambda';
2
+ import Response from '../../API/Response.js';
3
+ /**
4
+ * Defines a type for a launchable handler that takes an input event and context,
5
+ * and returns a promise of a response.
6
+ * @param {Input} event - The input event for the handler.
7
+ * @param {Context} context - The context for the handler.
8
+ * @returns {Promise<Response<any>>} A promise that resolves to a response.
9
+ */
10
+ export type LaunchableHandlerType<Input> = (event: Input, context: Context) => Promise<Response<any>>;
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=types.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.js","sourceRoot":"","sources":["../../../../src/BaseEvent/Launchable/types.ts"],"names":[],"mappings":""}
@@ -1 +1 @@
1
- {"root":["../index.ts","../src/globals.ts","../src/api/request.ts","../src/api/response.ts","../src/baseevent/dynamotransaction.ts","../src/baseevent/eventprocessor.ts","../src/baseevent/process.ts","../src/baseevent/steptransaction.ts","../src/baseevent/transaction.ts","../src/cache/redis.ts","../src/cache/types.ts","../src/config/configuration.ts","../src/config/environmentvar.ts","../src/crypto/crypto.ts","../src/database/database.ts","../src/database/databasemanager.ts","../src/database/databasetransaction.ts","../src/database/index.ts","../src/database/types.ts","../src/database/integrations/dynamo/dynamodatabase.ts","../src/database/integrations/kysely/kyselydatabase.ts","../src/database/integrations/kysely/kyselytransaction.ts","../src/database/integrations/pgsql/postgresdatabase.ts","../src/database/integrations/pgsql/postgrestransaction.ts","../src/logger/logger.ts","../src/mailer/mailer.ts","../src/publisher/publisher.ts","../src/server/routeresolver.ts","../src/server/router.ts","../src/server/lib/containerserver.ts","../src/server/lib/server.ts","../src/server/lib/container/generichandler.ts","../src/server/lib/container/generichandlerevent.ts","../src/server/lib/container/healthhandler.ts","../src/server/lib/container/proxy.ts","../src/server/lib/container/utils.ts","../src/util/asyncsingleton.ts","../src/util/utils.ts","../src/validation/validator.ts","../package-lock.json","../package.json"],"version":"5.6.2"}
1
+ {"root":["../index.ts","../src/globals.ts","../src/api/request.ts","../src/api/response.ts","../src/baseevent/dynamotransaction.ts","../src/baseevent/eventprocessor.ts","../src/baseevent/process.ts","../src/baseevent/steptransaction.ts","../src/baseevent/transaction.ts","../src/baseevent/launchable/containerexec.ts","../src/baseevent/launchable/index.ts","../src/baseevent/launchable/types.ts","../src/cache/redis.ts","../src/cache/types.ts","../src/config/configuration.ts","../src/config/environmentvar.ts","../src/crypto/crypto.ts","../src/database/database.ts","../src/database/databasemanager.ts","../src/database/databasetransaction.ts","../src/database/index.ts","../src/database/types.ts","../src/database/integrations/dynamo/dynamodatabase.ts","../src/database/integrations/kysely/kyselydatabase.ts","../src/database/integrations/kysely/kyselytransaction.ts","../src/database/integrations/pgsql/postgresdatabase.ts","../src/database/integrations/pgsql/postgrestransaction.ts","../src/logger/logger.ts","../src/mailer/mailer.ts","../src/publisher/publisher.ts","../src/server/routeresolver.ts","../src/server/router.ts","../src/server/lib/containerserver.ts","../src/server/lib/server.ts","../src/server/lib/container/generichandler.ts","../src/server/lib/container/generichandlerevent.ts","../src/server/lib/container/healthhandler.ts","../src/server/lib/container/proxy.ts","../src/server/lib/container/utils.ts","../src/util/asyncsingleton.ts","../src/util/utils.ts","../src/validation/validator.ts","../package-lock.json","../package.json"],"version":"5.6.2"}
package/index.ts CHANGED
@@ -2,6 +2,7 @@ import { HttpMethod } from './src/API/Request.js'
2
2
  import Response, { ResponseErrorType } from './src/API/Response.js'
3
3
  import DynamoTransaction from './src/BaseEvent/DynamoTransaction.js'
4
4
  import EventProcessor from './src/BaseEvent/EventProcessor.js'
5
+ import Launchable from './src/BaseEvent/Launchable/index.js'
5
6
  import Process from './src/BaseEvent/Process.js'
6
7
  import StepTransaction from './src/BaseEvent/StepTransaction.js'
7
8
  import Transaction, { TransactionConfig } from './src/BaseEvent/Transaction.js'
@@ -21,6 +22,7 @@ export {
21
22
  EventProcessor,
22
23
  DynamoTransaction,
23
24
  StepTransaction,
25
+ Launchable,
24
26
  // Http
25
27
  Router,
26
28
  Route,
package/package.json CHANGED
@@ -1,20 +1,20 @@
1
1
  {
2
2
  "name": "@ikonintegration/ikapi",
3
- "version": "5.0.0",
3
+ "version": "5.0.1-alpha.1",
4
4
  "description": "",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",
7
7
  "type": "module",
8
8
  "scripts": {
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"
9
+ "build": "task build",
10
+ "clean": "task clean",
11
+ "lint-fix": "task lint-fix",
12
+ "lint": "task lint",
13
+ "docs": "task docs",
14
+ "test": "task test",
15
+ "test-ts": "task test-ts",
16
+ "test-js": "task test-js",
17
+ "test-dev": "task test-dev"
18
18
  },
19
19
  "author": "",
20
20
  "license": "ISC",
@@ -50,6 +50,7 @@
50
50
  "zod": "^3.23.4"
51
51
  },
52
52
  "devDependencies": {
53
+ "@go-task/cli": "^3.39.0",
53
54
  "@jest/globals": "^29.7.0",
54
55
  "@types/aws-lambda": "^8.10.145",
55
56
  "@types/chai": "^4.3.19",
@@ -0,0 +1,96 @@
1
+ import { Context } from 'aws-lambda'
2
+
3
+ import { LaunchableHandlerType } from './types.js'
4
+ import Response from '../../API/Response.js'
5
+
6
+ /**
7
+ * Represents a ContainerExecution class that handles the execution of a launchable handler.
8
+ * @template Input - The type of input expected by the launchable handler.
9
+ */
10
+ export default class ContainerExecution<Input> {
11
+ /**
12
+ * A private readonly property that holds a handler of LaunchableHandlerType with a given Input type.
13
+ */
14
+ private readonly handler: LaunchableHandlerType<Input>
15
+
16
+ /**
17
+ * Constructor for creating an instance of a class with a LaunchableHandlerType input.
18
+ * @param {LaunchableHandlerType<Input>} handler - The handler for the launchable type.
19
+ * @returns None
20
+ */
21
+ constructor(handler: LaunchableHandlerType<Input>) {
22
+ this.handler = handler
23
+ }
24
+
25
+ /**
26
+ * Executes the function asynchronously, invoking the specified inputs and handling the response accordingly.
27
+ * If the response code is 200, the process exits with code 0; otherwise, it exits with code 1.
28
+ * @returns None
29
+ */
30
+ public async execute() {
31
+ try {
32
+ // Invoke
33
+ const resp = await this.invoke(this.getInputs())
34
+ // Return
35
+ console.debug(resp)
36
+ if (!resp.err && resp.data && resp.data.getCode() == 200) process.exit(0)
37
+ else process.exit(1)
38
+ } catch (e) {
39
+ console.error(e)
40
+ process.exit(1)
41
+ }
42
+ }
43
+
44
+ /**
45
+ * Retrieves inputs from the process arguments and parses them as JSON.
46
+ * @returns {any} The parsed input object from process arguments.
47
+ */
48
+ private getInputs() {
49
+ let input: any = {}
50
+ console.debug(process.argv)
51
+ try {
52
+ input = JSON.parse(process.argv[2])
53
+ } catch (e) {
54
+ console.log('[IKApi Launchable Runtime] - Error while decoding process arguments!', e)
55
+ }
56
+ return input
57
+ }
58
+
59
+ /**
60
+ * Builds a context object for AWS Lambda function.
61
+ * @param {CallableFunction} callback - The callback function to be executed.
62
+ * @returns {Context} A context object with AWS Lambda properties.
63
+ */
64
+ private buildContext(callback: CallableFunction): Context {
65
+ return {
66
+ awsRequestId: `${Date.now()}-${Date.now()}`,
67
+ callbackWaitsForEmptyEventLoop: true,
68
+ getRemainingTimeInMillis: () => 0,
69
+ done: (err, data) => callback(err, data),
70
+ fail: err => callback(err),
71
+ succeed: res => callback(null, res),
72
+ } as any as Context
73
+ }
74
+
75
+ /**
76
+ * Asynchronously invokes a function with the given input and returns a promise that resolves
77
+ * with an object containing an error message or data response.
78
+ * @param {any} input - The input to be passed to the function.
79
+ * @returns {Promise<{ err?: string; data?: Response<any> }>} A promise that resolves with an object
80
+ * containing an error message or data response.
81
+ */
82
+ private async invoke(input: any) {
83
+ // eslint-disable-next-line no-async-promise-executor
84
+ return new Promise<{ err?: string; data?: Response<any> }>(async (resolve, reject) => {
85
+ try {
86
+ const context = this.buildContext((err, data) => {
87
+ resolve({ err, data })
88
+ })
89
+ const resp = await this.handler(input, context)
90
+ if (resp) resolve({ data: resp })
91
+ } catch (e) {
92
+ reject(e)
93
+ }
94
+ })
95
+ }
96
+ }
@@ -0,0 +1,53 @@
1
+ import ContainerExecution from './ContainerExec.js'
2
+ import { LaunchableHandlerType } from './types.js'
3
+ import Utils from '../../Util/Utils.js'
4
+
5
+ /**
6
+ * Represents a Launchable class that can be used to handle launchable items.
7
+ * @template Input - The type of input expected by the LaunchableHandlerType.
8
+ */
9
+ export default class Launchable<Input = any> {
10
+ /**
11
+ * A private readonly property that holds a handler for launching with a specific input type.
12
+ * @type {LaunchableHandlerType<Input>}
13
+ */
14
+ private readonly handler: LaunchableHandlerType<Input>
15
+
16
+ /**
17
+ * Constructor for creating an instance of a class with a LaunchableHandlerType input.
18
+ * @param {LaunchableHandlerType<Input>} handler - The handler for the launchable type.
19
+ * @returns None
20
+ */
21
+ constructor(handler: LaunchableHandlerType<Input>) {
22
+ this.handler = handler
23
+ }
24
+
25
+ /**
26
+ * Returns the export function based on whether the object is a container or not.
27
+ * If it is a container, it returns the container export function, otherwise it returns the handler function.
28
+ * @returns {CallableFunction} The export function to be used.
29
+ */
30
+ public getExport(): CallableFunction {
31
+ return this.isContainer() ? this.getContainerExport() : this.handler
32
+ }
33
+
34
+ /**
35
+ * Checks if the current element is a container by calling the isHybridlessContainer method from the Utils class.
36
+ * @returns {boolean} - true if the element is a container, false otherwise.
37
+ */
38
+ private isContainer(): boolean {
39
+ return Utils.isHybridlessContainer()
40
+ }
41
+
42
+ /**
43
+ * Returns a callable function that executes a ContainerExecution instance and returns a promise.
44
+ * @returns {CallableFunction} A function that when called, executes a ContainerExecution instance.
45
+ */
46
+ private getContainerExport(): CallableFunction {
47
+ // emulate lambda invocation
48
+ const ce = new ContainerExecution(this.handler)
49
+ ce.execute().then(() => {})
50
+ // return empty function, we are all done
51
+ return () => {}
52
+ }
53
+ }
@@ -0,0 +1,15 @@
1
+ import { Context } from 'aws-lambda'
2
+
3
+ import Response from '../../API/Response.js'
4
+
5
+ /**
6
+ * Defines a type for a launchable handler that takes an input event and context,
7
+ * and returns a promise of a response.
8
+ * @param {Input} event - The input event for the handler.
9
+ * @param {Context} context - The context for the handler.
10
+ * @returns {Promise<Response<any>>} A promise that resolves to a response.
11
+ */
12
+ export type LaunchableHandlerType<Input> = (
13
+ event: Input,
14
+ context: Context
15
+ ) => Promise<Response<any>>
package/taskfile.yml ADDED
@@ -0,0 +1,65 @@
1
+ version: '3'
2
+
3
+ vars:
4
+ test_node_options: '--experimental-vm-modules'
5
+ coverage_file: 'coverage/coverage.txt'
6
+
7
+ tasks:
8
+ build:
9
+ desc: Build the project
10
+ cmds:
11
+ - tsc --build
12
+
13
+ clean:
14
+ desc: Clean the build artifacts
15
+ cmds:
16
+ - tsc --build --clean
17
+
18
+ lint:
19
+ desc: Run ESLint
20
+ cmds:
21
+ - eslint .
22
+
23
+ lint-fix:
24
+ desc: Run ESLint and fix issues
25
+ cmds:
26
+ - eslint . --fix
27
+
28
+ docs:
29
+ desc: Generate documentation
30
+ cmds:
31
+ - npx typedoc --tsconfig tsconfig.json index.ts src/**/* --includeVersion --entryPointStrategy expand
32
+
33
+ test:
34
+ desc: Run all tests
35
+ cmds:
36
+ - task test-ts
37
+ - task test-js
38
+
39
+ test-ts:
40
+ desc: Run TypeScript tests
41
+ cmds:
42
+ - jest --workerIdleMemoryLimit=1024 --coverage --silent --runInBand --logHeapUsage
43
+ - cat {{.coverage_file}}
44
+
45
+ test-js:
46
+ desc: Run JavaScript smoke tests
47
+ cmds:
48
+ - rm -rf ./smoke-tests
49
+ - tsc -p tsconfig.smoke.json
50
+ - task test-js-inner
51
+
52
+ test-js-inner:
53
+ desc: Run smoke tests in the smoke-tests directory
54
+ dir: smoke-tests
55
+ cmds:
56
+ - cp -R ../node_modules node_modules
57
+ - npm i
58
+ - NODE_OPTIONS="$NODE_OPTIONS {{.test_node_options}}" jest --workerIdleMemoryLimit=1024 --config=./jest.smoke.config.js --coverage --silent --runInBand --logHeapUsage
59
+ - cat ../{{.coverage_file}}
60
+
61
+ test-dev:
62
+ desc: Run tests in development mode
63
+ cmds:
64
+ - jest --coverage --runInBand
65
+ - cat {{.coverage_file}}