diff --git a/ts/examples/simple-example-ts/index.ts b/ts/examples/simple-example-ts/index.ts index c4c0f90..f1a9ede 100644 --- a/ts/examples/simple-example-ts/index.ts +++ b/ts/examples/simple-example-ts/index.ts @@ -7,13 +7,12 @@ import { const sdk = createSdk({ authToken: "token", - aquilaUrl: "127.0.0.1:50051", - actionId: "service", + aquilaUrl: "127.0.0.1:8081", + actionId: "example", version: "0.0.0", }, [ { - type: "LIST", - linkedDataTypes: ["STRING", "LIST"], + type: "string[]", identifier: "config_discord_bot_token", } ]) @@ -25,38 +24,35 @@ sdk.registerDataTypes({ sdk.registerRuntimeFunctionDefinitionsAndFunctionDefinitions({ definition: { - signature: "(n: NUMBER) => NUMBER", - linkedDataTypes: ["NUMBER"], + signature: "(number: number) => number", parameters: [ { - runtimeName: "n", + runtimeName: "number", defaultValue: 20, } ], runtimeName: "fib", }, - //This param is optional and can be omitted - handler: (context: HerculesFunctionContext, n: number): number => { - console.log(context) - console.log("Project id:", context.projectId); - console.log("Execution id:", context.executionId); - console.log("Matched configs:", context.matchedConfig); // matched configs for the current execution - - function fibonacci(num: number): number { - if (num <= 1) return num; - return fibonacci(num - 1) + fibonacci(num - 2); - } - - throw new RuntimeErrorException("ERROR_CALCULATING_FIB", "An error occurred while calculating the Fibonacci number."); + //This param is optional and can be omitted + handler: (context: HerculesFunctionContext, number: bigint): bigint => { + console.log(context) + console.log("Project id:", context.projectId); + console.log("Execution id:", context.executionId); + console.log("Matched configs:", context.matchedConfig); // matched configs for the current execution + function fibonacci(num: bigint): bigint { + if (num <= 1) return num; + return fibonacci(num - 1n) + fibonacci(num - 2n); } + + return fibonacci(number) + } } ) sdk.registerFlowTypes( { - signature: "(): TEXT", - linkedDataTypes: ["TEXT"], + signature: "(): string", editable: false, identifier: "test_flow", } @@ -68,11 +64,13 @@ connectToSdk(); function connectToSdk() { sdk.connect().then((configs: HerculesActionProjectConfiguration[]) => { console.log("SDK connected successfully"); + sdk.dispatchEvent("test_flow", configs[0].projectId, "Hello, World! Configs loaded: " + configs.length).then(() => { console.log("Event dispatched successfully"); }) - }).catch((_error) => { - console.error("Error connecting SDK:"); + }).catch(() => { + // will be handled by logger internally + process.exit(1) }) sdk.onError((error) => { diff --git a/ts/examples/simple-example-ts/package-lock.json b/ts/examples/simple-example-ts/package-lock.json index 8bdbf96..b9a1c24 100644 --- a/ts/examples/simple-example-ts/package-lock.json +++ b/ts/examples/simple-example-ts/package-lock.json @@ -9,36 +9,31 @@ "version": "1.0.0", "license": "ISC", "dependencies": { - "@code0-tech/hercules": "file:../../code0-tech-hercules-0.0.0.tgz", - "@code0-tech/tucana": "^0.0.62" + "@code0-tech/hercules": "file:../../code0-tech-hercules-0.0.0.tgz" } }, "node_modules/@code0-tech/hercules": { "version": "0.0.0", "resolved": "file:../../code0-tech-hercules-0.0.0.tgz", - "integrity": "sha512-p5QarLysqUiuz6fWvJdZBlJoBaeal5oGxKMMX/B1vWOFhKrMfkSF1XGhUWeAMcjLchAxRkdI17wEnsuyCPY9QA==", + "integrity": "sha512-0J+8A+AN0rmy8YTXBAGPBgHYUARwf60k63kiWVHA2dob9xJfX7PyyncnRfPdRG0DtENLVN26qmtTmCRo4mM0kQ==", "license": "ISC", "dependencies": { - "@code0-tech/tucana": "^0.0.67", + "@code0-tech/tucana": "0.0.67", "@grpc/grpc-js": "^1.14.3", "@protobuf-ts/grpc-backend": "^2.11.1", "@protobuf-ts/grpc-transport": "^2.11.1", "@protobuf-ts/runtime": "^2.11.1", - "@protobuf-ts/runtime-rpc": "^2.11.1" + "@protobuf-ts/runtime-rpc": "^2.11.1", + "pino": "^10.3.1", + "pino-pretty": "^13.1.3" } }, - "node_modules/@code0-tech/hercules/node_modules/@code0-tech/tucana": { + "node_modules/@code0-tech/tucana": { "version": "0.0.67", "resolved": "https://registry.npmjs.org/@code0-tech/tucana/-/tucana-0.0.67.tgz", "integrity": "sha512-3V1h3LB+iWeXnt80nsIQo+TeMgVTgbDxvDsAArbffHyU37ii1tsAAV6Ty7wAdkrCSsObyFRpdiIZgzgYVVKfzw==", "license": "Apache-2.0" }, - "node_modules/@code0-tech/tucana": { - "version": "0.0.62", - "resolved": "https://registry.npmjs.org/@code0-tech/tucana/-/tucana-0.0.62.tgz", - "integrity": "sha512-OLdGT0FSGxzlaGxVKnnvioaDovNZf1wdwofCoSx8nsT8fe7z24/IQLKSOkEYEF9ds3F8JXim7fiB+k3T2qky8Q==", - "license": "Apache-2.0" - }, "node_modules/@grpc/grpc-js": { "version": "1.14.3", "resolved": "https://registry.npmjs.org/@grpc/grpc-js/-/grpc-js-1.14.3.tgz", @@ -80,6 +75,12 @@ "url": "https://opencollective.com/js-sdsl" } }, + "node_modules/@pinojs/redact": { + "version": "0.4.0", + "resolved": "https://registry.npmjs.org/@pinojs/redact/-/redact-0.4.0.tgz", + "integrity": "sha512-k2ENnmBugE/rzQfEcdWHcCY+/FM3VLzH9cYEsbdsoqrvzAKRhUZeRNhAZvB8OitQJ1TBed3yqWtdjzS6wJKBwg==", + "license": "MIT" + }, "node_modules/@protobuf-ts/grpc-backend": { "version": "2.11.1", "resolved": "https://registry.npmjs.org/@protobuf-ts/grpc-backend/-/grpc-backend-2.11.1.tgz", @@ -218,6 +219,15 @@ "url": "https://github.com/chalk/ansi-styles?sponsor=1" } }, + "node_modules/atomic-sleep": { + "version": "1.0.0", + "resolved": "https://registry.npmjs.org/atomic-sleep/-/atomic-sleep-1.0.0.tgz", + "integrity": "sha512-kNOjDqAh7px0XWNI+4QbzoiR/nTkHAWNud2uvnJquD1/x5a7EQZMJT0AczqK0Qn67oY/TTQ1LbUKajZpp3I9tQ==", + "license": "MIT", + "engines": { + "node": ">=8.0.0" + } + }, "node_modules/cliui": { "version": "8.0.1", "resolved": "https://registry.npmjs.org/cliui/-/cliui-8.0.1.tgz", @@ -250,12 +260,36 @@ "integrity": "sha512-dOy+3AuW3a2wNbZHIuMZpTcgjGuLU/uBL/ubcZF9OXbDo8ff4O8yVp5Bf0efS8uEoYo5q4Fx7dY9OgQGXgAsQA==", "license": "MIT" }, + "node_modules/colorette": { + "version": "2.0.20", + "resolved": "https://registry.npmjs.org/colorette/-/colorette-2.0.20.tgz", + "integrity": "sha512-IfEDxwoWIjkeXL1eXcDiow4UbKjhLdq6/EuSVR9GMN7KVH3r9gQ83e73hsz1Nd1T3ijd5xv1wcWRYO+D6kCI2w==", + "license": "MIT" + }, + "node_modules/dateformat": { + "version": "4.6.3", + "resolved": "https://registry.npmjs.org/dateformat/-/dateformat-4.6.3.tgz", + "integrity": "sha512-2P0p0pFGzHS5EMnhdxQi7aJN+iMheud0UhG4dlE1DLAlvL8JHjJJTX/CSm4JXwV0Ka5nGk3zC5mcb5bUQUxxMA==", + "license": "MIT", + "engines": { + "node": "*" + } + }, "node_modules/emoji-regex": { "version": "8.0.0", "resolved": "https://registry.npmjs.org/emoji-regex/-/emoji-regex-8.0.0.tgz", "integrity": "sha512-MSjYzcWNOA0ewAHpz0MxpYFvwg6yjy1NG3xteoqz644VCo/RPgnr1/GGt+ic3iJTzQ8Eu3TdM14SawnVUmGE6A==", "license": "MIT" }, + "node_modules/end-of-stream": { + "version": "1.4.5", + "resolved": "https://registry.npmjs.org/end-of-stream/-/end-of-stream-1.4.5.tgz", + "integrity": "sha512-ooEGc6HP26xXq/N+GCGOT0JKCLDGrq2bQUZrQ7gyrJiZANJ/8YDTxTpQBXGMn+WbIQXNVpyWymm7KYVICQnyOg==", + "license": "MIT", + "dependencies": { + "once": "^1.4.0" + } + }, "node_modules/escalade": { "version": "3.2.0", "resolved": "https://registry.npmjs.org/escalade/-/escalade-3.2.0.tgz", @@ -265,6 +299,18 @@ "node": ">=6" } }, + "node_modules/fast-copy": { + "version": "4.0.2", + "resolved": "https://registry.npmjs.org/fast-copy/-/fast-copy-4.0.2.tgz", + "integrity": "sha512-ybA6PDXIXOXivLJK/z9e+Otk7ve13I4ckBvGO5I2RRmBU1gMHLVDJYEuJYhGwez7YNlYji2M2DvVU+a9mSFDlw==", + "license": "MIT" + }, + "node_modules/fast-safe-stringify": { + "version": "2.1.1", + "resolved": "https://registry.npmjs.org/fast-safe-stringify/-/fast-safe-stringify-2.1.1.tgz", + "integrity": "sha512-W+KJc2dmILlPplD/H4K9l9LcAHAfPtP6BY84uVLXQ6Evcz9Lcg33Y2z1IVblT6xdY54PXYVHEv+0Wpq8Io6zkA==", + "license": "MIT" + }, "node_modules/get-caller-file": { "version": "2.0.5", "resolved": "https://registry.npmjs.org/get-caller-file/-/get-caller-file-2.0.5.tgz", @@ -274,6 +320,12 @@ "node": "6.* || 8.* || >= 10.*" } }, + "node_modules/help-me": { + "version": "5.0.0", + "resolved": "https://registry.npmjs.org/help-me/-/help-me-5.0.0.tgz", + "integrity": "sha512-7xgomUX6ADmcYzFik0HzAxh/73YlKR9bmFzf51CZwR+b6YtzU2m0u49hQCqV6SvlqIqsaxovfwdvbnsw3b/zpg==", + "license": "MIT" + }, "node_modules/is-fullwidth-code-point": { "version": "3.0.0", "resolved": "https://registry.npmjs.org/is-fullwidth-code-point/-/is-fullwidth-code-point-3.0.0.tgz", @@ -283,6 +335,15 @@ "node": ">=8" } }, + "node_modules/joycon": { + "version": "3.1.1", + "resolved": "https://registry.npmjs.org/joycon/-/joycon-3.1.1.tgz", + "integrity": "sha512-34wB/Y7MW7bzjKRjUKTa46I2Z7eV62Rkhva+KkopW7Qvv/OSWBqvkSY7vusOPrNuZcUG3tApvdVgNB8POj3SPw==", + "license": "MIT", + "engines": { + "node": ">=10" + } + }, "node_modules/lodash.camelcase": { "version": "4.3.0", "resolved": "https://registry.npmjs.org/lodash.camelcase/-/lodash.camelcase-4.3.0.tgz", @@ -295,6 +356,110 @@ "integrity": "sha512-mNAgZ1GmyNhD7AuqnTG3/VQ26o760+ZYBPKjPvugO8+nLbYfX6TVpJPseBvopbdY+qpZ/lKUnmEc1LeZYS3QAA==", "license": "Apache-2.0" }, + "node_modules/minimist": { + "version": "1.2.8", + "resolved": "https://registry.npmjs.org/minimist/-/minimist-1.2.8.tgz", + "integrity": "sha512-2yyAR8qBkN3YuheJanUpWC5U3bb5osDywNB8RzDVlDwDHbocAJveqqj1u8+SVD7jkWT4yvsHCpWqqWqAxb0zCA==", + "license": "MIT", + "funding": { + "url": "https://github.com/sponsors/ljharb" + } + }, + "node_modules/on-exit-leak-free": { + "version": "2.1.2", + "resolved": "https://registry.npmjs.org/on-exit-leak-free/-/on-exit-leak-free-2.1.2.tgz", + "integrity": "sha512-0eJJY6hXLGf1udHwfNftBqH+g73EU4B504nZeKpz1sYRKafAghwxEJunB2O7rDZkL4PGfsMVnTXZ2EjibbqcsA==", + "license": "MIT", + "engines": { + "node": ">=14.0.0" + } + }, + "node_modules/once": { + "version": "1.4.0", + "resolved": "https://registry.npmjs.org/once/-/once-1.4.0.tgz", + "integrity": "sha512-lNaJgI+2Q5URQBkccEKHTQOPaXdUxnZZElQTZY0MFUAuaEqe1E+Nyvgdz/aIyNi6Z9MzO5dv1H8n58/GELp3+w==", + "license": "ISC", + "dependencies": { + "wrappy": "1" + } + }, + "node_modules/pino": { + "version": "10.3.1", + "resolved": "https://registry.npmjs.org/pino/-/pino-10.3.1.tgz", + "integrity": "sha512-r34yH/GlQpKZbU1BvFFqOjhISRo1MNx1tWYsYvmj6KIRHSPMT2+yHOEb1SG6NMvRoHRF0a07kCOox/9yakl1vg==", + "license": "MIT", + "dependencies": { + "@pinojs/redact": "^0.4.0", + "atomic-sleep": "^1.0.0", + "on-exit-leak-free": "^2.1.0", + "pino-abstract-transport": "^3.0.0", + "pino-std-serializers": "^7.0.0", + "process-warning": "^5.0.0", + "quick-format-unescaped": "^4.0.3", + "real-require": "^0.2.0", + "safe-stable-stringify": "^2.3.1", + "sonic-boom": "^4.0.1", + "thread-stream": "^4.0.0" + }, + "bin": { + "pino": "bin.js" + } + }, + "node_modules/pino-abstract-transport": { + "version": "3.0.0", + "resolved": "https://registry.npmjs.org/pino-abstract-transport/-/pino-abstract-transport-3.0.0.tgz", + "integrity": "sha512-wlfUczU+n7Hy/Ha5j9a/gZNy7We5+cXp8YL+X+PG8S0KXxw7n/JXA3c46Y0zQznIJ83URJiwy7Lh56WLokNuxg==", + "license": "MIT", + "dependencies": { + "split2": "^4.0.0" + } + }, + "node_modules/pino-pretty": { + "version": "13.1.3", + "resolved": "https://registry.npmjs.org/pino-pretty/-/pino-pretty-13.1.3.tgz", + "integrity": "sha512-ttXRkkOz6WWC95KeY9+xxWL6AtImwbyMHrL1mSwqwW9u+vLp/WIElvHvCSDg0xO/Dzrggz1zv3rN5ovTRVowKg==", + "license": "MIT", + "dependencies": { + "colorette": "^2.0.7", + "dateformat": "^4.6.3", + "fast-copy": "^4.0.0", + "fast-safe-stringify": "^2.1.1", + "help-me": "^5.0.0", + "joycon": "^3.1.1", + "minimist": "^1.2.6", + "on-exit-leak-free": "^2.1.0", + "pino-abstract-transport": "^3.0.0", + "pump": "^3.0.0", + "secure-json-parse": "^4.0.0", + "sonic-boom": "^4.0.1", + "strip-json-comments": "^5.0.2" + }, + "bin": { + "pino-pretty": "bin.js" + } + }, + "node_modules/pino-std-serializers": { + "version": "7.1.0", + "resolved": "https://registry.npmjs.org/pino-std-serializers/-/pino-std-serializers-7.1.0.tgz", + "integrity": "sha512-BndPH67/JxGExRgiX1dX0w1FvZck5Wa4aal9198SrRhZjH3GxKQUKIBnYJTdj2HDN3UQAS06HlfcSbQj2OHmaw==", + "license": "MIT" + }, + "node_modules/process-warning": { + "version": "5.0.0", + "resolved": "https://registry.npmjs.org/process-warning/-/process-warning-5.0.0.tgz", + "integrity": "sha512-a39t9ApHNx2L4+HBnQKqxxHNs1r7KF+Intd8Q/g1bUh6q0WIp9voPXJ/x0j+ZL45KF1pJd9+q2jLIRMfvEshkA==", + "funding": [ + { + "type": "github", + "url": "https://github.com/sponsors/fastify" + }, + { + "type": "opencollective", + "url": "https://opencollective.com/fastify" + } + ], + "license": "MIT" + }, "node_modules/protobufjs": { "version": "7.5.4", "resolved": "https://registry.npmjs.org/protobufjs/-/protobufjs-7.5.4.tgz", @@ -319,6 +484,31 @@ "node": ">=12.0.0" } }, + "node_modules/pump": { + "version": "3.0.4", + "resolved": "https://registry.npmjs.org/pump/-/pump-3.0.4.tgz", + "integrity": "sha512-VS7sjc6KR7e1ukRFhQSY5LM2uBWAUPiOPa/A3mkKmiMwSmRFUITt0xuj+/lesgnCv+dPIEYlkzrcyXgquIHMcA==", + "license": "MIT", + "dependencies": { + "end-of-stream": "^1.1.0", + "once": "^1.3.1" + } + }, + "node_modules/quick-format-unescaped": { + "version": "4.0.4", + "resolved": "https://registry.npmjs.org/quick-format-unescaped/-/quick-format-unescaped-4.0.4.tgz", + "integrity": "sha512-tYC1Q1hgyRuHgloV/YXs2w15unPVh8qfu/qCTfhTYamaw7fyhumKa2yGpdSo87vY32rIclj+4fWYQXUMs9EHvg==", + "license": "MIT" + }, + "node_modules/real-require": { + "version": "0.2.0", + "resolved": "https://registry.npmjs.org/real-require/-/real-require-0.2.0.tgz", + "integrity": "sha512-57frrGM/OCTLqLOAh0mhVA9VBMHd+9U7Zb2THMGdBUoZVOtGbJzjxsYGDJ3A9AYYCP4hn6y1TVbaOfzWtm5GFg==", + "license": "MIT", + "engines": { + "node": ">= 12.13.0" + } + }, "node_modules/require-directory": { "version": "2.1.1", "resolved": "https://registry.npmjs.org/require-directory/-/require-directory-2.1.1.tgz", @@ -328,6 +518,49 @@ "node": ">=0.10.0" } }, + "node_modules/safe-stable-stringify": { + "version": "2.5.0", + "resolved": "https://registry.npmjs.org/safe-stable-stringify/-/safe-stable-stringify-2.5.0.tgz", + "integrity": "sha512-b3rppTKm9T+PsVCBEOUR46GWI7fdOs00VKZ1+9c1EWDaDMvjQc6tUwuFyIprgGgTcWoVHSKrU8H31ZHA2e0RHA==", + "license": "MIT", + "engines": { + "node": ">=10" + } + }, + "node_modules/secure-json-parse": { + "version": "4.1.0", + "resolved": "https://registry.npmjs.org/secure-json-parse/-/secure-json-parse-4.1.0.tgz", + "integrity": "sha512-l4KnYfEyqYJxDwlNVyRfO2E4NTHfMKAWdUuA8J0yve2Dz/E/PdBepY03RvyJpssIpRFwJoCD55wA+mEDs6ByWA==", + "funding": [ + { + "type": "github", + "url": "https://github.com/sponsors/fastify" + }, + { + "type": "opencollective", + "url": "https://opencollective.com/fastify" + } + ], + "license": "BSD-3-Clause" + }, + "node_modules/sonic-boom": { + "version": "4.2.1", + "resolved": "https://registry.npmjs.org/sonic-boom/-/sonic-boom-4.2.1.tgz", + "integrity": "sha512-w6AxtubXa2wTXAUsZMMWERrsIRAdrK0Sc+FUytWvYAhBJLyuI4llrMIC1DtlNSdI99EI86KZum2MMq3EAZlF9Q==", + "license": "MIT", + "dependencies": { + "atomic-sleep": "^1.0.0" + } + }, + "node_modules/split2": { + "version": "4.2.0", + "resolved": "https://registry.npmjs.org/split2/-/split2-4.2.0.tgz", + "integrity": "sha512-UcjcJOWknrNkF6PLX83qcHM6KHgVKNkV62Y8a5uYDVv9ydGQVwAHMKqHdJje1VTWpljG0WYpCDhrCdAOYH4TWg==", + "license": "ISC", + "engines": { + "node": ">= 10.x" + } + }, "node_modules/string-width": { "version": "4.2.3", "resolved": "https://registry.npmjs.org/string-width/-/string-width-4.2.3.tgz", @@ -354,6 +587,30 @@ "node": ">=8" } }, + "node_modules/strip-json-comments": { + "version": "5.0.3", + "resolved": "https://registry.npmjs.org/strip-json-comments/-/strip-json-comments-5.0.3.tgz", + "integrity": "sha512-1tB5mhVo7U+ETBKNf92xT4hrQa3pm0MZ0PQvuDnWgAAGHDsfp4lPSpiS6psrSiet87wyGPh9ft6wmhOMQ0hDiw==", + "license": "MIT", + "engines": { + "node": ">=14.16" + }, + "funding": { + "url": "https://github.com/sponsors/sindresorhus" + } + }, + "node_modules/thread-stream": { + "version": "4.0.0", + "resolved": "https://registry.npmjs.org/thread-stream/-/thread-stream-4.0.0.tgz", + "integrity": "sha512-4iMVL6HAINXWf1ZKZjIPcz5wYaOdPhtO8ATvZ+Xqp3BTdaqtAwQkNmKORqcIo5YkQqGXq5cwfswDwMqqQNrpJA==", + "license": "MIT", + "dependencies": { + "real-require": "^0.2.0" + }, + "engines": { + "node": ">=20" + } + }, "node_modules/undici-types": { "version": "7.18.2", "resolved": "https://registry.npmjs.org/undici-types/-/undici-types-7.18.2.tgz", @@ -377,6 +634,12 @@ "url": "https://github.com/chalk/wrap-ansi?sponsor=1" } }, + "node_modules/wrappy": { + "version": "1.0.2", + "resolved": "https://registry.npmjs.org/wrappy/-/wrappy-1.0.2.tgz", + "integrity": "sha512-l4Sp/DRseor9wL6EvV2+TuQn63dMkPjZ/sp9XkghTEbV9KlPS1xUsZ3u7/IQO4wxtcFB4bgpQPRcR3QCvezPcQ==", + "license": "ISC" + }, "node_modules/y18n": { "version": "5.0.8", "resolved": "https://registry.npmjs.org/y18n/-/y18n-5.0.8.tgz", diff --git a/ts/examples/simple-example-ts/package.json b/ts/examples/simple-example-ts/package.json index 1108ddd..80046ca 100644 --- a/ts/examples/simple-example-ts/package.json +++ b/ts/examples/simple-example-ts/package.json @@ -11,7 +11,6 @@ "dev": "cd ../.. && npm install && npm run build && npm pack && cd examples/simple-example-ts && npm install ../../code0-tech-hercules-0.0.0.tgz && npx tsx index.ts" }, "dependencies": { - "@code0-tech/hercules": "file:../../code0-tech-hercules-0.0.0.tgz", - "@code0-tech/tucana": "^0.0.62" + "@code0-tech/hercules": "file:../../code0-tech-hercules-0.0.0.tgz" } } diff --git a/ts/package-lock.json b/ts/package-lock.json index bf6863b..5f6a676 100644 --- a/ts/package-lock.json +++ b/ts/package-lock.json @@ -9,12 +9,14 @@ "version": "0.0.0", "license": "ISC", "dependencies": { - "@code0-tech/tucana": "^0.0.67", + "@code0-tech/tucana": "0.0.67", "@grpc/grpc-js": "^1.14.3", "@protobuf-ts/grpc-backend": "^2.11.1", "@protobuf-ts/grpc-transport": "^2.11.1", "@protobuf-ts/runtime": "^2.11.1", - "@protobuf-ts/runtime-rpc": "^2.11.1" + "@protobuf-ts/runtime-rpc": "^2.11.1", + "pino": "^10.3.1", + "pino-pretty": "^13.1.3" }, "devDependencies": { "@types/node": "^25.0.10", @@ -732,6 +734,12 @@ "url": "https://github.com/sponsors/Boshen" } }, + "node_modules/@pinojs/redact": { + "version": "0.4.0", + "resolved": "https://registry.npmjs.org/@pinojs/redact/-/redact-0.4.0.tgz", + "integrity": "sha512-k2ENnmBugE/rzQfEcdWHcCY+/FM3VLzH9cYEsbdsoqrvzAKRhUZeRNhAZvB8OitQJ1TBed3yqWtdjzS6wJKBwg==", + "license": "MIT" + }, "node_modules/@protobuf-ts/grpc-backend": { "version": "2.11.1", "resolved": "https://registry.npmjs.org/@protobuf-ts/grpc-backend/-/grpc-backend-2.11.1.tgz", @@ -1993,6 +2001,15 @@ "node": ">=12" } }, + "node_modules/atomic-sleep": { + "version": "1.0.0", + "resolved": "https://registry.npmjs.org/atomic-sleep/-/atomic-sleep-1.0.0.tgz", + "integrity": "sha512-kNOjDqAh7px0XWNI+4QbzoiR/nTkHAWNud2uvnJquD1/x5a7EQZMJT0AczqK0Qn67oY/TTQ1LbUKajZpp3I9tQ==", + "license": "MIT", + "engines": { + "node": ">=8.0.0" + } + }, "node_modules/balanced-match": { "version": "4.0.4", "resolved": "https://registry.npmjs.org/balanced-match/-/balanced-match-4.0.4.tgz", @@ -2100,6 +2117,12 @@ "integrity": "sha512-dOy+3AuW3a2wNbZHIuMZpTcgjGuLU/uBL/ubcZF9OXbDo8ff4O8yVp5Bf0efS8uEoYo5q4Fx7dY9OgQGXgAsQA==", "license": "MIT" }, + "node_modules/colorette": { + "version": "2.0.20", + "resolved": "https://registry.npmjs.org/colorette/-/colorette-2.0.20.tgz", + "integrity": "sha512-IfEDxwoWIjkeXL1eXcDiow4UbKjhLdq6/EuSVR9GMN7KVH3r9gQ83e73hsz1Nd1T3ijd5xv1wcWRYO+D6kCI2w==", + "license": "MIT" + }, "node_modules/commander": { "version": "4.1.1", "resolved": "https://registry.npmjs.org/commander/-/commander-4.1.1.tgz", @@ -2141,6 +2164,15 @@ "dev": true, "license": "MIT" }, + "node_modules/dateformat": { + "version": "4.6.3", + "resolved": "https://registry.npmjs.org/dateformat/-/dateformat-4.6.3.tgz", + "integrity": "sha512-2P0p0pFGzHS5EMnhdxQi7aJN+iMheud0UhG4dlE1DLAlvL8JHjJJTX/CSm4JXwV0Ka5nGk3zC5mcb5bUQUxxMA==", + "license": "MIT", + "engines": { + "node": "*" + } + }, "node_modules/de-indent": { "version": "1.0.2", "resolved": "https://registry.npmjs.org/de-indent/-/de-indent-1.0.2.tgz", @@ -2192,6 +2224,15 @@ "integrity": "sha512-MSjYzcWNOA0ewAHpz0MxpYFvwg6yjy1NG3xteoqz644VCo/RPgnr1/GGt+ic3iJTzQ8Eu3TdM14SawnVUmGE6A==", "license": "MIT" }, + "node_modules/end-of-stream": { + "version": "1.4.5", + "resolved": "https://registry.npmjs.org/end-of-stream/-/end-of-stream-1.4.5.tgz", + "integrity": "sha512-ooEGc6HP26xXq/N+GCGOT0JKCLDGrq2bQUZrQ7gyrJiZANJ/8YDTxTpQBXGMn+WbIQXNVpyWymm7KYVICQnyOg==", + "license": "MIT", + "dependencies": { + "once": "^1.4.0" + } + }, "node_modules/entities": { "version": "7.0.1", "resolved": "https://registry.npmjs.org/entities/-/entities-7.0.1.tgz", @@ -2290,6 +2331,12 @@ "dev": true, "license": "MIT" }, + "node_modules/fast-copy": { + "version": "4.0.2", + "resolved": "https://registry.npmjs.org/fast-copy/-/fast-copy-4.0.2.tgz", + "integrity": "sha512-ybA6PDXIXOXivLJK/z9e+Otk7ve13I4ckBvGO5I2RRmBU1gMHLVDJYEuJYhGwez7YNlYji2M2DvVU+a9mSFDlw==", + "license": "MIT" + }, "node_modules/fast-deep-equal": { "version": "3.1.3", "resolved": "https://registry.npmjs.org/fast-deep-equal/-/fast-deep-equal-3.1.3.tgz", @@ -2297,6 +2344,12 @@ "dev": true, "license": "MIT" }, + "node_modules/fast-safe-stringify": { + "version": "2.1.1", + "resolved": "https://registry.npmjs.org/fast-safe-stringify/-/fast-safe-stringify-2.1.1.tgz", + "integrity": "sha512-W+KJc2dmILlPplD/H4K9l9LcAHAfPtP6BY84uVLXQ6Evcz9Lcg33Y2z1IVblT6xdY54PXYVHEv+0Wpq8Io6zkA==", + "license": "MIT" + }, "node_modules/fast-uri": { "version": "3.1.0", "resolved": "https://registry.npmjs.org/fast-uri/-/fast-uri-3.1.0.tgz", @@ -2433,6 +2486,12 @@ "he": "bin/he" } }, + "node_modules/help-me": { + "version": "5.0.0", + "resolved": "https://registry.npmjs.org/help-me/-/help-me-5.0.0.tgz", + "integrity": "sha512-7xgomUX6ADmcYzFik0HzAxh/73YlKR9bmFzf51CZwR+b6YtzU2m0u49hQCqV6SvlqIqsaxovfwdvbnsw3b/zpg==", + "license": "MIT" + }, "node_modules/import-lazy": { "version": "4.0.0", "resolved": "https://registry.npmjs.org/import-lazy/-/import-lazy-4.0.0.tgz", @@ -2479,7 +2538,6 @@ "version": "3.1.1", "resolved": "https://registry.npmjs.org/joycon/-/joycon-3.1.1.tgz", "integrity": "sha512-34wB/Y7MW7bzjKRjUKTa46I2Z7eV62Rkhva+KkopW7Qvv/OSWBqvkSY7vusOPrNuZcUG3tApvdVgNB8POj3SPw==", - "dev": true, "license": "MIT", "engines": { "node": ">=10" @@ -2898,6 +2956,15 @@ "url": "https://github.com/sponsors/isaacs" } }, + "node_modules/minimist": { + "version": "1.2.8", + "resolved": "https://registry.npmjs.org/minimist/-/minimist-1.2.8.tgz", + "integrity": "sha512-2yyAR8qBkN3YuheJanUpWC5U3bb5osDywNB8RzDVlDwDHbocAJveqqj1u8+SVD7jkWT4yvsHCpWqqWqAxb0zCA==", + "license": "MIT", + "funding": { + "url": "https://github.com/sponsors/ljharb" + } + }, "node_modules/mlly": { "version": "1.8.2", "resolved": "https://registry.npmjs.org/mlly/-/mlly-1.8.2.tgz", @@ -2977,6 +3044,24 @@ ], "license": "MIT" }, + "node_modules/on-exit-leak-free": { + "version": "2.1.2", + "resolved": "https://registry.npmjs.org/on-exit-leak-free/-/on-exit-leak-free-2.1.2.tgz", + "integrity": "sha512-0eJJY6hXLGf1udHwfNftBqH+g73EU4B504nZeKpz1sYRKafAghwxEJunB2O7rDZkL4PGfsMVnTXZ2EjibbqcsA==", + "license": "MIT", + "engines": { + "node": ">=14.0.0" + } + }, + "node_modules/once": { + "version": "1.4.0", + "resolved": "https://registry.npmjs.org/once/-/once-1.4.0.tgz", + "integrity": "sha512-lNaJgI+2Q5URQBkccEKHTQOPaXdUxnZZElQTZY0MFUAuaEqe1E+Nyvgdz/aIyNi6Z9MzO5dv1H8n58/GELp3+w==", + "license": "ISC", + "dependencies": { + "wrappy": "1" + } + }, "node_modules/path-browserify": { "version": "1.0.1", "resolved": "https://registry.npmjs.org/path-browserify/-/path-browserify-1.0.1.tgz", @@ -3018,6 +3103,79 @@ "url": "https://github.com/sponsors/jonschlinkert" } }, + "node_modules/pino": { + "version": "10.3.1", + "resolved": "https://registry.npmjs.org/pino/-/pino-10.3.1.tgz", + "integrity": "sha512-r34yH/GlQpKZbU1BvFFqOjhISRo1MNx1tWYsYvmj6KIRHSPMT2+yHOEb1SG6NMvRoHRF0a07kCOox/9yakl1vg==", + "license": "MIT", + "dependencies": { + "@pinojs/redact": "^0.4.0", + "atomic-sleep": "^1.0.0", + "on-exit-leak-free": "^2.1.0", + "pino-abstract-transport": "^3.0.0", + "pino-std-serializers": "^7.0.0", + "process-warning": "^5.0.0", + "quick-format-unescaped": "^4.0.3", + "real-require": "^0.2.0", + "safe-stable-stringify": "^2.3.1", + "sonic-boom": "^4.0.1", + "thread-stream": "^4.0.0" + }, + "bin": { + "pino": "bin.js" + } + }, + "node_modules/pino-abstract-transport": { + "version": "3.0.0", + "resolved": "https://registry.npmjs.org/pino-abstract-transport/-/pino-abstract-transport-3.0.0.tgz", + "integrity": "sha512-wlfUczU+n7Hy/Ha5j9a/gZNy7We5+cXp8YL+X+PG8S0KXxw7n/JXA3c46Y0zQznIJ83URJiwy7Lh56WLokNuxg==", + "license": "MIT", + "dependencies": { + "split2": "^4.0.0" + } + }, + "node_modules/pino-pretty": { + "version": "13.1.3", + "resolved": "https://registry.npmjs.org/pino-pretty/-/pino-pretty-13.1.3.tgz", + "integrity": "sha512-ttXRkkOz6WWC95KeY9+xxWL6AtImwbyMHrL1mSwqwW9u+vLp/WIElvHvCSDg0xO/Dzrggz1zv3rN5ovTRVowKg==", + "license": "MIT", + "dependencies": { + "colorette": "^2.0.7", + "dateformat": "^4.6.3", + "fast-copy": "^4.0.0", + "fast-safe-stringify": "^2.1.1", + "help-me": "^5.0.0", + "joycon": "^3.1.1", + "minimist": "^1.2.6", + "on-exit-leak-free": "^2.1.0", + "pino-abstract-transport": "^3.0.0", + "pump": "^3.0.0", + "secure-json-parse": "^4.0.0", + "sonic-boom": "^4.0.1", + "strip-json-comments": "^5.0.2" + }, + "bin": { + "pino-pretty": "bin.js" + } + }, + "node_modules/pino-pretty/node_modules/strip-json-comments": { + "version": "5.0.3", + "resolved": "https://registry.npmjs.org/strip-json-comments/-/strip-json-comments-5.0.3.tgz", + "integrity": "sha512-1tB5mhVo7U+ETBKNf92xT4hrQa3pm0MZ0PQvuDnWgAAGHDsfp4lPSpiS6psrSiet87wyGPh9ft6wmhOMQ0hDiw==", + "license": "MIT", + "engines": { + "node": ">=14.16" + }, + "funding": { + "url": "https://github.com/sponsors/sindresorhus" + } + }, + "node_modules/pino-std-serializers": { + "version": "7.1.0", + "resolved": "https://registry.npmjs.org/pino-std-serializers/-/pino-std-serializers-7.1.0.tgz", + "integrity": "sha512-BndPH67/JxGExRgiX1dX0w1FvZck5Wa4aal9198SrRhZjH3GxKQUKIBnYJTdj2HDN3UQAS06HlfcSbQj2OHmaw==", + "license": "MIT" + }, "node_modules/pirates": { "version": "4.0.7", "resolved": "https://registry.npmjs.org/pirates/-/pirates-4.0.7.tgz", @@ -3112,6 +3270,22 @@ } } }, + "node_modules/process-warning": { + "version": "5.0.0", + "resolved": "https://registry.npmjs.org/process-warning/-/process-warning-5.0.0.tgz", + "integrity": "sha512-a39t9ApHNx2L4+HBnQKqxxHNs1r7KF+Intd8Q/g1bUh6q0WIp9voPXJ/x0j+ZL45KF1pJd9+q2jLIRMfvEshkA==", + "funding": [ + { + "type": "github", + "url": "https://github.com/sponsors/fastify" + }, + { + "type": "opencollective", + "url": "https://opencollective.com/fastify" + } + ], + "license": "MIT" + }, "node_modules/protobufjs": { "version": "7.5.4", "resolved": "https://registry.npmjs.org/protobufjs/-/protobufjs-7.5.4.tgz", @@ -3136,6 +3310,16 @@ "node": ">=12.0.0" } }, + "node_modules/pump": { + "version": "3.0.4", + "resolved": "https://registry.npmjs.org/pump/-/pump-3.0.4.tgz", + "integrity": "sha512-VS7sjc6KR7e1ukRFhQSY5LM2uBWAUPiOPa/A3mkKmiMwSmRFUITt0xuj+/lesgnCv+dPIEYlkzrcyXgquIHMcA==", + "license": "MIT", + "dependencies": { + "end-of-stream": "^1.1.0", + "once": "^1.3.1" + } + }, "node_modules/quansync": { "version": "0.2.11", "resolved": "https://registry.npmjs.org/quansync/-/quansync-0.2.11.tgz", @@ -3153,6 +3337,12 @@ ], "license": "MIT" }, + "node_modules/quick-format-unescaped": { + "version": "4.0.4", + "resolved": "https://registry.npmjs.org/quick-format-unescaped/-/quick-format-unescaped-4.0.4.tgz", + "integrity": "sha512-tYC1Q1hgyRuHgloV/YXs2w15unPVh8qfu/qCTfhTYamaw7fyhumKa2yGpdSo87vY32rIclj+4fWYQXUMs9EHvg==", + "license": "MIT" + }, "node_modules/readdirp": { "version": "4.1.2", "resolved": "https://registry.npmjs.org/readdirp/-/readdirp-4.1.2.tgz", @@ -3167,6 +3357,15 @@ "url": "https://paulmillr.com/funding/" } }, + "node_modules/real-require": { + "version": "0.2.0", + "resolved": "https://registry.npmjs.org/real-require/-/real-require-0.2.0.tgz", + "integrity": "sha512-57frrGM/OCTLqLOAh0mhVA9VBMHd+9U7Zb2THMGdBUoZVOtGbJzjxsYGDJ3A9AYYCP4hn6y1TVbaOfzWtm5GFg==", + "license": "MIT", + "engines": { + "node": ">= 12.13.0" + } + }, "node_modules/require-directory": { "version": "2.1.1", "resolved": "https://registry.npmjs.org/require-directory/-/require-directory-2.1.1.tgz", @@ -3296,6 +3495,31 @@ "fsevents": "~2.3.2" } }, + "node_modules/safe-stable-stringify": { + "version": "2.5.0", + "resolved": "https://registry.npmjs.org/safe-stable-stringify/-/safe-stable-stringify-2.5.0.tgz", + "integrity": "sha512-b3rppTKm9T+PsVCBEOUR46GWI7fdOs00VKZ1+9c1EWDaDMvjQc6tUwuFyIprgGgTcWoVHSKrU8H31ZHA2e0RHA==", + "license": "MIT", + "engines": { + "node": ">=10" + } + }, + "node_modules/secure-json-parse": { + "version": "4.1.0", + "resolved": "https://registry.npmjs.org/secure-json-parse/-/secure-json-parse-4.1.0.tgz", + "integrity": "sha512-l4KnYfEyqYJxDwlNVyRfO2E4NTHfMKAWdUuA8J0yve2Dz/E/PdBepY03RvyJpssIpRFwJoCD55wA+mEDs6ByWA==", + "funding": [ + { + "type": "github", + "url": "https://github.com/sponsors/fastify" + }, + { + "type": "opencollective", + "url": "https://opencollective.com/fastify" + } + ], + "license": "BSD-3-Clause" + }, "node_modules/semver": { "version": "7.5.4", "resolved": "https://registry.npmjs.org/semver/-/semver-7.5.4.tgz", @@ -3319,6 +3543,15 @@ "dev": true, "license": "ISC" }, + "node_modules/sonic-boom": { + "version": "4.2.1", + "resolved": "https://registry.npmjs.org/sonic-boom/-/sonic-boom-4.2.1.tgz", + "integrity": "sha512-w6AxtubXa2wTXAUsZMMWERrsIRAdrK0Sc+FUytWvYAhBJLyuI4llrMIC1DtlNSdI99EI86KZum2MMq3EAZlF9Q==", + "license": "MIT", + "dependencies": { + "atomic-sleep": "^1.0.0" + } + }, "node_modules/source-map": { "version": "0.7.6", "resolved": "https://registry.npmjs.org/source-map/-/source-map-0.7.6.tgz", @@ -3339,6 +3572,15 @@ "node": ">=0.10.0" } }, + "node_modules/split2": { + "version": "4.2.0", + "resolved": "https://registry.npmjs.org/split2/-/split2-4.2.0.tgz", + "integrity": "sha512-UcjcJOWknrNkF6PLX83qcHM6KHgVKNkV62Y8a5uYDVv9ydGQVwAHMKqHdJje1VTWpljG0WYpCDhrCdAOYH4TWg==", + "license": "ISC", + "engines": { + "node": ">= 10.x" + } + }, "node_modules/sprintf-js": { "version": "1.0.3", "resolved": "https://registry.npmjs.org/sprintf-js/-/sprintf-js-1.0.3.tgz", @@ -3484,6 +3726,18 @@ "node": ">=0.8" } }, + "node_modules/thread-stream": { + "version": "4.0.0", + "resolved": "https://registry.npmjs.org/thread-stream/-/thread-stream-4.0.0.tgz", + "integrity": "sha512-4iMVL6HAINXWf1ZKZjIPcz5wYaOdPhtO8ATvZ+Xqp3BTdaqtAwQkNmKORqcIo5YkQqGXq5cwfswDwMqqQNrpJA==", + "license": "MIT", + "dependencies": { + "real-require": "^0.2.0" + }, + "engines": { + "node": ">=20" + } + }, "node_modules/tinybench": { "version": "2.9.0", "resolved": "https://registry.npmjs.org/tinybench/-/tinybench-2.9.0.tgz", @@ -3878,6 +4132,12 @@ "url": "https://github.com/chalk/wrap-ansi?sponsor=1" } }, + "node_modules/wrappy": { + "version": "1.0.2", + "resolved": "https://registry.npmjs.org/wrappy/-/wrappy-1.0.2.tgz", + "integrity": "sha512-l4Sp/DRseor9wL6EvV2+TuQn63dMkPjZ/sp9XkghTEbV9KlPS1xUsZ3u7/IQO4wxtcFB4bgpQPRcR3QCvezPcQ==", + "license": "ISC" + }, "node_modules/y18n": { "version": "5.0.8", "resolved": "https://registry.npmjs.org/y18n/-/y18n-5.0.8.tgz", diff --git a/ts/package.json b/ts/package.json index cef30d2..251652a 100644 --- a/ts/package.json +++ b/ts/package.json @@ -30,12 +30,14 @@ "license": "ISC", "type": "module", "dependencies": { - "@code0-tech/tucana": "^0.0.67", + "@code0-tech/tucana": "0.0.67", "@grpc/grpc-js": "^1.14.3", "@protobuf-ts/grpc-backend": "^2.11.1", "@protobuf-ts/grpc-transport": "^2.11.1", "@protobuf-ts/runtime": "^2.11.1", - "@protobuf-ts/runtime-rpc": "^2.11.1" + "@protobuf-ts/runtime-rpc": "^2.11.1", + "pino": "^10.3.1", + "pino-pretty": "^13.1.3" }, "devDependencies": { "@types/node": "^25.0.10", diff --git a/ts/src/action_sdk.ts b/ts/src/action_sdk.ts index d7d6ad8..f8c1137 100644 --- a/ts/src/action_sdk.ts +++ b/ts/src/action_sdk.ts @@ -21,6 +21,7 @@ import { FlowTypeSetting, } from "@code0-tech/tucana/shared"; import {constructValue, toAllowedValue} from "@code0-tech/tucana/helpers"; +import {logger} from "./logger"; const createSdk = (config: ActionSdk["config"], configDefinitions?: HerculesActionConfigurationDefinition[]): ActionSdk => { const transport = new GrpcTransport( @@ -278,9 +279,13 @@ async function connect(state: SdkState, config: ActionSdk["config"], options?: R return Promise.reject(value.response); } }).catch(reason => { + logger.error({ + err: reason, + config, + }, "Error while updating data types") return Promise.reject(reason); }) - + logger.debug("Sent data types request") await state.stream.requests.send( TransferRequest.create({ @@ -295,9 +300,15 @@ async function connect(state: SdkState, config: ActionSdk["config"], options?: R } ), ).catch(reason => { + logger.error({ + err: reason, + config, + }, "Failed to send logon request") return Promise.reject(reason); }) + logger.debug("Successfully sent logon request") + const runtimeFunctionDefinitionClient = new RuntimeFunctionDefinitionServiceClient(state.transport) await runtimeFunctionDefinitionClient.update( RuntimeFunctionDefinitionUpdateRequest.create( @@ -311,26 +322,46 @@ async function connect(state: SdkState, config: ActionSdk["config"], options?: R ), builtOptions ).then(value => { if (!value.response.success) { + logger.error({ + err: value.response, + request: value.request, + config, + }) return Promise.reject(value.response); } }) + logger.debug("Successfully updated runtime function definitions") const FunctionDefinitionClient = new FunctionDefinitionServiceClient(state.transport) - await FunctionDefinitionClient.update( - FunctionDefinitionUpdateRequest.create( - { - functions: [ - ...state.functions.map(func => ({ - ...func.definition, - })) - ] - } - ), builtOptions - ).then(value => { - if (!value.response.success) { - return Promise.reject(value.response); + try { + const finishedCall = await FunctionDefinitionClient.update( + FunctionDefinitionUpdateRequest.create( + { + functions: [ + ...state.functions.map(func => ({ + ...func.definition, + })) + ] + } + ), builtOptions + ); + + if (!finishedCall.response.success) { + logger.error({ + err: finishedCall.response, + request: finishedCall.request, + config, + }, "Error while updating function definitions") + return Promise.reject(finishedCall.response); } - }) + } catch (error) { + logger.error({ + err: error, + config, + }, "Error while updating function definitions") + return Promise.reject(error); + } + logger.debug("Updated function definitions") const flowTypeClient = new FlowTypeServiceClient(state.transport) await flowTypeClient.update(FlowTypeUpdateRequest.create({ @@ -339,18 +370,29 @@ async function connect(state: SdkState, config: ActionSdk["config"], options?: R ] }), builtOptions).then(value => { if (!value.response.success) { + logger.error({ + err: value.response, + request: value.request, + config, + }) return Promise.reject(value.response); } }) + logger.info("Connected successfully to aquila") return new Promise(async (resolve, reject) => { try { for await (let message of state?.stream?.responses || []) { + logger.debug({ + message: message, + config, + }, "Received message from stream") switch (message?.data.oneofKind) { case "actionConfigurations": { + logger.info("Received action configurations") + const configs = message.data.actionConfigurations as ActionConfigurations; - console.log("Received action configurations:", configs); state.projectConfigurations = configs.actionConfigurations resolve(state.projectConfigurations.map(value => { return { @@ -371,12 +413,25 @@ async function connect(state: SdkState, config: ActionSdk["config"], options?: R break; } case "execution": { + logger.info({ + executionD: message.data.execution.executionIdentifier, + config, + }, "Handling execution request") + + logger.debug({ + message: message, + config, + }, "Handling execution request") handleExecutionRequest(state, message) break; } } } } catch (reason) { + logger.error({ + err: reason, + config + }, "Error occurred in stream") reject(reason); } }) @@ -388,100 +443,168 @@ function handleExecutionRequest(state: SdkState, message: TransferResponse) { } const execution = message.data.execution as ExecutionRequest; const func = state.runtimeFunctions.find(value => value.identifier == execution.functionIdentifier); - if (func) { - const params = Object.entries(execution.parameters!.fields!).map(([key, value]) => { - const param = func.definition.runtimeParameterDefinitions - .find(p => p.runtimeName === key); - return param ? toAllowedValue(value) : undefined; - }); - const conf = state.projectConfigurations.find(config => { - return true - }) - if (!conf) { - console.error(`No configuration found for project ${execution.projectId}`) - return; + if (!func) { + logger.warn({ + message + }, "Received execution request but no matching function found") + return; + } + + const params = Object.entries(execution.parameters!.fields!).map(([key, value]) => { + const param = func.definition.runtimeParameterDefinitions + .find(p => p.runtimeName === key); + + const parameterValue = param ? toAllowedValue(value) : undefined; + if (!parameterValue) return parameterValue + return parameterValue; + }); + + logger.debug({ + message, + BuiltParameter: params + }) + + let conf = state.projectConfigurations.find(config => { + //TODO + return true + }) + + if (!conf) { + logger.error({ + message, + execution + }, "No configuration found") + conf = { + projectId: 0n, + actionConfigurations: [] } + } + logger.debug({ + message, + conf + }) - const context: HerculesFunctionContext = { - projectId: execution.projectId, - executionId: execution.executionIdentifier, - matchedConfig: { - projectId: conf.projectId, - configValues: conf.actionConfigurations.map(value => { - return { - identifier: value.identifier, - value: toAllowedValue(value.value || constructValue(null)), - } - }), - findConfig: identifier => { - const config = conf.actionConfigurations.find(config => config.identifier === identifier); - return config ? toAllowedValue(config.value || constructValue(null)) : undefined; + const context: HerculesFunctionContext = { + projectId: execution.projectId, + executionId: execution.executionIdentifier, + matchedConfig: { + projectId: conf.projectId, + configValues: conf.actionConfigurations.map(value => { + return { + identifier: value.identifier, + value: toAllowedValue(value.value || constructValue(null)), } + }), + findConfig: identifier => { + const config = conf.actionConfigurations.find(config => config.identifier === identifier); + return config ? toAllowedValue(config.value || constructValue(null)) : undefined; } } + } - if (func.handler.length == params.length + 1) { - // handler has context parameter - params.unshift(context) - } else if (func.handler.length > params.length + 1) { - console.error("Handler has more parameters than provided arguments. This may lead to unexpected behavior.") - return; - } + if (func.handler.length == params.length + 1) { + // handler has context parameter + params.unshift(context) + } else if (func.handler.length > params.length + 1) { + logger.error({ + params, + func, + }, "Handler has more parameters than provided arguments") + return; + } - const result = new Promise((resolve, reject) => { - try { - resolve(func.handler(...params)) - } catch (e) { - reject(e) + const result = new Promise((resolve, reject) => { + try { + resolve(func.handler(...params)) + } catch (e) { + reject(e) + } + }) + result.then((value: any) => { + const request = TransferRequest.create({ + data: { + oneofKind: "result", + result: { + executionIdentifier: execution.executionIdentifier, + result: { + oneofKind: "success", + success: constructValue(value) + }, + } } - }) - result.then((value: any) => { - state.stream!.requests.send( - TransferRequest.create({ - data: { - oneofKind: "result", + }); + logger.debug({ + request: request + }, "Responding with execution result") + + state.stream!.requests.send(request).catch(reason => { + logger.error({ + err: reason, + request: request, + message, + execution + }, "Responding with execution result lead to error") + }); + }).catch(reason => { + logger.warn({ + err: reason + }, "Executed function lead to error") + let request + if (reason instanceof RuntimeErrorException) { + request = TransferRequest.create({ + data: { + oneofKind: "result", + result: { + executionIdentifier: execution.executionIdentifier, result: { - executionIdentifier: execution.executionIdentifier, - result: { - oneofKind: "success", - success: constructValue(value) - }, - } + oneofKind: "error", + error: { + code: reason.code, + description: reason.description + } + }, } - }) - ).catch(reason => { - console.error(`Failed to send execution result for execution ${execution.executionIdentifier}:`, reason); + } }); - }).catch(reason => { - if (reason instanceof RuntimeErrorException) { - state.stream!.requests.send( - TransferRequest.create({ - data: { - oneofKind: "result", - result: { - executionIdentifier: execution.executionIdentifier, - result: { - oneofKind: "error", - error: { - code: reason.code, - description: reason.description - } - }, + } else { + request = TransferRequest.create({ + data: { + oneofKind: "result", + result: { + executionIdentifier: execution.executionIdentifier, + result: { + oneofKind: "error", + error: { + code: "UNKNOWN_ERROR", + description: reason.toString() } - } - }) - ).catch(reason => { - console.error(`Failed to send execution result for execution ${execution.executionIdentifier}:`, reason); - }); - - } else { - console.error(`Error executing function ${func?.identifier} for execution ${execution.executionIdentifier}:`, reason); - } - }) + }, + } + } + }); + logger.warn({ + err: reason, + func, + execution + }, "Error occured while executing function, but not an RuntimeErrorException") + } + logger.debug({ + request: request + }, "Responding with execution error") - } + state.stream!.requests.send( + request + ).catch(reason => { + logger.error({ + err: reason, + request: request, + execution, + message + }, "Failed to send execution result error") + }); + }) } export { diff --git a/ts/src/logger.ts b/ts/src/logger.ts new file mode 100644 index 0000000..a196c63 --- /dev/null +++ b/ts/src/logger.ts @@ -0,0 +1,12 @@ +import pino from 'pino'; + +export const logger = pino({ + redact: ["config.authToken"], + level: process.env.LOG_LEVEL || "debug", + transport: { + target: 'pino-pretty', + options: { + colorize: true + } + } +}); \ No newline at end of file