@kaleido-io/workflow-engine-sdk 0.9.2 → 0.9.4
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/README.md +486 -362
- package/bin/init.js +14 -15
- package/dist/src/client/client.d.ts +22 -0
- package/dist/src/client/client.d.ts.map +1 -1
- package/dist/src/client/client.js +1 -0
- package/dist/src/client/client.js.map +1 -1
- package/dist/src/client/client_factory.d.ts +14 -0
- package/dist/src/client/client_factory.d.ts.map +1 -0
- package/dist/src/client/client_factory.js +64 -0
- package/dist/src/client/client_factory.js.map +1 -0
- package/dist/src/client/rest-client.d.ts.map +1 -1
- package/dist/src/client/rest-client.js +1 -1
- package/dist/src/client/rest-client.js.map +1 -1
- package/dist/src/config/config.d.ts +81 -1
- package/dist/src/config/config.d.ts.map +1 -1
- package/dist/src/config/config.js +269 -24
- package/dist/src/config/config.js.map +1 -1
- package/dist/src/config/config_helpers.d.ts +44 -0
- package/dist/src/config/config_helpers.d.ts.map +1 -0
- package/dist/src/config/config_helpers.js +68 -0
- package/dist/src/config/config_helpers.js.map +1 -0
- package/dist/src/helpers/stage_director.js +2 -2
- package/dist/src/i18n/errors.d.ts +5 -0
- package/dist/src/i18n/errors.d.ts.map +1 -1
- package/dist/src/i18n/errors.js +8 -3
- package/dist/src/i18n/errors.js.map +1 -1
- package/dist/src/index.d.ts +3 -2
- package/dist/src/index.d.ts.map +1 -1
- package/dist/src/index.js +5 -1
- package/dist/src/index.js.map +1 -1
- package/dist/src/runtime/handler_runtime.d.ts +22 -0
- package/dist/src/runtime/handler_runtime.d.ts.map +1 -1
- package/dist/src/runtime/handler_runtime.js +43 -3
- package/dist/src/runtime/handler_runtime.js.map +1 -1
- package/dist/src/utils/patch.d.ts +1 -1
- package/dist-esm/src/client/client.js +2 -1
- package/dist-esm/src/client/client.js.map +1 -1
- package/dist-esm/src/client/client_factory.js +60 -0
- package/dist-esm/src/client/client_factory.js.map +1 -0
- package/dist-esm/src/client/rest-client.js +1 -1
- package/dist-esm/src/client/rest-client.js.map +1 -1
- package/dist-esm/src/config/config.js +235 -25
- package/dist-esm/src/config/config.js.map +1 -1
- package/dist-esm/src/config/config_helpers.js +61 -0
- package/dist-esm/src/config/config_helpers.js.map +1 -0
- package/dist-esm/src/helpers/stage_director.js +2 -2
- package/dist-esm/src/i18n/errors.js +8 -3
- package/dist-esm/src/i18n/errors.js.map +1 -1
- package/dist-esm/src/index.js +2 -1
- package/dist-esm/src/index.js.map +1 -1
- package/dist-esm/src/runtime/handler_runtime.js +38 -2
- package/dist-esm/src/runtime/handler_runtime.js.map +1 -1
- package/dist-esm/src/utils/patch.js +2 -2
- package/package.json +1 -1
- package/template/README.md +5 -8
- package/template/config/config.yaml +12 -0
- package/template/config/wfe-config.yaml +12 -0
- package/template/package-lock.json +1908 -0
- package/template/package.json +4 -2
- package/template/src/connect.ts +35 -37
- package/template/src/provider.ts +4 -4
- package/template/src/samples/event-source/echo-handler.ts +2 -2
- package/template/src/samples/event-source/event-processor.ts +1 -1
- package/template/src/samples/event-source/event-source.ts +1 -1
- package/template/src/samples/event-source/stream.ts +11 -11
- package/template/src/samples/hello/flow.ts +36 -36
- package/template/src/samples/hello/handlers.ts +2 -2
- package/template/src/samples/hello/transaction.ts +4 -4
- package/template/src/samples/http-invoke/flow.ts +29 -29
- package/template/src/samples/http-invoke/handlers.ts +88 -39
- package/template/src/samples/http-invoke/transaction.ts +3 -3
- package/template/src/samples/snap/event-source.ts +1 -1
- package/template/src/samples/snap/flow.ts +40 -40
- package/template/src/samples/snap/snap-handler.ts +2 -2
- package/template/src/samples/snap/transaction.ts +6 -6
- package/template/.env.sample +0 -14
package/template/package.json
CHANGED
|
@@ -16,6 +16,7 @@
|
|
|
16
16
|
},
|
|
17
17
|
"private": true,
|
|
18
18
|
"devDependencies": {
|
|
19
|
+
"@types/js-yaml": "^4.0.9",
|
|
19
20
|
"@vitest/coverage-v8": "^4.0.16",
|
|
20
21
|
"tsx": "^4.21.0",
|
|
21
22
|
"typescript": "^5.9.3",
|
|
@@ -28,9 +29,10 @@
|
|
|
28
29
|
"README.md"
|
|
29
30
|
],
|
|
30
31
|
"dependencies": {
|
|
31
|
-
"@kaleido-io/workflow-engine-sdk": "^
|
|
32
|
+
"@kaleido-io/workflow-engine-sdk": "^0.9.4",
|
|
32
33
|
"dotenv": "^17.2.3",
|
|
34
|
+
"js-yaml": "^4.1.1",
|
|
33
35
|
"web3": "^4.16.0",
|
|
34
36
|
"ws": "^8.18.0"
|
|
35
37
|
}
|
|
36
|
-
}
|
|
38
|
+
}
|
package/template/src/connect.ts
CHANGED
|
@@ -14,45 +14,43 @@
|
|
|
14
14
|
// See the License for the specific language governing permissions and
|
|
15
15
|
// limitations under the License.
|
|
16
16
|
|
|
17
|
-
|
|
18
17
|
import {
|
|
19
18
|
newDirectedTransactionHandler,
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
import { actionMap as
|
|
27
|
-
import {
|
|
28
|
-
import {
|
|
29
|
-
import {
|
|
30
|
-
import {
|
|
31
|
-
import { eventSource as dealerEventSource } from './samples/snap/event-source.js';
|
|
19
|
+
NewWorkflowEngineClient,
|
|
20
|
+
HandlerSetFor,
|
|
21
|
+
} from "@kaleido-io/workflow-engine-sdk";
|
|
22
|
+
import dotenv from "dotenv";
|
|
23
|
+
|
|
24
|
+
import { actionMap as helloActionMap } from "./samples/hello/handlers.js";
|
|
25
|
+
import { actionMap as httpInvokeActionMap } from "./samples/http-invoke/handlers.js";
|
|
26
|
+
import { eventSource } from "./samples/event-source/event-source.js";
|
|
27
|
+
import { actionMap as snapActionMap } from "./samples/snap/snap-handler.js";
|
|
28
|
+
import { echoEventProcessor } from "./samples/event-source/event-processor.js";
|
|
29
|
+
import { eventSource as dealerEventSource } from "./samples/snap/event-source.js";
|
|
32
30
|
|
|
33
31
|
dotenv.config();
|
|
34
|
-
const wsUrl = `wss://${process.env.ACCOUNT}/endpoint/${process.env.ENVIRONMENT}/${process.env.WORKFLOW_ENGINE}/rest/ws`;
|
|
35
|
-
const client = new WorkflowEngineClient({
|
|
36
|
-
url: wsUrl,
|
|
37
|
-
authHeaderName: 'Authorization',
|
|
38
|
-
authToken: `basic ${Buffer.from(`${process.env.KEY_NAME}:${process.env.KEY_VALUE}`).toString("base64")}`,
|
|
39
|
-
providerName: provider.name,
|
|
40
|
-
providerMetadata: provider.metadata ?? {},
|
|
41
|
-
reconnectDelay: 2000,
|
|
42
|
-
});
|
|
43
|
-
|
|
44
|
-
const helloHandler = newDirectedTransactionHandler('hello', helloActionMap);
|
|
45
|
-
client.registerTransactionHandler('hello', helloHandler);
|
|
46
|
-
|
|
47
|
-
const httpInvokeHandler = newDirectedTransactionHandler('http-invoke', httpInvokeActionMap);
|
|
48
|
-
client.registerTransactionHandler('http-invoke', httpInvokeHandler);
|
|
49
|
-
|
|
50
|
-
client.registerEventProcessor('echo', echoEventProcessor);
|
|
51
|
-
client.registerEventSource('my-listener', eventSource);
|
|
52
|
-
|
|
53
|
-
const snapHandler = newDirectedTransactionHandler('snap-watcher', snapActionMap);
|
|
54
|
-
client.registerTransactionHandler('snap-watcher', snapHandler);
|
|
55
|
-
|
|
56
|
-
client.registerEventSource('snap-dealer', dealerEventSource);
|
|
57
32
|
|
|
58
|
-
|
|
33
|
+
const helloHandler = newDirectedTransactionHandler("hello", helloActionMap);
|
|
34
|
+
const httpInvokeHandler = newDirectedTransactionHandler(
|
|
35
|
+
"http-invoke",
|
|
36
|
+
httpInvokeActionMap,
|
|
37
|
+
);
|
|
38
|
+
const snapHandler = newDirectedTransactionHandler(
|
|
39
|
+
"snap-watcher",
|
|
40
|
+
snapActionMap,
|
|
41
|
+
);
|
|
42
|
+
|
|
43
|
+
const client = await NewWorkflowEngineClient(
|
|
44
|
+
HandlerSetFor(
|
|
45
|
+
helloHandler,
|
|
46
|
+
httpInvokeHandler,
|
|
47
|
+
echoEventProcessor,
|
|
48
|
+
eventSource,
|
|
49
|
+
snapHandler,
|
|
50
|
+
dealerEventSource,
|
|
51
|
+
),
|
|
52
|
+
process.env.WFE_CONFIG_FILE ?? "./config/wfe-config.yaml",
|
|
53
|
+
);
|
|
54
|
+
|
|
55
|
+
process.on("SIGINT", () => client.disconnect());
|
|
56
|
+
process.on("SIGTERM", () => client.disconnect());
|
package/template/src/provider.ts
CHANGED
|
@@ -16,9 +16,9 @@
|
|
|
16
16
|
|
|
17
17
|
|
|
18
18
|
export default {
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
19
|
+
'name': 'example-provider',
|
|
20
|
+
'metadata': {
|
|
21
|
+
'displayName': 'Example provider',
|
|
22
|
+
'description': 'An example provider for the Kaleido Workflow Engine'
|
|
23
23
|
}
|
|
24
24
|
}
|
|
@@ -15,7 +15,7 @@
|
|
|
15
15
|
// limitations under the License.
|
|
16
16
|
|
|
17
17
|
|
|
18
|
-
import { BasicStageDirector, DirectedActionConfig, EvalResult, InvocationMode, WithStageDirector, WSEvaluateTransaction } from
|
|
18
|
+
import { BasicStageDirector, DirectedActionConfig, EvalResult, InvocationMode, WithStageDirector, WSEvaluateTransaction } from '@kaleido-io/workflow-engine-sdk';
|
|
19
19
|
|
|
20
20
|
class MyHandlerInput implements WithStageDirector {
|
|
21
21
|
public stageDirector: BasicStageDirector;
|
|
@@ -43,7 +43,7 @@ class MyHandlerInput implements WithStageDirector {
|
|
|
43
43
|
}
|
|
44
44
|
|
|
45
45
|
const map: Map<string, DirectedActionConfig<MyHandlerInput>> = new Map([
|
|
46
|
-
[
|
|
46
|
+
['echo', {
|
|
47
47
|
invocationMode: InvocationMode.PARALLEL, handler: async (transaction: WSEvaluateTransaction) => {
|
|
48
48
|
if (transaction.state?.input?.data === undefined || transaction.state?.input?.data?.message === undefined) {
|
|
49
49
|
return {
|
|
@@ -14,7 +14,7 @@
|
|
|
14
14
|
// See the License for the specific language governing permissions and
|
|
15
15
|
// limitations under the License.
|
|
16
16
|
|
|
17
|
-
import { EngineAPI, WSEventProcessorBatchRequest, WSEventProcessorBatchResult } from
|
|
17
|
+
import { EngineAPI, WSEventProcessorBatchRequest, WSEventProcessorBatchResult } from '@kaleido-io/workflow-engine-sdk';
|
|
18
18
|
|
|
19
19
|
export class MyEventProcessor {
|
|
20
20
|
|
|
@@ -15,7 +15,7 @@
|
|
|
15
15
|
// limitations under the License.
|
|
16
16
|
|
|
17
17
|
|
|
18
|
-
import { EventSourceConf, EventSourceEvent, newEventSource, newLogger, WSEventStreamInfo } from
|
|
18
|
+
import { EventSourceConf, EventSourceEvent, newEventSource, newLogger, WSEventStreamInfo } from '@kaleido-io/workflow-engine-sdk';
|
|
19
19
|
|
|
20
20
|
const log = newLogger('event-source');
|
|
21
21
|
|
|
@@ -18,17 +18,17 @@
|
|
|
18
18
|
import provider from '../../provider.js';
|
|
19
19
|
|
|
20
20
|
export const stream = {
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
21
|
+
'name': 'event-echo-stream',
|
|
22
|
+
'description': 'Listen for events from the custom event source and pass them to the echo event processor',
|
|
23
|
+
'type': 'event_stream',
|
|
24
|
+
'config': {
|
|
25
|
+
'pollingInterval': '2s'
|
|
26
26
|
},
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
27
|
+
'listenerHandler': 'my-listener',
|
|
28
|
+
'listenerHandlerProvider': provider.name,
|
|
29
|
+
'eventHandler': 'echo',
|
|
30
|
+
'eventHandlerProvider': provider.name,
|
|
31
|
+
'postFilter': {
|
|
32
|
+
'jsonata': 'true'
|
|
33
33
|
}
|
|
34
34
|
}
|
|
@@ -17,58 +17,58 @@
|
|
|
17
17
|
|
|
18
18
|
import provider from '../../provider.js';
|
|
19
19
|
export const flow = {
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
20
|
+
'name': 'hello-flow',
|
|
21
|
+
'description': '',
|
|
22
|
+
'labels': {},
|
|
23
|
+
'handlerBindings': {
|
|
24
|
+
'hello': {
|
|
25
|
+
'provider': provider.name,
|
|
26
|
+
'providerHandler': 'hello'
|
|
27
27
|
}
|
|
28
28
|
},
|
|
29
|
-
|
|
30
|
-
|
|
29
|
+
'version': '1.0.0',
|
|
30
|
+
'operations': [
|
|
31
31
|
{
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
32
|
+
'name': 'hello',
|
|
33
|
+
'description': 'Hello',
|
|
34
|
+
'type': 'asynchronous',
|
|
35
|
+
'stage': 'my-beginning-state',
|
|
36
|
+
'stateUpdates': null,
|
|
37
|
+
'inputSchema': {
|
|
38
|
+
'type': 'object',
|
|
39
|
+
'properties': {
|
|
40
|
+
'name': {
|
|
41
|
+
'type': [
|
|
42
|
+
'string'
|
|
43
43
|
]
|
|
44
44
|
}
|
|
45
45
|
},
|
|
46
|
-
|
|
47
|
-
|
|
46
|
+
'required': [
|
|
47
|
+
'name'
|
|
48
48
|
],
|
|
49
|
-
|
|
49
|
+
'additionalProperties': false
|
|
50
50
|
}
|
|
51
51
|
}
|
|
52
52
|
],
|
|
53
|
-
|
|
53
|
+
'stages': [
|
|
54
54
|
{
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
55
|
+
'name': 'my-beginning-state',
|
|
56
|
+
'type': 'pending',
|
|
57
|
+
'handler': 'hello',
|
|
58
|
+
'inputMap': {
|
|
59
|
+
'jsonata': '{\n "action": "hello",\n "invoke": {\n "input": state.input\n },\n "nextStage": "end",\n "failureStage": "failure",\n "outputPath": "/output"\n}\n'
|
|
60
60
|
},
|
|
61
|
-
|
|
61
|
+
'fullState': true
|
|
62
62
|
},
|
|
63
63
|
{
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
64
|
+
'name': 'end',
|
|
65
|
+
'type': 'success',
|
|
66
|
+
'handler': ''
|
|
67
67
|
},
|
|
68
68
|
{
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
69
|
+
'name': 'failure',
|
|
70
|
+
'type': 'failure',
|
|
71
|
+
'handler': ''
|
|
72
72
|
}
|
|
73
73
|
]
|
|
74
74
|
}
|
|
@@ -15,7 +15,7 @@
|
|
|
15
15
|
// limitations under the License.
|
|
16
16
|
|
|
17
17
|
|
|
18
|
-
import { BasicStageDirector, DirectedActionConfig, EvalResult, InvocationMode, WithStageDirector, WSEvaluateTransaction } from
|
|
18
|
+
import { BasicStageDirector, DirectedActionConfig, EvalResult, InvocationMode, WithStageDirector, WSEvaluateTransaction } from '@kaleido-io/workflow-engine-sdk';
|
|
19
19
|
|
|
20
20
|
class MyHandlerInput implements WithStageDirector {
|
|
21
21
|
public stageDirector: BasicStageDirector;
|
|
@@ -43,7 +43,7 @@ class MyHandlerInput implements WithStageDirector {
|
|
|
43
43
|
}
|
|
44
44
|
|
|
45
45
|
const map: Map<string, DirectedActionConfig<MyHandlerInput>> = new Map([
|
|
46
|
-
[
|
|
46
|
+
['hello', {
|
|
47
47
|
invocationMode: InvocationMode.PARALLEL, handler: async (transaction: WSEvaluateTransaction) => {
|
|
48
48
|
if (transaction.state?.input?.name === undefined) {
|
|
49
49
|
return {
|
|
@@ -16,9 +16,9 @@
|
|
|
16
16
|
|
|
17
17
|
|
|
18
18
|
export const transaction = {
|
|
19
|
-
|
|
20
|
-
|
|
19
|
+
'input': {
|
|
20
|
+
'name': 'workflow engine developer'
|
|
21
21
|
},
|
|
22
|
-
|
|
23
|
-
|
|
22
|
+
'operation': 'hello',
|
|
23
|
+
'workflow': 'hello-flow'
|
|
24
24
|
}
|
|
@@ -17,47 +17,47 @@
|
|
|
17
17
|
|
|
18
18
|
import provider from '../../provider.js';
|
|
19
19
|
export const flow = {
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
20
|
+
'name': 'http-invoke-flow',
|
|
21
|
+
'description': '',
|
|
22
|
+
'labels': {},
|
|
23
|
+
'handlerBindings': {
|
|
24
|
+
'http-invoke': {
|
|
25
|
+
'provider': provider.name,
|
|
26
|
+
'providerHandler': 'http-invoke'
|
|
27
27
|
}
|
|
28
28
|
},
|
|
29
|
-
|
|
30
|
-
|
|
29
|
+
'version': '1.0.0',
|
|
30
|
+
'operations': [
|
|
31
31
|
{
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
32
|
+
'name': 'http-invoke',
|
|
33
|
+
'description': 'HTTP Invoke',
|
|
34
|
+
'type': 'asynchronous',
|
|
35
|
+
'stage': 'start',
|
|
36
|
+
'inputSchema': {
|
|
37
|
+
'type': 'object',
|
|
38
|
+
'additionalProperties': true
|
|
39
39
|
}
|
|
40
40
|
}
|
|
41
41
|
],
|
|
42
|
-
|
|
42
|
+
'stages': [
|
|
43
43
|
{
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
44
|
+
'name': 'start',
|
|
45
|
+
'type': 'pending',
|
|
46
|
+
'handler': 'http-invoke',
|
|
47
|
+
'inputMap': {
|
|
48
|
+
'jsonata': '{\n "action": "http-invoke",\n "invoke": {\n "input": state.input\n },\n "nextStage": "end",\n "failureStage": "failure",\n "outputPath": "/output"\n}\n'
|
|
49
49
|
},
|
|
50
|
-
|
|
50
|
+
'fullState': true
|
|
51
51
|
},
|
|
52
52
|
{
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
53
|
+
'name': 'end',
|
|
54
|
+
'type': 'success',
|
|
55
|
+
'handler': ''
|
|
56
56
|
},
|
|
57
57
|
{
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
58
|
+
'name': 'failure',
|
|
59
|
+
'type': 'failure',
|
|
60
|
+
'handler': ''
|
|
61
61
|
}
|
|
62
62
|
]
|
|
63
63
|
}
|
|
@@ -14,53 +14,102 @@
|
|
|
14
14
|
// See the License for the specific language governing permissions and
|
|
15
15
|
// limitations under the License.
|
|
16
16
|
|
|
17
|
+
import * as fs from 'fs';
|
|
18
|
+
import * as path from 'path';
|
|
19
|
+
import yaml from 'js-yaml';
|
|
20
|
+
import {
|
|
21
|
+
BasicStageDirector,
|
|
22
|
+
DirectedActionConfig,
|
|
23
|
+
EvalResult,
|
|
24
|
+
InvocationMode,
|
|
25
|
+
WithStageDirector,
|
|
26
|
+
} from '@kaleido-io/workflow-engine-sdk';
|
|
17
27
|
|
|
18
|
-
|
|
28
|
+
export interface HTTPInvokeConfig {
|
|
29
|
+
url: string;
|
|
30
|
+
invocationMode: keyof typeof InvocationMode;
|
|
31
|
+
apiKeyHeader: string;
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
function resolveAppConfigPath(): string | undefined {
|
|
35
|
+
const fromEnv = process.env.CONFIG_FILE?.trim();
|
|
36
|
+
const candidates = [
|
|
37
|
+
fromEnv,
|
|
38
|
+
path.join(process.cwd(), 'src', 'config', 'config.yaml'),
|
|
39
|
+
path.join(process.cwd(), 'config', 'config.yaml'),
|
|
40
|
+
].filter(Boolean) as string[];
|
|
41
|
+
for (const p of candidates) {
|
|
42
|
+
if (fs.existsSync(p)) {
|
|
43
|
+
return p;
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
return undefined;
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
function loadAppConfig(): { httpInvoke?: HTTPInvokeConfig } {
|
|
50
|
+
const configPath = resolveAppConfigPath();
|
|
51
|
+
if (!configPath) {
|
|
52
|
+
return {};
|
|
53
|
+
}
|
|
54
|
+
const raw = fs.readFileSync(configPath, 'utf8');
|
|
55
|
+
return yaml.load(raw) as { httpInvoke?: HTTPInvokeConfig };
|
|
56
|
+
}
|
|
19
57
|
|
|
20
58
|
class HTTPInvokeHandlerInput implements WithStageDirector {
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
59
|
+
public stageDirector: BasicStageDirector;
|
|
60
|
+
public action1?: { inputA: string };
|
|
61
|
+
public action2?: { inputB: string };
|
|
62
|
+
public customData?: any;
|
|
25
63
|
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
64
|
+
constructor(data: any) {
|
|
65
|
+
this.stageDirector = new BasicStageDirector(
|
|
66
|
+
data.action || 'http-invoke',
|
|
67
|
+
data.outputPath || '/output',
|
|
68
|
+
data.nextStage || 'end',
|
|
69
|
+
data.failureStage || 'failed',
|
|
70
|
+
);
|
|
71
|
+
this.customData = data.customData;
|
|
72
|
+
}
|
|
35
73
|
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
74
|
+
getStageDirector(): BasicStageDirector {
|
|
75
|
+
return this.stageDirector;
|
|
76
|
+
}
|
|
39
77
|
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
78
|
+
name(): string {
|
|
79
|
+
return 'hello';
|
|
80
|
+
}
|
|
43
81
|
}
|
|
44
82
|
|
|
45
|
-
const
|
|
83
|
+
const appConfig = loadAppConfig();
|
|
84
|
+
const httpInvoke = appConfig.httpInvoke ?? {
|
|
85
|
+
url: 'https://httpbin.org/get',
|
|
86
|
+
invocationMode: 'PARALLEL' as const,
|
|
87
|
+
apiKeyHeader: 'X-API-KEY',
|
|
88
|
+
};
|
|
89
|
+
|
|
46
90
|
const map: Map<string, DirectedActionConfig<HTTPInvokeHandlerInput>> = new Map([
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
91
|
+
[
|
|
92
|
+
'http-invoke',
|
|
93
|
+
{
|
|
94
|
+
invocationMode:
|
|
95
|
+
InvocationMode[httpInvoke.invocationMode] ?? InvocationMode.PARALLEL,
|
|
96
|
+
handler: async () => {
|
|
97
|
+
const response = await fetch(httpInvoke.url, {
|
|
98
|
+
headers: {
|
|
99
|
+
[httpInvoke.apiKeyHeader]: process.env.API_KEY ?? '',
|
|
100
|
+
},
|
|
101
|
+
});
|
|
102
|
+
const body = await response.json();
|
|
103
|
+
return {
|
|
104
|
+
result: EvalResult.COMPLETE,
|
|
105
|
+
output: {
|
|
106
|
+
body,
|
|
107
|
+
status: response.status,
|
|
108
|
+
},
|
|
109
|
+
};
|
|
110
|
+
},
|
|
111
|
+
},
|
|
112
|
+
],
|
|
64
113
|
]);
|
|
65
114
|
|
|
66
|
-
export const actionMap = map;
|
|
115
|
+
export const actionMap = map;
|
|
@@ -14,7 +14,7 @@
|
|
|
14
14
|
// See the License for the specific language governing permissions and
|
|
15
15
|
// limitations under the License.
|
|
16
16
|
|
|
17
|
-
import { EventSourceConf, newEventSource, newLogger, WSEventStreamInfo } from
|
|
17
|
+
import { EventSourceConf, newEventSource, newLogger, WSEventStreamInfo } from '@kaleido-io/workflow-engine-sdk';
|
|
18
18
|
|
|
19
19
|
const log = newLogger('dealer-event-source');
|
|
20
20
|
|