@kaleido-io/workflow-engine-sdk 0.0.1 → 0.9.2
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/LICENSE +201 -0
- package/README.md +1121 -0
- package/bin/init.js +200 -0
- package/bin/wesdk.js +57 -0
- package/dist/package.json +3 -0
- package/dist/src/client/client.d.ts +24 -0
- package/dist/src/client/client.d.ts.map +1 -0
- package/dist/src/client/client.js +58 -0
- package/dist/src/client/client.js.map +1 -0
- package/dist/src/client/rest-client.d.ts +222 -0
- package/dist/src/client/rest-client.d.ts.map +1 -0
- package/dist/src/client/rest-client.js +242 -0
- package/dist/src/client/rest-client.js.map +1 -0
- package/dist/src/config/config.d.ts +60 -0
- package/dist/src/config/config.d.ts.map +1 -0
- package/dist/src/config/config.js +117 -0
- package/dist/src/config/config.js.map +1 -0
- package/dist/src/factories/event_source.d.ts +54 -0
- package/dist/src/factories/event_source.d.ts.map +1 -0
- package/dist/src/factories/event_source.js +170 -0
- package/dist/src/factories/event_source.js.map +1 -0
- package/dist/src/factories/transaction_handler.d.ts +27 -0
- package/dist/src/factories/transaction_handler.d.ts.map +1 -0
- package/dist/src/factories/transaction_handler.js +66 -0
- package/dist/src/factories/transaction_handler.js.map +1 -0
- package/dist/src/helpers/stage_director.d.ts +42 -0
- package/dist/src/helpers/stage_director.d.ts.map +1 -0
- package/dist/src/helpers/stage_director.js +304 -0
- package/dist/src/helpers/stage_director.js.map +1 -0
- package/dist/src/i18n/errors.d.ts +61 -0
- package/dist/src/i18n/errors.d.ts.map +1 -0
- package/dist/src/i18n/errors.js +90 -0
- package/dist/src/i18n/errors.js.map +1 -0
- package/dist/src/index.d.ts +20 -0
- package/dist/src/index.d.ts.map +1 -0
- package/dist/src/index.js +85 -0
- package/dist/src/index.js.map +1 -0
- package/dist/src/interfaces/handlers.d.ts +112 -0
- package/dist/src/interfaces/handlers.d.ts.map +1 -0
- package/dist/src/interfaces/handlers.js +18 -0
- package/dist/src/interfaces/handlers.js.map +1 -0
- package/dist/src/interfaces/messages.d.ts +6 -0
- package/dist/src/interfaces/messages.d.ts.map +1 -0
- package/dist/src/interfaces/messages.js +18 -0
- package/dist/src/interfaces/messages.js.map +1 -0
- package/dist/src/log/logger.d.ts +8 -0
- package/dist/src/log/logger.d.ts.map +1 -0
- package/dist/src/log/logger.js +39 -0
- package/dist/src/log/logger.js.map +1 -0
- package/dist/src/runtime/engine_client.d.ts +37 -0
- package/dist/src/runtime/engine_client.d.ts.map +1 -0
- package/dist/src/runtime/engine_client.js +99 -0
- package/dist/src/runtime/engine_client.js.map +1 -0
- package/dist/src/runtime/handler_runtime.d.ts +124 -0
- package/dist/src/runtime/handler_runtime.d.ts.map +1 -0
- package/dist/src/runtime/handler_runtime.js +623 -0
- package/dist/src/runtime/handler_runtime.js.map +1 -0
- package/dist/src/types/core.d.ts +258 -0
- package/dist/src/types/core.d.ts.map +1 -0
- package/dist/src/types/core.js +71 -0
- package/dist/src/types/core.js.map +1 -0
- package/dist/src/types/flows.d.ts +144 -0
- package/dist/src/types/flows.d.ts.map +1 -0
- package/dist/src/types/flows.js +30 -0
- package/dist/src/types/flows.js.map +1 -0
- package/dist/src/utils/errors.d.ts +2 -0
- package/dist/src/utils/errors.d.ts.map +1 -0
- package/dist/src/utils/errors.js +23 -0
- package/dist/src/utils/errors.js.map +1 -0
- package/dist/src/utils/patch.d.ts +9 -0
- package/dist/src/utils/patch.d.ts.map +1 -0
- package/dist/src/utils/patch.js +99 -0
- package/dist/src/utils/patch.js.map +1 -0
- package/dist-esm/src/client/client.js +54 -0
- package/dist-esm/src/client/client.js.map +1 -0
- package/dist-esm/src/client/rest-client.js +238 -0
- package/dist-esm/src/client/rest-client.js.map +1 -0
- package/dist-esm/src/config/config.js +113 -0
- package/dist-esm/src/config/config.js.map +1 -0
- package/dist-esm/src/factories/event_source.js +167 -0
- package/dist-esm/src/factories/event_source.js.map +1 -0
- package/dist-esm/src/factories/transaction_handler.js +63 -0
- package/dist-esm/src/factories/transaction_handler.js.map +1 -0
- package/dist-esm/src/helpers/stage_director.js +298 -0
- package/dist-esm/src/helpers/stage_director.js.map +1 -0
- package/dist-esm/src/i18n/errors.js +85 -0
- package/dist-esm/src/i18n/errors.js.map +1 -0
- package/dist-esm/src/index.js +51 -0
- package/dist-esm/src/index.js.map +1 -0
- package/dist-esm/src/interfaces/handlers.js +17 -0
- package/dist-esm/src/interfaces/handlers.js.map +1 -0
- package/dist-esm/src/interfaces/messages.js +17 -0
- package/dist-esm/src/interfaces/messages.js.map +1 -0
- package/dist-esm/src/log/logger.js +36 -0
- package/dist-esm/src/log/logger.js.map +1 -0
- package/dist-esm/src/runtime/engine_client.js +95 -0
- package/dist-esm/src/runtime/engine_client.js.map +1 -0
- package/dist-esm/src/runtime/handler_runtime.js +586 -0
- package/dist-esm/src/runtime/handler_runtime.js.map +1 -0
- package/dist-esm/src/types/core.js +68 -0
- package/dist-esm/src/types/core.js.map +1 -0
- package/dist-esm/src/types/flows.js +27 -0
- package/dist-esm/src/types/flows.js.map +1 -0
- package/dist-esm/src/utils/errors.js +19 -0
- package/dist-esm/src/utils/errors.js.map +1 -0
- package/dist-esm/src/utils/patch.js +56 -0
- package/dist-esm/src/utils/patch.js.map +1 -0
- package/package.json +79 -11
- package/template/.env.sample +14 -0
- package/template/.vscode/launch.json +23 -0
- package/template/README.md +37 -0
- package/template/package.json +36 -0
- package/template/src/connect.ts +58 -0
- package/template/src/provider.ts +24 -0
- package/template/src/samples/event-source/README.md +50 -0
- package/template/src/samples/event-source/echo-handler.ts +65 -0
- package/template/src/samples/event-source/event-processor.ts +46 -0
- package/template/src/samples/event-source/event-source.ts +70 -0
- package/template/src/samples/event-source/stream.ts +34 -0
- package/template/src/samples/hello/README.md +52 -0
- package/template/src/samples/hello/flow.ts +74 -0
- package/template/src/samples/hello/handlers.test.ts +147 -0
- package/template/src/samples/hello/handlers.ts +72 -0
- package/template/src/samples/hello/transaction.ts +24 -0
- package/template/src/samples/http-invoke/README.md +42 -0
- package/template/src/samples/http-invoke/flow.ts +63 -0
- package/template/src/samples/http-invoke/handlers.ts +66 -0
- package/template/src/samples/http-invoke/transaction.ts +22 -0
- package/template/src/samples/snap/README.md +98 -0
- package/template/src/samples/snap/event-source.ts +104 -0
- package/template/src/samples/snap/flow.ts +85 -0
- package/template/src/samples/snap/snap-handler.ts +84 -0
- package/template/src/samples/snap/stream.ts +26 -0
- package/template/src/samples/snap/transaction.ts +26 -0
- package/template/src/utils/post-stream.ts +67 -0
- package/template/src/utils/post-transaction.ts +64 -0
- package/template/src/utils/post-workflow.ts +63 -0
- package/template/tsconfig.json +24 -0
- package/template/vitest.config.ts +42 -0
- package/CODEOWNERS +0 -5
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
// Copyright © 2026 Kaleido, Inc.
|
|
2
|
+
//
|
|
3
|
+
// SPDX-License-Identifier: Apache-2.0
|
|
4
|
+
//
|
|
5
|
+
// Licensed under the Apache License, Version 2.0 (the "License");
|
|
6
|
+
// you may not use this file except in compliance with the License.
|
|
7
|
+
// You may obtain a copy of the License at
|
|
8
|
+
//
|
|
9
|
+
// http://www.apache.org/licenses/LICENSE-2.0
|
|
10
|
+
//
|
|
11
|
+
// Unless required by applicable law or agreed to in writing, software
|
|
12
|
+
// distributed under the License is distributed on an "AS IS" BASIS,
|
|
13
|
+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
14
|
+
// See the License for the specific language governing permissions and
|
|
15
|
+
// limitations under the License.
|
|
16
|
+
/**
|
|
17
|
+
* Core types and enums for the Workflow Engine TypeScript SDK.
|
|
18
|
+
*/
|
|
19
|
+
export var EvalResult;
|
|
20
|
+
(function (EvalResult) {
|
|
21
|
+
EvalResult[EvalResult["FIXABLE_ERROR"] = 0] = "FIXABLE_ERROR";
|
|
22
|
+
EvalResult[EvalResult["TRANSIENT_ERROR"] = 1] = "TRANSIENT_ERROR";
|
|
23
|
+
EvalResult[EvalResult["HARD_FAILURE"] = 2] = "HARD_FAILURE";
|
|
24
|
+
EvalResult[EvalResult["COMPLETE"] = 3] = "COMPLETE";
|
|
25
|
+
EvalResult[EvalResult["WAITING"] = 4] = "WAITING";
|
|
26
|
+
})(EvalResult || (EvalResult = {}));
|
|
27
|
+
export var InvocationMode;
|
|
28
|
+
(function (InvocationMode) {
|
|
29
|
+
InvocationMode[InvocationMode["PARALLEL"] = 0] = "PARALLEL";
|
|
30
|
+
InvocationMode[InvocationMode["BATCH"] = 1] = "BATCH";
|
|
31
|
+
})(InvocationMode || (InvocationMode = {}));
|
|
32
|
+
export var WSMessageType;
|
|
33
|
+
(function (WSMessageType) {
|
|
34
|
+
WSMessageType["PROTOCOL_ERROR"] = "protocol_error";
|
|
35
|
+
WSMessageType["REGISTER_PROVIDER"] = "register_provider";
|
|
36
|
+
WSMessageType["REGISTER_HANDLER"] = "register_handler";
|
|
37
|
+
WSMessageType["EVALUATE"] = "evaluate";
|
|
38
|
+
WSMessageType["EVALUATE_RESULT"] = "evaluate_result";
|
|
39
|
+
WSMessageType["HANDLE_TRANSACTIONS"] = "handle_transactions";
|
|
40
|
+
WSMessageType["HANDLE_TRANSACTIONS_RESULT"] = "handle_transactions_result";
|
|
41
|
+
WSMessageType["EVENT_SOURCE_CONFIG"] = "event_source_config";
|
|
42
|
+
WSMessageType["EVENT_SOURCE_POLL"] = "event_source_poll";
|
|
43
|
+
WSMessageType["EVENT_SOURCE_POLL_RESULT"] = "event_source_poll_result";
|
|
44
|
+
WSMessageType["EVENT_SOURCE_VALIDATE_CONFIG"] = "event_source_validate_config";
|
|
45
|
+
WSMessageType["EVENT_SOURCE_VALIDATE_CONFIG_RESULT"] = "event_source_validate_config_result";
|
|
46
|
+
WSMessageType["EVENT_SOURCE_DELETE"] = "event_source_delete";
|
|
47
|
+
WSMessageType["EVENT_SOURCE_DELETE_RESULT"] = "event_source_delete_result";
|
|
48
|
+
WSMessageType["EVENT_PROCESSOR_BATCH"] = "event_processor_batch";
|
|
49
|
+
WSMessageType["EVENT_PROCESSOR_BATCH_RESULT"] = "event_processor_batch_result";
|
|
50
|
+
WSMessageType["ENGINE_API_SUBMIT_TRANSACTIONS"] = "engineapi_submit_transactions";
|
|
51
|
+
WSMessageType["ENGINE_API_SUBMIT_TRANSACTIONS_RESULT"] = "engineapi_submit_transactions_result";
|
|
52
|
+
})(WSMessageType || (WSMessageType = {}));
|
|
53
|
+
export var WSHandlerType;
|
|
54
|
+
(function (WSHandlerType) {
|
|
55
|
+
WSHandlerType["TRANSACTION_HANDLER"] = "transaction_handler";
|
|
56
|
+
WSHandlerType["EVENT_PROCESSOR"] = "event_processor";
|
|
57
|
+
WSHandlerType["EVENT_SOURCE"] = "event_source";
|
|
58
|
+
})(WSHandlerType || (WSHandlerType = {}));
|
|
59
|
+
export var PatchOpType;
|
|
60
|
+
(function (PatchOpType) {
|
|
61
|
+
PatchOpType["ADD"] = "add";
|
|
62
|
+
PatchOpType["REMOVE"] = "remove";
|
|
63
|
+
PatchOpType["REPLACE"] = "replace";
|
|
64
|
+
PatchOpType["MOVE"] = "move";
|
|
65
|
+
PatchOpType["COPY"] = "copy";
|
|
66
|
+
PatchOpType["TEST"] = "test";
|
|
67
|
+
})(PatchOpType || (PatchOpType = {}));
|
|
68
|
+
//# sourceMappingURL=core.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"core.js","sourceRoot":"","sources":["../../../src/types/core.ts"],"names":[],"mappings":"AAAA,iCAAiC;AACjC,EAAE;AACF,sCAAsC;AACtC,EAAE;AACF,kEAAkE;AAClE,mEAAmE;AACnE,0CAA0C;AAC1C,EAAE;AACF,iDAAiD;AACjD,EAAE;AACF,sEAAsE;AACtE,oEAAoE;AACpE,2EAA2E;AAC3E,sEAAsE;AACtE,iCAAiC;AAGjC;;GAEG;AAEH,MAAM,CAAN,IAAY,UAMX;AAND,WAAY,UAAU;IACpB,6DAAiB,CAAA;IACjB,iEAAmB,CAAA;IACnB,2DAAgB,CAAA;IAChB,mDAAY,CAAA;IACZ,iDAAW,CAAA;AACb,CAAC,EANW,UAAU,KAAV,UAAU,QAMrB;AAED,MAAM,CAAN,IAAY,cAGX;AAHD,WAAY,cAAc;IACxB,2DAAY,CAAA;IACZ,qDAAS,CAAA;AACX,CAAC,EAHW,cAAc,KAAd,cAAc,QAGzB;AAED,MAAM,CAAN,IAAY,aAmBX;AAnBD,WAAY,aAAa;IACvB,kDAAiC,CAAA;IACjC,wDAAuC,CAAA;IACvC,sDAAqC,CAAA;IACrC,sCAAqB,CAAA;IACrB,oDAAmC,CAAA;IACnC,4DAA2C,CAAA;IAC3C,0EAAyD,CAAA;IACzD,4DAA2C,CAAA;IAC3C,wDAAuC,CAAA;IACvC,sEAAqD,CAAA;IACrD,8EAA6D,CAAA;IAC7D,4FAA2E,CAAA;IAC3E,4DAA2C,CAAA;IAC3C,0EAAyD,CAAA;IACzD,gEAA+C,CAAA;IAC/C,8EAA6D,CAAA;IAC7D,iFAAgE,CAAA;IAChE,+FAA8E,CAAA;AAChF,CAAC,EAnBW,aAAa,KAAb,aAAa,QAmBxB;AAED,MAAM,CAAN,IAAY,aAIX;AAJD,WAAY,aAAa;IACvB,4DAA2C,CAAA;IAC3C,oDAAmC,CAAA;IACnC,8CAA6B,CAAA;AAC/B,CAAC,EAJW,aAAa,KAAb,aAAa,QAIxB;AAED,MAAM,CAAN,IAAY,WAOX;AAPD,WAAY,WAAW;IACrB,0BAAW,CAAA;IACX,gCAAiB,CAAA;IACjB,kCAAmB,CAAA;IACnB,4BAAa,CAAA;IACb,4BAAa,CAAA;IACb,4BAAa,CAAA;AACf,CAAC,EAPW,WAAW,KAAX,WAAW,QAOtB"}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
// Copyright © 2026 Kaleido, Inc.
|
|
2
|
+
//
|
|
3
|
+
// SPDX-License-Identifier: Apache-2.0
|
|
4
|
+
//
|
|
5
|
+
// Licensed under the Apache License, Version 2.0 (the "License");
|
|
6
|
+
// you may not use this file except in compliance with the License.
|
|
7
|
+
// You may obtain a copy of the License at
|
|
8
|
+
//
|
|
9
|
+
// http://www.apache.org/licenses/LICENSE-2.0
|
|
10
|
+
//
|
|
11
|
+
// Unless required by applicable law or agreed to in writing, software
|
|
12
|
+
// distributed under the License is distributed on an "AS IS" BASIS,
|
|
13
|
+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
14
|
+
// See the License for the specific language governing permissions and
|
|
15
|
+
// limitations under the License.
|
|
16
|
+
/** Available flow stage types */
|
|
17
|
+
export const FlowStageTypes = {
|
|
18
|
+
PENDING: 'pending',
|
|
19
|
+
SUCCESS: 'success',
|
|
20
|
+
FAILURE: 'failure',
|
|
21
|
+
};
|
|
22
|
+
/** Available flow operation types */
|
|
23
|
+
export const FlowOperationTypes = {
|
|
24
|
+
ASYNC: 'asynchronous',
|
|
25
|
+
SYNC: 'synchronous',
|
|
26
|
+
};
|
|
27
|
+
//# sourceMappingURL=flows.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"flows.js","sourceRoot":"","sources":["../../../src/types/flows.ts"],"names":[],"mappings":"AAAA,iCAAiC;AACjC,EAAE;AACF,sCAAsC;AACtC,EAAE;AACF,kEAAkE;AAClE,mEAAmE;AACnE,0CAA0C;AAC1C,EAAE;AACF,iDAAiD;AACjD,EAAE;AACF,sEAAsE;AACtE,oEAAoE;AACpE,2EAA2E;AAC3E,sEAAsE;AACtE,iCAAiC;AAYjC,iCAAiC;AACjC,MAAM,CAAC,MAAM,cAAc,GAAG;IAC5B,OAAO,EAAE,SAA0B;IACnC,OAAO,EAAE,SAA0B;IACnC,OAAO,EAAE,SAA0B;CAC3B,CAAC;AAKX,qCAAqC;AACrC,MAAM,CAAC,MAAM,kBAAkB,GAAG;IAChC,KAAK,EAAE,cAAmC;IAC1C,IAAI,EAAE,aAAkC;CAChC,CAAC"}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
// Copyright © 2026 Kaleido, Inc.
|
|
2
|
+
//
|
|
3
|
+
// SPDX-License-Identifier: Apache-2.0
|
|
4
|
+
//
|
|
5
|
+
// Licensed under the Apache License, Version 2.0 (the "License");
|
|
6
|
+
// you may not use this file except in compliance with the License.
|
|
7
|
+
// You may obtain a copy of the License at
|
|
8
|
+
//
|
|
9
|
+
// http://www.apache.org/licenses/LICENSE-2.0
|
|
10
|
+
//
|
|
11
|
+
// Unless required by applicable law or agreed to in writing, software
|
|
12
|
+
// distributed under the License is distributed on an "AS IS" BASIS,
|
|
13
|
+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
14
|
+
// See the License for the specific language governing permissions and
|
|
15
|
+
// limitations under the License.
|
|
16
|
+
export const getErrorMessage = (error) => {
|
|
17
|
+
return error instanceof Error ? error.message : String(error);
|
|
18
|
+
};
|
|
19
|
+
//# sourceMappingURL=errors.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"errors.js","sourceRoot":"","sources":["../../../src/utils/errors.ts"],"names":[],"mappings":"AAAA,iCAAiC;AACjC,EAAE;AACF,sCAAsC;AACtC,EAAE;AACF,kEAAkE;AAClE,mEAAmE;AACnE,0CAA0C;AAC1C,EAAE;AACF,iDAAiD;AACjD,EAAE;AACF,sEAAsE;AACtE,oEAAoE;AACpE,2EAA2E;AAC3E,sEAAsE;AACtE,iCAAiC;AAGjC,MAAM,CAAC,MAAM,eAAe,GAAG,CAAC,KAAc,EAAU,EAAE;IACxD,OAAO,KAAK,YAAY,KAAK,CAAC,CAAC,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC;AAChE,CAAC,CAAA"}
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
// Copyright © 2026 Kaleido, Inc.
|
|
2
|
+
//
|
|
3
|
+
// SPDX-License-Identifier: Apache-2.0
|
|
4
|
+
//
|
|
5
|
+
// Licensed under the Apache License, Version 2.0 (the "License");
|
|
6
|
+
// you may not use this file except in compliance with the License.
|
|
7
|
+
// You may obtain a copy of the License at
|
|
8
|
+
//
|
|
9
|
+
// http://www.apache.org/licenses/LICENSE-2.0
|
|
10
|
+
//
|
|
11
|
+
// Unless required by applicable law or agreed to in writing, software
|
|
12
|
+
// distributed under the License is distributed on an "AS IS" BASIS,
|
|
13
|
+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
14
|
+
// See the License for the specific language governing permissions and
|
|
15
|
+
// limitations under the License.
|
|
16
|
+
import * as fastJsonPatch from "fast-json-patch";
|
|
17
|
+
import { PatchOpType } from "../types/core.js";
|
|
18
|
+
const { applyPatch } = fastJsonPatch;
|
|
19
|
+
export const apply = (state, patch) => {
|
|
20
|
+
if (!patch || patch.length === 0) {
|
|
21
|
+
return state;
|
|
22
|
+
}
|
|
23
|
+
const { newDocument: newState } = applyPatch(state, patch);
|
|
24
|
+
return newState;
|
|
25
|
+
};
|
|
26
|
+
// JSON Patch operation creators
|
|
27
|
+
export const addOp = (path, value) => ({
|
|
28
|
+
op: PatchOpType.ADD,
|
|
29
|
+
path,
|
|
30
|
+
value,
|
|
31
|
+
});
|
|
32
|
+
export const removeOp = (path) => ({
|
|
33
|
+
op: PatchOpType.REMOVE,
|
|
34
|
+
path,
|
|
35
|
+
});
|
|
36
|
+
export const replaceOp = (path, value) => ({
|
|
37
|
+
op: PatchOpType.REPLACE,
|
|
38
|
+
path,
|
|
39
|
+
value,
|
|
40
|
+
});
|
|
41
|
+
export const moveOp = (from, path) => ({
|
|
42
|
+
op: PatchOpType.MOVE,
|
|
43
|
+
from,
|
|
44
|
+
path,
|
|
45
|
+
});
|
|
46
|
+
export const copyOp = (from, path) => ({
|
|
47
|
+
op: PatchOpType.COPY,
|
|
48
|
+
from,
|
|
49
|
+
path,
|
|
50
|
+
});
|
|
51
|
+
export const testOp = (path, value) => ({
|
|
52
|
+
op: PatchOpType.TEST,
|
|
53
|
+
path,
|
|
54
|
+
value,
|
|
55
|
+
});
|
|
56
|
+
//# sourceMappingURL=patch.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"patch.js","sourceRoot":"","sources":["../../../src/utils/patch.ts"],"names":[],"mappings":"AAAA,iCAAiC;AACjC,EAAE;AACF,sCAAsC;AACtC,EAAE;AACF,kEAAkE;AAClE,mEAAmE;AACnE,0CAA0C;AAC1C,EAAE;AACF,iDAAiD;AACjD,EAAE;AACF,sEAAsE;AACtE,oEAAoE;AACpE,2EAA2E;AAC3E,sEAAsE;AACtE,iCAAiC;AAGjC,OAAO,KAAK,aAAa,MAAM,iBAAiB,CAAC;AACjD,OAAO,EAAW,WAAW,EAAS,MAAM,eAAe,CAAC;AAE5D,MAAM,EAAE,UAAU,EAAE,GAAG,aAAa,CAAC;AAErC,MAAM,CAAC,MAAM,KAAK,GAAG,CAAC,KAAc,EAAE,KAAY,EAAE,EAAE;IACpD,IAAI,CAAC,KAAK,IAAI,KAAK,CAAC,MAAM,KAAK,CAAC,EAAE,CAAC;QACjC,OAAO,KAAK,CAAC;IACf,CAAC;IAED,MAAM,EAAE,WAAW,EAAE,QAAQ,EAAE,GAAG,UAAU,CAAC,KAAK,EAAE,KAAkC,CAAC,CAAC;IACxF,OAAO,QAAQ,CAAC;AAClB,CAAC,CAAC;AAEF,gCAAgC;AAChC,MAAM,CAAC,MAAM,KAAK,GAAG,CAAC,IAAY,EAAE,KAAc,EAAW,EAAE,CAAC,CAAC;IAC/D,EAAE,EAAE,WAAW,CAAC,GAAG;IACnB,IAAI;IACJ,KAAK;CACN,CAAC,CAAC;AAEH,MAAM,CAAC,MAAM,QAAQ,GAAG,CAAC,IAAY,EAAW,EAAE,CAAC,CAAC;IAClD,EAAE,EAAE,WAAW,CAAC,MAAM;IACtB,IAAI;CACL,CAAC,CAAC;AAEH,MAAM,CAAC,MAAM,SAAS,GAAG,CAAC,IAAY,EAAE,KAAc,EAAW,EAAE,CAAC,CAAC;IACnE,EAAE,EAAE,WAAW,CAAC,OAAO;IACvB,IAAI;IACJ,KAAK;CACN,CAAC,CAAC;AAEH,MAAM,CAAC,MAAM,MAAM,GAAG,CAAC,IAAY,EAAE,IAAY,EAAW,EAAE,CAAC,CAAC;IAC9D,EAAE,EAAE,WAAW,CAAC,IAAI;IACpB,IAAI;IACJ,IAAI;CACL,CAAC,CAAC;AAEH,MAAM,CAAC,MAAM,MAAM,GAAG,CAAC,IAAY,EAAE,IAAY,EAAW,EAAE,CAAC,CAAC;IAC9D,EAAE,EAAE,WAAW,CAAC,IAAI;IACpB,IAAI;IACJ,IAAI;CACL,CAAC,CAAC;AAEH,MAAM,CAAC,MAAM,MAAM,GAAG,CAAC,IAAY,EAAE,KAAc,EAAW,EAAE,CAAC,CAAC;IAChE,EAAE,EAAE,WAAW,CAAC,IAAI;IACpB,IAAI;IACJ,KAAK;CACN,CAAC,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,22 +1,90 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@kaleido-io/workflow-engine-sdk",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"description": "Kaleido
|
|
5
|
-
"
|
|
6
|
-
"
|
|
7
|
-
|
|
8
|
-
|
|
3
|
+
"version": "0.9.2",
|
|
4
|
+
"description": "TypeScript SDK for Kaleido Workflow Engine",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"main": "dist/src/index.js",
|
|
7
|
+
"module": "dist-esm/src/index.js",
|
|
8
|
+
"types": "dist/src/index.d.ts",
|
|
9
9
|
"repository": {
|
|
10
10
|
"type": "git",
|
|
11
11
|
"url": "git+https://github.com/kaleido-io/kaleido-sdk-typescript.git"
|
|
12
12
|
},
|
|
13
|
+
"scripts": {
|
|
14
|
+
"prebuild": "npm run clean && npm run lint",
|
|
15
|
+
"build": "tsc && npm run build:cjs && npm run build:esm",
|
|
16
|
+
"build:cjs": "tsc && cp cjs-package-template.json dist/package.json",
|
|
17
|
+
"build:esm": "tsc -p tsconfig.esm.json",
|
|
18
|
+
"postbuild": "tsc-esm-fix --target='dist-esm'",
|
|
19
|
+
"clean": "rm -rf dist && rm -rf dist-esm",
|
|
20
|
+
"dev": "tsc --watch",
|
|
21
|
+
"test": "jest --testPathIgnorePatterns=tests/componenttest --coverage",
|
|
22
|
+
"test:unit": "jest tests/unit",
|
|
23
|
+
"test:component": "jest tests/componenttest",
|
|
24
|
+
"test:all": "jest --coverage",
|
|
25
|
+
"lint": "eslint . --config eslint.config.mjs",
|
|
26
|
+
"lint:fix": "eslint . --fix --config eslint.config.mjs"
|
|
27
|
+
},
|
|
13
28
|
"keywords": [
|
|
14
|
-
"kaleido"
|
|
29
|
+
"kaleido",
|
|
30
|
+
"sdk",
|
|
31
|
+
"typescript",
|
|
32
|
+
"workflows",
|
|
33
|
+
"workflow-engine",
|
|
34
|
+
"handlers",
|
|
35
|
+
"providers"
|
|
15
36
|
],
|
|
16
|
-
"author": "
|
|
37
|
+
"author": "Kaleido",
|
|
17
38
|
"license": "Apache-2.0",
|
|
18
|
-
"
|
|
19
|
-
"
|
|
39
|
+
"dependencies": {
|
|
40
|
+
"exponential-backoff": "^3.1.1",
|
|
41
|
+
"fast-json-patch": "^3.1.1",
|
|
42
|
+
"js-yaml": "^4.1.1",
|
|
43
|
+
"uuid": "^13.0.0",
|
|
44
|
+
"ws": "^8.14.0"
|
|
20
45
|
},
|
|
21
|
-
"
|
|
46
|
+
"devDependencies": {
|
|
47
|
+
"@eslint/compat": "^2.0.0",
|
|
48
|
+
"@eslint/js": "^10.0.0",
|
|
49
|
+
"@jest/globals": "^30.2.0",
|
|
50
|
+
"@types/jest": "^30.0.0",
|
|
51
|
+
"@types/js-yaml": "^4.0.9",
|
|
52
|
+
"@types/node": "^25.2.1",
|
|
53
|
+
"@types/uuid": "^10.0.0",
|
|
54
|
+
"@types/ws": "^8.5.0",
|
|
55
|
+
"eslint": "^10.0.0",
|
|
56
|
+
"eslint-plugin-notice": "^1.0.0",
|
|
57
|
+
"find-root": "^1.1.0",
|
|
58
|
+
"globals": "^17.3.0",
|
|
59
|
+
"jest": "^30.2.0",
|
|
60
|
+
"lodash": "^4.17.21",
|
|
61
|
+
"metric-lcs": "^1.0.3",
|
|
62
|
+
"ts-jest": "^29.1.0",
|
|
63
|
+
"ts-node": "^10.9.2",
|
|
64
|
+
"tsc-esm-fix": "^3.1.2",
|
|
65
|
+
"typescript": "^5.2.0",
|
|
66
|
+
"typescript-eslint": "^8.56.0"
|
|
67
|
+
},
|
|
68
|
+
"engines": {
|
|
69
|
+
"node": ">=20.19.0"
|
|
70
|
+
},
|
|
71
|
+
"bin": {
|
|
72
|
+
"wesdk": "./bin/wesdk.js"
|
|
73
|
+
},
|
|
74
|
+
"files": [
|
|
75
|
+
"dist/**/*",
|
|
76
|
+
"dist-esm/**/*",
|
|
77
|
+
"bin/**/*",
|
|
78
|
+
"template/**/*",
|
|
79
|
+
"!template/node_modules/**/*",
|
|
80
|
+
"README.md",
|
|
81
|
+
"LICENSE"
|
|
82
|
+
],
|
|
83
|
+
"exports": {
|
|
84
|
+
".": {
|
|
85
|
+
"import": "./dist-esm/src/index.js",
|
|
86
|
+
"require": "./dist/src/index.js",
|
|
87
|
+
"types": "./dist/src/index.d.ts"
|
|
88
|
+
}
|
|
89
|
+
}
|
|
22
90
|
}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
# Account URL
|
|
2
|
+
ACCOUNT=my-account.my-tenant.com
|
|
3
|
+
|
|
4
|
+
# Environment
|
|
5
|
+
ENVIRONMENT=my-environment-name
|
|
6
|
+
|
|
7
|
+
# Workflow engine
|
|
8
|
+
WORKFLOW_ENGINE=my-workflow-engine-name
|
|
9
|
+
|
|
10
|
+
# API key name
|
|
11
|
+
KEY_NAME="my-key-name"
|
|
12
|
+
|
|
13
|
+
# API key
|
|
14
|
+
KEY_VALUE="my-key-value"
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": "0.2.0",
|
|
3
|
+
"configurations": [
|
|
4
|
+
{
|
|
5
|
+
"name": "Debug: npm run start:dev",
|
|
6
|
+
"type": "node",
|
|
7
|
+
"request": "launch",
|
|
8
|
+
"runtimeExecutable": "npm",
|
|
9
|
+
"runtimeArgs": ["run", "start:dev"],
|
|
10
|
+
"console": "integratedTerminal",
|
|
11
|
+
"internalConsoleOptions": "neverOpen"
|
|
12
|
+
},
|
|
13
|
+
{
|
|
14
|
+
"name": "Debug: npm run test",
|
|
15
|
+
"type": "node",
|
|
16
|
+
"request": "launch",
|
|
17
|
+
"runtimeExecutable": "npm",
|
|
18
|
+
"runtimeArgs": ["run", "test"],
|
|
19
|
+
"console": "integratedTerminal",
|
|
20
|
+
"internalConsoleOptions": "neverOpen"
|
|
21
|
+
}
|
|
22
|
+
]
|
|
23
|
+
}
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
# Kaleido workflow engine custom providers
|
|
2
|
+
|
|
3
|
+
This project contains worked examples of custom providers that register transaction handlers and event sources with the Kaleido workflow engine.
|
|
4
|
+
|
|
5
|
+
## Getting started
|
|
6
|
+
|
|
7
|
+
1. Copy `.env.sample` to `.env` and populate the values. You will need:
|
|
8
|
+
- a Kaleido account in a tenant something of the format <account_name>.<tenant_url>
|
|
9
|
+
- an environment in that account, either name or ID
|
|
10
|
+
- a workflow engine in that environment, either name or ID
|
|
11
|
+
- an API key name and value - the API key will need to be granted service access to the workflow engine
|
|
12
|
+
2. Install dependencies: `npm install`
|
|
13
|
+
3. Start the provider, either:
|
|
14
|
+
- use the vscode launch configurations to run inside the debugger
|
|
15
|
+
- use `npm run start:dev` to run TypeScript
|
|
16
|
+
- use `npm build` and `npm start` to run transpiled JavaScript
|
|
17
|
+
|
|
18
|
+
Your provider will initialize and attempt to connect to the workflow engine and register the provider and handlers. You should see:
|
|
19
|
+
```bash
|
|
20
|
+
[handler_runtime] Registering provider and handlers
|
|
21
|
+
```
|
|
22
|
+
Followed by some handler registration messages. You can now take a look at your workflow engine provider page in the Kaleido UI and you should see your provider listed.
|
|
23
|
+
|
|
24
|
+
This project will be bootstrapped with some example handlers, and the flows and streams needed to put them to use. To trigger a handler, you can use the `hello` sample by:
|
|
25
|
+
- defining a workflow that uses the `hello` handler by running `npm run create-workflow ./src/samples/hello/flow.ts`
|
|
26
|
+
- create a transaction against that workflow by running `npm run create-transaction ./src/samples/hello/transaction.json`
|
|
27
|
+
|
|
28
|
+
You should see the transaction appear in your workflow engine, and it should transition to `succeeded` shortly afterwars with a greeting message produced by the `hello` handler in this project.
|
|
29
|
+
|
|
30
|
+
## Included Samples
|
|
31
|
+
|
|
32
|
+
This project includes several samples demonstrating different patterns and capabilities:
|
|
33
|
+
|
|
34
|
+
- **[Hello](./src/samples/hello/README.md)** - A simple transaction handler that processes input and returns a greeting message
|
|
35
|
+
- **[HTTP invoke](./src/samples/http-invoke/README.md)** - Demonstrates making HTTP requests to external APIs from within a transaction handler
|
|
36
|
+
- **[Event source](./src/samples/event-source/README.md)** - Shows how to set up a custom event source that generates events and streams them to an event processor
|
|
37
|
+
- **[Snap](./src/samples/snap/README.md)** - By playing the card game "snap", this sample demonstrates a correlation stream that matches events from any event source with inflight transactions.
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "{{PROVIDER_NAME}}",
|
|
3
|
+
"version": "0.0.1",
|
|
4
|
+
"scripts": {
|
|
5
|
+
"prebuild": "npm run clean",
|
|
6
|
+
"build": "tsc",
|
|
7
|
+
"clean": "rm -rf dist",
|
|
8
|
+
"start": "node dist/src/connect.js",
|
|
9
|
+
"start:dev": "tsx ./src/connect.ts",
|
|
10
|
+
"create-workflow": "tsx ./src/utils/post-workflow.ts",
|
|
11
|
+
"create-transaction": "tsx ./src/utils/post-transaction.ts",
|
|
12
|
+
"create-stream": "tsx ./src/utils/post-stream.ts",
|
|
13
|
+
"test": "vitest run",
|
|
14
|
+
"test:watch": "vitest watch",
|
|
15
|
+
"test:coverage": "vitest run --coverage"
|
|
16
|
+
},
|
|
17
|
+
"private": true,
|
|
18
|
+
"devDependencies": {
|
|
19
|
+
"@vitest/coverage-v8": "^4.0.16",
|
|
20
|
+
"tsx": "^4.21.0",
|
|
21
|
+
"typescript": "^5.9.3",
|
|
22
|
+
"vitest": "^4.0.16"
|
|
23
|
+
},
|
|
24
|
+
"type": "module",
|
|
25
|
+
"main": "dist/src/connect.js",
|
|
26
|
+
"files": [
|
|
27
|
+
"dist/src",
|
|
28
|
+
"README.md"
|
|
29
|
+
],
|
|
30
|
+
"dependencies": {
|
|
31
|
+
"@kaleido-io/workflow-engine-sdk": "^1.0.0",
|
|
32
|
+
"dotenv": "^17.2.3",
|
|
33
|
+
"web3": "^4.16.0",
|
|
34
|
+
"ws": "^8.18.0"
|
|
35
|
+
}
|
|
36
|
+
}
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
// Copyright © 2026 Kaleido, Inc.
|
|
2
|
+
//
|
|
3
|
+
// SPDX-License-Identifier: Apache-2.0
|
|
4
|
+
//
|
|
5
|
+
// Licensed under the Apache License, Version 2.0 (the "License");
|
|
6
|
+
// you may not use this file except in compliance with the License.
|
|
7
|
+
// You may obtain a copy of the License at
|
|
8
|
+
//
|
|
9
|
+
// http://www.apache.org/licenses/LICENSE-2.0
|
|
10
|
+
//
|
|
11
|
+
// Unless required by applicable law or agreed to in writing, software
|
|
12
|
+
// distributed under the License is distributed on an "AS IS" BASIS,
|
|
13
|
+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
14
|
+
// See the License for the specific language governing permissions and
|
|
15
|
+
// limitations under the License.
|
|
16
|
+
|
|
17
|
+
|
|
18
|
+
import {
|
|
19
|
+
newDirectedTransactionHandler,
|
|
20
|
+
WorkflowEngineClient,
|
|
21
|
+
} from '@kaleido-io/workflow-engine-sdk';
|
|
22
|
+
import dotenv from 'dotenv';
|
|
23
|
+
|
|
24
|
+
import provider from './provider.js';
|
|
25
|
+
|
|
26
|
+
import { actionMap as helloActionMap } from './samples/hello/handlers.js';
|
|
27
|
+
import { actionMap as httpInvokeActionMap } from './samples/http-invoke/handlers.js';
|
|
28
|
+
import { eventSource } from './samples/event-source/event-source.js';
|
|
29
|
+
import { actionMap as snapActionMap } from './samples/snap/snap-handler.js';
|
|
30
|
+
import { echoEventProcessor } from './samples/event-source/event-processor.js';
|
|
31
|
+
import { eventSource as dealerEventSource } from './samples/snap/event-source.js';
|
|
32
|
+
|
|
33
|
+
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
|
+
|
|
58
|
+
await client.connect();
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
// Copyright © 2026 Kaleido, Inc.
|
|
2
|
+
//
|
|
3
|
+
// SPDX-License-Identifier: Apache-2.0
|
|
4
|
+
//
|
|
5
|
+
// Licensed under the Apache License, Version 2.0 (the "License");
|
|
6
|
+
// you may not use this file except in compliance with the License.
|
|
7
|
+
// You may obtain a copy of the License at
|
|
8
|
+
//
|
|
9
|
+
// http://www.apache.org/licenses/LICENSE-2.0
|
|
10
|
+
//
|
|
11
|
+
// Unless required by applicable law or agreed to in writing, software
|
|
12
|
+
// distributed under the License is distributed on an "AS IS" BASIS,
|
|
13
|
+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
14
|
+
// See the License for the specific language governing permissions and
|
|
15
|
+
// limitations under the License.
|
|
16
|
+
|
|
17
|
+
|
|
18
|
+
export default {
|
|
19
|
+
"name": "example-provider",
|
|
20
|
+
"metadata": {
|
|
21
|
+
"displayName": "Example provider",
|
|
22
|
+
"description": "An example provider for the Kaleido Workflow Engine"
|
|
23
|
+
}
|
|
24
|
+
}
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
# Event source sample
|
|
2
|
+
|
|
3
|
+
This example demonstrates how to set up a custom event source that generates events and streams them to an event processor.
|
|
4
|
+
|
|
5
|
+
## Overview
|
|
6
|
+
|
|
7
|
+
The event source sample consists of three main components:
|
|
8
|
+
|
|
9
|
+
1. **Event source** (`event-source.ts`) - Generates timestamped events at regular intervals
|
|
10
|
+
2. **Event Processor** (`event-processor.ts`) - Logs out any events it receives
|
|
11
|
+
3. **Event stream** (`stream.ts`) - Connects the event source to the event processor
|
|
12
|
+
|
|
13
|
+
## How it works
|
|
14
|
+
|
|
15
|
+
### Event source
|
|
16
|
+
|
|
17
|
+
The event source (`event-source.ts`) generates a new timestamped event every ten seconds. When the workflow engine polls for events, the event source checks if more than ten seconds have passed since the last poll time stored in the checkpoint. If so, it generates a new event with:
|
|
18
|
+
|
|
19
|
+
- A unique idempotency key
|
|
20
|
+
- A topic (`my-topic`)
|
|
21
|
+
- A data payload containing a message and timestamp
|
|
22
|
+
|
|
23
|
+
### Stream
|
|
24
|
+
|
|
25
|
+
When an event is received from the event source, the stream (`stream.ts`) ensures that the event is passed on to the event processor handler. In this scenario, for simplicity, the event processor is part of the same provider, but this is not a requirement.
|
|
26
|
+
|
|
27
|
+
### Event processor
|
|
28
|
+
|
|
29
|
+
The event processor (`event-processor.ts`) listens for batches of events and logs them out as they are received. It then updates the checkpoint to acknowledge the event shave been processed.
|
|
30
|
+
|
|
31
|
+
## Usage
|
|
32
|
+
|
|
33
|
+
1. Register the event source in your provider's main file:
|
|
34
|
+
```typescript
|
|
35
|
+
client.registerEventSource('my-listener', eventSource);
|
|
36
|
+
```
|
|
37
|
+
|
|
38
|
+
2. Register the event processor:
|
|
39
|
+
```typescript
|
|
40
|
+
client.registerEventProcessor('echo', echoEventProcessor);
|
|
41
|
+
```
|
|
42
|
+
|
|
43
|
+
3. Start your application to register your provider and handlers with the workflow engine.
|
|
44
|
+
|
|
45
|
+
4. Post the stream to the workflow engine using the utility scripts:
|
|
46
|
+
```bash
|
|
47
|
+
npm run create-stream src/samples/event-source/stream.ts
|
|
48
|
+
```
|
|
49
|
+
|
|
50
|
+
Once configured, the event source will generate events every ten seconds, which will result in the event processor being called.
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
// Copyright © 2026 Kaleido, Inc.
|
|
2
|
+
//
|
|
3
|
+
// SPDX-License-Identifier: Apache-2.0
|
|
4
|
+
//
|
|
5
|
+
// Licensed under the Apache License, Version 2.0 (the "License");
|
|
6
|
+
// you may not use this file except in compliance with the License.
|
|
7
|
+
// You may obtain a copy of the License at
|
|
8
|
+
//
|
|
9
|
+
// http://www.apache.org/licenses/LICENSE-2.0
|
|
10
|
+
//
|
|
11
|
+
// Unless required by applicable law or agreed to in writing, software
|
|
12
|
+
// distributed under the License is distributed on an "AS IS" BASIS,
|
|
13
|
+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
14
|
+
// See the License for the specific language governing permissions and
|
|
15
|
+
// limitations under the License.
|
|
16
|
+
|
|
17
|
+
|
|
18
|
+
import { BasicStageDirector, DirectedActionConfig, EvalResult, InvocationMode, WithStageDirector, WSEvaluateTransaction } from "@kaleido-io/workflow-engine-sdk";
|
|
19
|
+
|
|
20
|
+
class MyHandlerInput implements WithStageDirector {
|
|
21
|
+
public stageDirector: BasicStageDirector;
|
|
22
|
+
public action1?: { inputA: string };
|
|
23
|
+
public action2?: { inputB: string };
|
|
24
|
+
public customData?: any;
|
|
25
|
+
|
|
26
|
+
constructor(data: any) {
|
|
27
|
+
this.stageDirector = new BasicStageDirector(
|
|
28
|
+
data.action || 'echo',
|
|
29
|
+
data.outputPath || '/output',
|
|
30
|
+
data.nextStage || 'end',
|
|
31
|
+
data.failureStage || 'failed'
|
|
32
|
+
);
|
|
33
|
+
this.customData = data.customData;
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
getStageDirector(): BasicStageDirector {
|
|
37
|
+
return this.stageDirector;
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
name(): string {
|
|
41
|
+
return 'echo';
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
const map: Map<string, DirectedActionConfig<MyHandlerInput>> = new Map([
|
|
46
|
+
["echo", {
|
|
47
|
+
invocationMode: InvocationMode.PARALLEL, handler: async (transaction: WSEvaluateTransaction) => {
|
|
48
|
+
if (transaction.state?.input?.data === undefined || transaction.state?.input?.data?.message === undefined) {
|
|
49
|
+
return {
|
|
50
|
+
result: EvalResult.HARD_FAILURE,
|
|
51
|
+
error: new Error('Message is required')
|
|
52
|
+
}
|
|
53
|
+
} else {
|
|
54
|
+
return {
|
|
55
|
+
result: EvalResult.COMPLETE,
|
|
56
|
+
output: {
|
|
57
|
+
message: `Event received with message: ${transaction.state.input.data.message}`,
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
}],
|
|
63
|
+
]);
|
|
64
|
+
|
|
65
|
+
export const actionMap = map;
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
// Copyright © 2026 Kaleido, Inc.
|
|
2
|
+
//
|
|
3
|
+
// SPDX-License-Identifier: Apache-2.0
|
|
4
|
+
//
|
|
5
|
+
// Licensed under the Apache License, Version 2.0 (the "License");
|
|
6
|
+
// you may not use this file except in compliance with the License.
|
|
7
|
+
// You may obtain a copy of the License at
|
|
8
|
+
//
|
|
9
|
+
// http://www.apache.org/licenses/LICENSE-2.0
|
|
10
|
+
//
|
|
11
|
+
// Unless required by applicable law or agreed to in writing, software
|
|
12
|
+
// distributed under the License is distributed on an "AS IS" BASIS,
|
|
13
|
+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
14
|
+
// See the License for the specific language governing permissions and
|
|
15
|
+
// limitations under the License.
|
|
16
|
+
|
|
17
|
+
import { EngineAPI, WSEventProcessorBatchRequest, WSEventProcessorBatchResult } from "@kaleido-io/workflow-engine-sdk";
|
|
18
|
+
|
|
19
|
+
export class MyEventProcessor {
|
|
20
|
+
|
|
21
|
+
constructor() { }
|
|
22
|
+
|
|
23
|
+
name(): string {
|
|
24
|
+
return 'echo';
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
init(_engAPI: EngineAPI): Promise<void> {
|
|
28
|
+
return Promise.resolve();
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
close(): void {
|
|
32
|
+
return;
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
eventProcessorBatch(result: WSEventProcessorBatchResult, batch: WSEventProcessorBatchRequest): Promise<void> {
|
|
36
|
+
for (const event of batch.events) {
|
|
37
|
+
console.log(`Event received: ${event.topic} - ${JSON.stringify(event.data, null, '\t')}`);
|
|
38
|
+
}
|
|
39
|
+
result.checkpoint = {
|
|
40
|
+
lastPollTime: Date.now()
|
|
41
|
+
};
|
|
42
|
+
return Promise.resolve();
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
export const echoEventProcessor = new MyEventProcessor();
|