@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 @@
|
|
|
1
|
+
{"version":3,"file":"transaction_handler.js","sourceRoot":"","sources":["../../../src/factories/transaction_handler.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;AAoBjC,OAAO,EAAE,YAAY,EAAE,MAAM,2BAA2B,CAAC;AAUzD;;GAEG;AACH,MAAM,sBAAsB;IAM1B,YAAY,IAAY,EAAE,SAA+C;QACvE,IAAI,CAAC,KAAK,GAAG,IAAI,CAAC;QAClB,IAAI,CAAC,SAAS,GAAG,SAAS,CAAC;IAC7B,CAAC;IAED,IAAI;QACF,OAAO,IAAI,CAAC,KAAK,CAAC;IACpB,CAAC;IAED,UAAU,CAAC,MAA4C;QACrD,IAAI,CAAC,MAAM,GAAG,MAAM,CAAC;QACrB,OAAO,IAAI,CAAC;IACd,CAAC;IAED,WAAW,CAAC,OAAmB;QAC7B,IAAI,CAAC,OAAO,GAAG,OAAO,CAAC;QACvB,OAAO,IAAI,CAAC;IACd,CAAC;IAED,KAAK,CAAC,IAAI,CAAC,MAAiB;QAC1B,IAAI,IAAI,CAAC,MAAM,EAAE,CAAC;YAChB,MAAM,IAAI,CAAC,MAAM,CAAC,MAAM,CAAC,CAAC;QAC5B,CAAC;IACH,CAAC;IAED,KAAK;QACH,IAAI,IAAI,CAAC,OAAO,EAAE,CAAC;YACjB,IAAI,CAAC,OAAO,EAAE,CAAC;QACjB,CAAC;IACH,CAAC;IAED,KAAK,CAAC,uBAAuB,CAC3B,KAAiC,EACjC,KAA2B;QAE3B,MAAM,YAAY,CAAC,KAAK,EAAE,KAAK,EAAE,IAAI,CAAC,SAAS,CAAC,CAAC;IACnD,CAAC;CACF;AAED;;;;;;;;;GASG;AACH,MAAM,UAAU,6BAA6B,CAC3C,IAAY,EACZ,SAA+C;IAE/C,OAAO,IAAI,sBAAsB,CAAI,IAAI,EAAE,SAAS,CAAC,CAAC;AACxD,CAAC"}
|
|
@@ -0,0 +1,298 @@
|
|
|
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
|
+
* Stage Director Helper
|
|
18
|
+
*
|
|
19
|
+
* Provides the StageDirector pattern for building composable transaction handlers.
|
|
20
|
+
* The StageDirector pattern allows handlers to define multiple "actions" that can
|
|
21
|
+
* be configured to transition to different stages based on success or failure.
|
|
22
|
+
*/
|
|
23
|
+
import { SDKErrors, newError } from '../i18n/errors.js';
|
|
24
|
+
import { newLogger } from '../log/logger.js';
|
|
25
|
+
import { EvalResult, InvocationMode, PatchOpType, } from '../types/core.js';
|
|
26
|
+
import { getErrorMessage } from '../utils/errors.js';
|
|
27
|
+
const log = newLogger('stage_director.ts');
|
|
28
|
+
/**
|
|
29
|
+
* Basic StageDirector implementation
|
|
30
|
+
*/
|
|
31
|
+
export class BasicStageDirector {
|
|
32
|
+
constructor(action, outputPath, nextStage, failureStage) {
|
|
33
|
+
this.action = action;
|
|
34
|
+
this.outputPath = outputPath;
|
|
35
|
+
this.nextStage = nextStage;
|
|
36
|
+
this.failureStage = failureStage;
|
|
37
|
+
}
|
|
38
|
+
getStageDirector() {
|
|
39
|
+
return this;
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
/**
|
|
43
|
+
* Helper class for mapping evaluation results to WebSocket responses
|
|
44
|
+
*/
|
|
45
|
+
export class StageDirectorHelper {
|
|
46
|
+
/**
|
|
47
|
+
* Maps an evaluation result to a WebSocket reply result
|
|
48
|
+
*/
|
|
49
|
+
static mapOutput(stageDirector, transaction, result, output, error, triggers, extraStateUpdates, customStage, events) {
|
|
50
|
+
const replyResult = {};
|
|
51
|
+
// Add triggers if provided
|
|
52
|
+
if (triggers && triggers.length > 0) {
|
|
53
|
+
replyResult.triggers = triggers;
|
|
54
|
+
}
|
|
55
|
+
// Add events if provided
|
|
56
|
+
if (events && events.length > 0) {
|
|
57
|
+
replyResult.events = events;
|
|
58
|
+
}
|
|
59
|
+
// Serialize output to state updates
|
|
60
|
+
if (output !== undefined && output !== null) {
|
|
61
|
+
if (!stageDirector.outputPath) {
|
|
62
|
+
log.error(`Transaction ${transaction.transactionId} cannot store output as outputPath is missing`);
|
|
63
|
+
if (!error) {
|
|
64
|
+
error = newError(SDKErrors.MsgSDKDirectorOutputPathMissing);
|
|
65
|
+
result = EvalResult.FIXABLE_ERROR;
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
else {
|
|
69
|
+
replyResult.stateUpdates = [{
|
|
70
|
+
op: PatchOpType.ADD,
|
|
71
|
+
path: stageDirector.outputPath,
|
|
72
|
+
value: output
|
|
73
|
+
}];
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
// Append any extra state updates provided by the handler
|
|
77
|
+
if (extraStateUpdates && extraStateUpdates.length) {
|
|
78
|
+
replyResult.stateUpdates = (replyResult.stateUpdates || []).concat(extraStateUpdates);
|
|
79
|
+
}
|
|
80
|
+
// Set result based on evaluation outcome
|
|
81
|
+
switch (result) {
|
|
82
|
+
case EvalResult.HARD_FAILURE: {
|
|
83
|
+
// Check if failureStage is missing (validation inside switch for failure-stage handling)
|
|
84
|
+
const failureStage = stageDirector.failureStage;
|
|
85
|
+
if (!failureStage && !customStage) {
|
|
86
|
+
log.error(`Transaction ${transaction.transactionId} cannot be transitioned due to missing failureStage`);
|
|
87
|
+
if (!error) {
|
|
88
|
+
error = newError(SDKErrors.MsgSDKDirectorFailureStageMissing);
|
|
89
|
+
}
|
|
90
|
+
// Fall through to error handling below by breaking and letting default case handle it
|
|
91
|
+
replyResult.error = error.message;
|
|
92
|
+
log.debug(`Transaction ${transaction.transactionId} encountered error: ${error.message}`);
|
|
93
|
+
}
|
|
94
|
+
else {
|
|
95
|
+
// Successfully transitioning to failure stage
|
|
96
|
+
const next = customStage || failureStage;
|
|
97
|
+
replyResult.stage = next;
|
|
98
|
+
// Store error in state at /error path
|
|
99
|
+
if (error) {
|
|
100
|
+
if (!replyResult.stateUpdates) {
|
|
101
|
+
replyResult.stateUpdates = [];
|
|
102
|
+
}
|
|
103
|
+
replyResult.stateUpdates.push({
|
|
104
|
+
op: PatchOpType.ADD,
|
|
105
|
+
path: '/error',
|
|
106
|
+
value: error.message
|
|
107
|
+
});
|
|
108
|
+
}
|
|
109
|
+
log.debug(`Transaction ${transaction.transactionId} directed to failureStage '${next}'`);
|
|
110
|
+
}
|
|
111
|
+
break;
|
|
112
|
+
}
|
|
113
|
+
case EvalResult.COMPLETE: {
|
|
114
|
+
const next = customStage || stageDirector.nextStage;
|
|
115
|
+
if (!next) {
|
|
116
|
+
error = newError(SDKErrors.MsgSDKDirectorNextStageMissing);
|
|
117
|
+
return { error: error.message };
|
|
118
|
+
}
|
|
119
|
+
replyResult.stage = next;
|
|
120
|
+
log.debug(`Transaction ${transaction.transactionId} evaluated successfully and will transition to nextStage '${next}'`);
|
|
121
|
+
break;
|
|
122
|
+
}
|
|
123
|
+
case EvalResult.WAITING:
|
|
124
|
+
log.debug(`Transaction ${transaction.transactionId} evaluated successfully and will remain in stage`);
|
|
125
|
+
break;
|
|
126
|
+
case EvalResult.FIXABLE_ERROR:
|
|
127
|
+
case EvalResult.TRANSIENT_ERROR:
|
|
128
|
+
default:
|
|
129
|
+
if (error) {
|
|
130
|
+
replyResult.error = error.message;
|
|
131
|
+
log.debug(`Transaction ${transaction.transactionId} encountered error: ${error.message}`);
|
|
132
|
+
}
|
|
133
|
+
break;
|
|
134
|
+
}
|
|
135
|
+
return replyResult;
|
|
136
|
+
}
|
|
137
|
+
}
|
|
138
|
+
/**
|
|
139
|
+
* Evaluate a batch of directed transactions
|
|
140
|
+
*
|
|
141
|
+
* This is the core function that processes a batch of transactions using the
|
|
142
|
+
* StageDirector pattern. It groups transactions by action, executes them according
|
|
143
|
+
* to their invocation mode (PARALLEL or BATCH), and maps the results back to
|
|
144
|
+
* the workflow engine's expected format.
|
|
145
|
+
*
|
|
146
|
+
* @param reply The reply object to populate with results
|
|
147
|
+
* @param batch The batch of transactions to process
|
|
148
|
+
* @param actionMap Map of action names to their configurations
|
|
149
|
+
* @param parseInput Function to parse transaction input
|
|
150
|
+
*
|
|
151
|
+
* @example
|
|
152
|
+
* ```typescript
|
|
153
|
+
* evalDirected(reply, batch, actionMap, (input) => input as MyInput);
|
|
154
|
+
* ```
|
|
155
|
+
*/
|
|
156
|
+
export async function evalDirected(reply, batch, actionMap) {
|
|
157
|
+
reply.results = new Array(batch.transactions.length);
|
|
158
|
+
const byAction = new Map();
|
|
159
|
+
// Phase 1: Parse inputs and group by action
|
|
160
|
+
for (let i = 0; i < batch.transactions.length; i++) {
|
|
161
|
+
const req = batch.transactions[i];
|
|
162
|
+
log.debug(`Transaction id=${req.transactionId},workflow=${req.workflowId},stage=${req.stage} evaluating`);
|
|
163
|
+
const execReq = { idx: i, transaction: req, input: {} };
|
|
164
|
+
try {
|
|
165
|
+
// Direct type assertion for transaction input (JSON-deserialized generic type)
|
|
166
|
+
execReq.input = req.input;
|
|
167
|
+
// Check if input is valid (not null or undefined)
|
|
168
|
+
if (!execReq.input) {
|
|
169
|
+
throw newError(SDKErrors.MsgSDKInputNullOrUndefined, req.stage);
|
|
170
|
+
}
|
|
171
|
+
// If input doesn't have getStageDirector method (plain object from JSON),
|
|
172
|
+
// wrap it to provide the method
|
|
173
|
+
if (typeof execReq.input.getStageDirector !== 'function') {
|
|
174
|
+
const plainInput = execReq.input;
|
|
175
|
+
// Validate that the plain input has the required action field
|
|
176
|
+
if (!plainInput.action) {
|
|
177
|
+
throw newError(SDKErrors.MsgSDKMissingActionField, req.stage, Object.keys(plainInput).join(', '));
|
|
178
|
+
}
|
|
179
|
+
execReq.input = {
|
|
180
|
+
...plainInput,
|
|
181
|
+
getStageDirector: () => ({
|
|
182
|
+
action: plainInput.action,
|
|
183
|
+
outputPath: plainInput.outputPath,
|
|
184
|
+
nextStage: plainInput.nextStage,
|
|
185
|
+
failureStage: plainInput.failureStage
|
|
186
|
+
})
|
|
187
|
+
};
|
|
188
|
+
}
|
|
189
|
+
}
|
|
190
|
+
catch (error) {
|
|
191
|
+
log.error(`Transaction id=${req.transactionId} could not be parsed: ${error}`);
|
|
192
|
+
reply.results[i] = {
|
|
193
|
+
error: `Input parsing error: ${getErrorMessage(error)}`
|
|
194
|
+
};
|
|
195
|
+
continue;
|
|
196
|
+
}
|
|
197
|
+
const sd = execReq.input.getStageDirector();
|
|
198
|
+
const actionConf = actionMap.get(sd.action);
|
|
199
|
+
if (!actionConf) {
|
|
200
|
+
reply.results[i] = {
|
|
201
|
+
error: `Invalid action '${sd.action}' for handler '${batch.handler}'`
|
|
202
|
+
};
|
|
203
|
+
continue;
|
|
204
|
+
}
|
|
205
|
+
if (!byAction.has(sd.action)) {
|
|
206
|
+
byAction.set(sd.action, []);
|
|
207
|
+
}
|
|
208
|
+
byAction.get(sd.action).push(execReq);
|
|
209
|
+
}
|
|
210
|
+
// Phase 2: Execute transactions by action
|
|
211
|
+
const completions = [];
|
|
212
|
+
for (const [actionName, transactions] of byAction) {
|
|
213
|
+
const actionConf = actionMap.get(actionName);
|
|
214
|
+
switch (actionConf.invocationMode) {
|
|
215
|
+
case InvocationMode.PARALLEL:
|
|
216
|
+
// Execute each transaction in parallel
|
|
217
|
+
for (const req of transactions) {
|
|
218
|
+
completions.push((async () => {
|
|
219
|
+
req.result = await execMapped(actionConf, req.transaction, req.input);
|
|
220
|
+
return req;
|
|
221
|
+
})());
|
|
222
|
+
}
|
|
223
|
+
break;
|
|
224
|
+
case InvocationMode.BATCH: {
|
|
225
|
+
// Execute all transactions for this action as a batch
|
|
226
|
+
// Note: We execute the batch as one async operation, but add each
|
|
227
|
+
// individual transaction to completions
|
|
228
|
+
const batchPromise = (async () => {
|
|
229
|
+
const batchIn = transactions.map(r => ({
|
|
230
|
+
transaction: r.transaction,
|
|
231
|
+
value: r.input
|
|
232
|
+
}));
|
|
233
|
+
const batchOut = await execBatchMapped(actionConf, batchIn);
|
|
234
|
+
for (let i = 0; i < transactions.length; i++) {
|
|
235
|
+
transactions[i].result = batchOut[i];
|
|
236
|
+
}
|
|
237
|
+
return transactions;
|
|
238
|
+
})();
|
|
239
|
+
// Add each transaction as a separate completion to maintain flat array structure
|
|
240
|
+
for (const req of transactions) {
|
|
241
|
+
completions.push(batchPromise.then(() => req));
|
|
242
|
+
}
|
|
243
|
+
break;
|
|
244
|
+
}
|
|
245
|
+
}
|
|
246
|
+
}
|
|
247
|
+
// Phase 3: Wait for all completions and collect results
|
|
248
|
+
const completed = await Promise.all(completions);
|
|
249
|
+
for (const execReq of completed) {
|
|
250
|
+
if (execReq.result) {
|
|
251
|
+
reply.results[execReq.idx] = execReq.result;
|
|
252
|
+
}
|
|
253
|
+
}
|
|
254
|
+
}
|
|
255
|
+
/**
|
|
256
|
+
* Execute a single mapped transaction
|
|
257
|
+
*/
|
|
258
|
+
async function execMapped(config, transaction, input) {
|
|
259
|
+
try {
|
|
260
|
+
if (!config.handler) {
|
|
261
|
+
throw newError(SDKErrors.MsgSDKHandlerNotConfigured);
|
|
262
|
+
}
|
|
263
|
+
const handlerResult = await config.handler(transaction, input);
|
|
264
|
+
const { result, output, error, triggers, extraUpdates, customStage, events } = handlerResult;
|
|
265
|
+
return StageDirectorHelper.mapOutput(input.getStageDirector(), transaction, result, output, error, triggers, extraUpdates, customStage, events);
|
|
266
|
+
}
|
|
267
|
+
catch (error) {
|
|
268
|
+
log.error(`Handler execution failed:`, error);
|
|
269
|
+
return {
|
|
270
|
+
error: getErrorMessage(error)
|
|
271
|
+
};
|
|
272
|
+
}
|
|
273
|
+
}
|
|
274
|
+
/**
|
|
275
|
+
* Execute a batch of mapped transactions
|
|
276
|
+
*/
|
|
277
|
+
async function execBatchMapped(config, transactions) {
|
|
278
|
+
if (!config.batchHandler) {
|
|
279
|
+
throw newError(SDKErrors.MsgSDKBatchHandlerNotConfigured);
|
|
280
|
+
}
|
|
281
|
+
try {
|
|
282
|
+
const batchResults = await config.batchHandler(transactions);
|
|
283
|
+
if (batchResults.length !== transactions.length) {
|
|
284
|
+
throw newError(SDKErrors.MsgSDKBatchHandlerResultCountMismatch, batchResults.length, transactions.length);
|
|
285
|
+
}
|
|
286
|
+
return transactions.map((req, i) => {
|
|
287
|
+
const batchResult = batchResults[i];
|
|
288
|
+
return StageDirectorHelper.mapOutput(req.value.getStageDirector(), req.transaction, batchResult.result, batchResult.output, batchResult.error, batchResult.triggers, batchResult.extraUpdates, batchResult.customStage);
|
|
289
|
+
});
|
|
290
|
+
}
|
|
291
|
+
catch (error) {
|
|
292
|
+
log.error(`Batch handler execution failed:`, error);
|
|
293
|
+
return transactions.map(() => ({
|
|
294
|
+
error: getErrorMessage(error)
|
|
295
|
+
}));
|
|
296
|
+
}
|
|
297
|
+
}
|
|
298
|
+
//# sourceMappingURL=stage_director.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"stage_director.js","sourceRoot":"","sources":["../../../src/helpers/stage_director.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;;;;;;GAMG;AAEH,OAAO,EAAE,SAAS,EAAE,QAAQ,EAAE,MAAM,gBAAgB,CAAC;AAKrD,OAAO,EAAE,SAAS,EAAE,MAAM,eAAe,CAAC;AAC1C,OAAO,EACL,UAAU,EAGV,cAAc,EAEd,WAAW,GAQZ,MAAM,eAAe,CAAC;AACvB,OAAO,EAAE,eAAe,EAAE,MAAM,iBAAiB,CAAC;AAElD,MAAM,GAAG,GAAG,SAAS,CAAC,mBAAmB,CAAC,CAAC;AAE3C;;GAEG;AACH,MAAM,OAAO,kBAAkB;IAC7B,YACS,MAAc,EACd,UAAkB,EAClB,SAAiB,EACjB,YAAoB;QAHpB,WAAM,GAAN,MAAM,CAAQ;QACd,eAAU,GAAV,UAAU,CAAQ;QAClB,cAAS,GAAT,SAAS,CAAQ;QACjB,iBAAY,GAAZ,YAAY,CAAQ;IACzB,CAAC;IAEL,gBAAgB;QACd,OAAO,IAAI,CAAC;IACd,CAAC;CACF;AAED;;GAEG;AACH,MAAM,OAAO,mBAAmB;IAC9B;;OAEG;IACH,MAAM,CAAC,SAAS,CACd,aAA4B,EAC5B,WAAkC,E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AE,YAAY,CAAC,MAAM,EAAE,YAAY,CAAC,MAAM,CAAC,CAAC;QAC5G,CAAC;QAED,OAAO,YAAY,CAAC,GAAG,CAAC,CAAC,GAAG,EAAE,CAAC,EAAE,EAAE;YACjC,MAAM,WAAW,GAAG,YAAY,CAAC,CAAC,CAAC,CAAC;YACpC,OAAO,mBAAmB,CAAC,SAAS,CAClC,GAAG,CAAC,KAAK,CAAC,gBAAgB,EAAE,EAC5B,GAAG,CAAC,WAAW,EACf,WAAW,CAAC,MAAM,EAClB,WAAW,CAAC,MAAM,EAClB,WAAW,CAAC,KAAK,EACjB,WAAW,CAAC,QAAQ,EACpB,WAAW,CAAC,YAAY,EACxB,WAAW,CAAC,WAAW,CACxB,CAAC;QACJ,CAAC,CAAC,CAAC;IACL,CAAC;IAAC,OAAO,KAAK,EAAE,CAAC;QACf,GAAG,CAAC,KAAK,CAAC,iCAAiC,EAAE,KAAK,CAAC,CAAC;QACpD,OAAO,YAAY,CAAC,GAAG,CAAC,GAAG,EAAE,CAAC,CAAC;YAC7B,KAAK,EAAE,eAAe,CAAC,KAAK,CAAC;SAC9B,CAAC,CAAC,CAAC;IACN,CAAC;AACH,CAAC"}
|
|
@@ -0,0 +1,85 @@
|
|
|
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
|
+
* Create a formatted error with code and message
|
|
18
|
+
*/
|
|
19
|
+
function fe(code, template) {
|
|
20
|
+
return { code, message: template };
|
|
21
|
+
}
|
|
22
|
+
/**
|
|
23
|
+
* SDK error messages
|
|
24
|
+
*/
|
|
25
|
+
export const SDKErrors = {
|
|
26
|
+
// Handler errors (KA1406XX)
|
|
27
|
+
MsgSDKObservedPanic: fe('KA140600', 'Observed panic: %s'),
|
|
28
|
+
MsgSDKUnknownHandler: fe('KA140601', "Unknown handler '%s'"),
|
|
29
|
+
MsgSDKUnknownNoListenerConfig: fe('KA140602', "Listener config for stream '%s' not supplied by workflow engine"),
|
|
30
|
+
MsgSDKOutputSerializationError: fe('KA140603', "Unable to serialize output to %s"),
|
|
31
|
+
MsgSDKDirectorNextStageMissing: fe('KA140604', "Handler called with 'nextStage' missing from input"),
|
|
32
|
+
MsgSDKDirectorOutputPathMissing: fe('KA140605', "Handler called with 'outputPath' missing from input"),
|
|
33
|
+
MsgSDKDirectorFailureStageMissing: fe('KA140606', "Handler resulted in a failure, but 'failureStage' missing from input"),
|
|
34
|
+
MsgSDKInputParsingError: fe('KA140607', 'Unable to parse input'),
|
|
35
|
+
MsgSDKInvalidAction: fe('KA140608', "Action '%s' is invalid for handler '%s'"),
|
|
36
|
+
MsgSDKInvalidResult: fe('KA140609', "Action '%s' gave unexpected result '%s' without error"),
|
|
37
|
+
// Event source errors
|
|
38
|
+
MsgSDKCheckpointInvalidForHandler: fe('KA140610', "Checkpoint could not be parsed by handler '%s'"),
|
|
39
|
+
MsgSDKStreamConfigInvalidForHandler: fe('KA140611', "Event stream config could not be parsed by handler '%s'"),
|
|
40
|
+
MsgSDKCheckpointInvalid: fe('KA140612', "Checkpoint generated by handler '%s' cannot be serialized"),
|
|
41
|
+
MsgSDKEventSourceDataInvalid: fe('KA140613', "Event source data could not be serialized for handler '%s'"),
|
|
42
|
+
// Engine API errors
|
|
43
|
+
MsgSDKEngineReplyInvalidData: fe('KA140614', "Engine API reply for transaction %s invalid: %s"),
|
|
44
|
+
MsgSDKEngineReplyInvalidType: fe('KA140615', "Engine API reply type for transaction %s invalid: %s"),
|
|
45
|
+
MsgSDKEngineReqNoActiveRequest: fe('KA140616', 'No engine handler is active on the supplied context'),
|
|
46
|
+
MsgSDKEngineFailMarshalEngineRequest: fe('KA140617', 'Failed to marshal engine transaction data'),
|
|
47
|
+
MsgSDKEngineFailSendEngineRequest: fe('KA140618', 'Failed to send engine transaction'),
|
|
48
|
+
MsgSDKEngineNoTokenAuthRef: fe('KA140619', "No auth token available in engine supplied context for authRef '%s'"),
|
|
49
|
+
// Configuration errors
|
|
50
|
+
MsgSDKProviderNameNotSet: fe('KA140620', 'Provider name not set'),
|
|
51
|
+
MsgSDKURLRequiredOutbound: fe('KA140630', 'URL is required in outbound mode'),
|
|
52
|
+
MsgSDKWebSocketPortRequiredInbound: fe('KA140631', 'WEBSOCKET_PORT is required in inbound mode'),
|
|
53
|
+
MsgSDKAccountNotSet: fe('KA140632', 'ACCOUNT is not set and no baseUrl provided'),
|
|
54
|
+
MsgSDKEnvironmentNotSet: fe('KA140633', 'ENVIRONMENT is not set and no baseUrl provided'),
|
|
55
|
+
MsgSDKWorkflowEngineNotSet: fe('KA140634', 'WORKFLOW_ENGINE is not set and no baseUrl provided'),
|
|
56
|
+
// Stage Director errors
|
|
57
|
+
MsgSDKHandlerNotConfigured: fe('KA140621', 'Handler not configured for this action'),
|
|
58
|
+
MsgSDKBatchHandlerNotConfigured: fe('KA140622', 'Handler not configured for BATCH invocation mode'),
|
|
59
|
+
MsgSDKBatchHandlerResultCountMismatch: fe('KA140623', 'Batch handler returned %d results but expected %d'),
|
|
60
|
+
MsgSDKInputNullOrUndefined: fe('KA140628', 'Input is null or undefined in stage %s'),
|
|
61
|
+
MsgSDKMissingActionField: fe('KA140629', 'Input is missing required "action" field in stage %s. Available fields: %s'),
|
|
62
|
+
// Configuration validation errors
|
|
63
|
+
MsgSDKConfigUnknownAuthType: fe('KA140626', 'Unknown auth type: %s'),
|
|
64
|
+
// Engine connection errors
|
|
65
|
+
MsgSDKEngineNotConnected: fe('KA140627', 'WebSocket is not connected. Cannot submit async transactions'),
|
|
66
|
+
};
|
|
67
|
+
/**
|
|
68
|
+
* Format an error message with arguments
|
|
69
|
+
* Supports simple %s, %d placeholders
|
|
70
|
+
*/
|
|
71
|
+
export function formatError(errorMsg, ...args) {
|
|
72
|
+
let formatted = errorMsg.message;
|
|
73
|
+
for (const arg of args) {
|
|
74
|
+
// Replace first occurrence of %s or %d
|
|
75
|
+
formatted = formatted.replace(/%[sd]/, String(arg));
|
|
76
|
+
}
|
|
77
|
+
return `${errorMsg.code}: ${formatted}`;
|
|
78
|
+
}
|
|
79
|
+
/**
|
|
80
|
+
* Create a new Error with an i18n message
|
|
81
|
+
*/
|
|
82
|
+
export function newError(errorMsg, ...args) {
|
|
83
|
+
return new Error(formatError(errorMsg, ...args));
|
|
84
|
+
}
|
|
85
|
+
//# sourceMappingURL=errors.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"errors.js","sourceRoot":"","sources":["../../../src/i18n/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;AAkBjC;;GAEG;AACH,SAAS,EAAE,CAAC,IAAY,EAAE,QAAgB;IACxC,OAAO,EAAE,IAAI,EAAE,OAAO,EAAE,QAAQ,EAAE,CAAC;AACrC,CAAC;AAED;;GAEG;AACH,MAAM,CAAC,MAAM,SAAS,GAAG;IACvB,4BAA4B;IAC5B,mBAAmB,EAAE,EAAE,CAAC,UAAU,EAAE,oBAAoB,CAAC;IACzD,oBAAoB,EAAE,EAAE,CAAC,UAAU,EAAE,sBAAsB,C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CAAC"}
|
|
@@ -0,0 +1,51 @@
|
|
|
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
|
+
* Kaleido Workflow Engine SDK - TypeScript
|
|
18
|
+
*/
|
|
19
|
+
// ============================================================================
|
|
20
|
+
// Client Entry Point
|
|
21
|
+
// ============================================================================
|
|
22
|
+
export { WorkflowEngineClient, } from './client/client.js';
|
|
23
|
+
export { WorkflowEngineRestClient, } from './client/rest-client.js';
|
|
24
|
+
export { ConfigLoader, } from './config/config.js';
|
|
25
|
+
export { newLogger } from './log/logger.js';
|
|
26
|
+
// ============================================================================
|
|
27
|
+
// Core Types & Interfaces
|
|
28
|
+
// ============================================================================
|
|
29
|
+
export * from './types/core.js';
|
|
30
|
+
export * from './interfaces/handlers.js';
|
|
31
|
+
export * from './interfaces/messages.js';
|
|
32
|
+
// ============================================================================
|
|
33
|
+
// Factories & Helpers
|
|
34
|
+
// ============================================================================
|
|
35
|
+
// Transaction handler factory
|
|
36
|
+
export { newDirectedTransactionHandler, } from './factories/transaction_handler.js';
|
|
37
|
+
// Event source factory
|
|
38
|
+
export { newEventSource, } from './factories/event_source.js';
|
|
39
|
+
// Stage director helpers
|
|
40
|
+
export { BasicStageDirector, StageDirectorHelper, evalDirected, } from './helpers/stage_director.js';
|
|
41
|
+
// Configuration
|
|
42
|
+
export * from './config/config.js';
|
|
43
|
+
// Utilities
|
|
44
|
+
// ============================================================================
|
|
45
|
+
// JSON Patch utilities
|
|
46
|
+
export { apply, addOp, removeOp, replaceOp, moveOp, copyOp, testOp, } from './utils/patch.js';
|
|
47
|
+
// Logger
|
|
48
|
+
export * from './log/logger.js';
|
|
49
|
+
export * from './i18n/errors.js';
|
|
50
|
+
export { HandlerRuntimeMode } from './runtime/handler_runtime.js';
|
|
51
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.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,+EAA+E;AAC/E,qBAAqB;AACrB,+EAA+E;AAE/E,OAAO,EACL,oBAAoB,GAErB,MAAM,iBAAiB,CAAC;AAEzB,OAAO,EACL,wBAAwB,GASzB,MAAM,sBAAsB,CAAC;AAE9B,OAAO,EAEL,YAAY,GACb,MAAM,iBAAiB,CAAC;AAEzB,OAAO,EAAE,SAAS,EAAE,MAAM,cAAc,CAAC;AAEzC,+EAA+E;AAC/E,0BAA0B;AAC1B,+EAA+E;AAE/E,cAAc,cAAc,CAAC;AAC7B,cAAc,uBAAuB,CAAC;AACtC,cAAc,uBAAuB,CAAC;AAEtC,+EAA+E;AAC/E,sBAAsB;AACtB,+EAA+E;AAE/E,8BAA8B;AAC9B,OAAO,EACL,6BAA6B,GAE9B,MAAM,iCAAiC,CAAC;AAEzC,uBAAuB;AACvB,OAAO,EACL,cAAc,GAQf,MAAM,0BAA0B,CAAC;AAElC,yBAAyB;AACzB,OAAO,EACL,kBAAkB,EAClB,mBAAmB,EACnB,YAAY,GACb,MAAM,0BAA0B,CAAC;AAElC,gBAAgB;AAChB,cAAc,iBAAiB,CAAC;AAEhC,YAAY;AACZ,+EAA+E;AAE/E,uBAAuB;AACvB,OAAO,EACL,KAAK,EACL,KAAK,EACL,QAAQ,EACR,SAAS,EACT,MAAM,EACN,MAAM,EACN,MAAM,GACP,MAAM,eAAe,CAAC;AAEvB,SAAS;AACT,cAAc,cAAc,CAAC;AAE7B,cAAc,eAAe,CAAC;AAI9B,OAAO,EAAE,kBAAkB,EAAE,MAAM,2BAA2B,CAAC"}
|
|
@@ -0,0 +1,17 @@
|
|
|
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 {};
|
|
17
|
+
//# sourceMappingURL=handlers.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"handlers.js","sourceRoot":"","sources":["../../../src/interfaces/handlers.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"}
|
|
@@ -0,0 +1,17 @@
|
|
|
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 {};
|
|
17
|
+
//# sourceMappingURL=messages.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"messages.js","sourceRoot":"","sources":["../../../src/interfaces/messages.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"}
|
|
@@ -0,0 +1,36 @@
|
|
|
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
|
+
class ConsoleLogger {
|
|
17
|
+
constructor(context) {
|
|
18
|
+
this.context = context;
|
|
19
|
+
}
|
|
20
|
+
debug(message, ...args) {
|
|
21
|
+
console.debug(`[${this.context}] ${message}`, ...args);
|
|
22
|
+
}
|
|
23
|
+
info(message, ...args) {
|
|
24
|
+
console.info(`[${this.context}] ${message}`, ...args);
|
|
25
|
+
}
|
|
26
|
+
warn(message, ...args) {
|
|
27
|
+
console.warn(`[${this.context}] ${message}`, ...args);
|
|
28
|
+
}
|
|
29
|
+
error(message, ...args) {
|
|
30
|
+
console.error(`[${this.context}] ${message}`, ...args);
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
export function newLogger(context) {
|
|
34
|
+
return new ConsoleLogger(context);
|
|
35
|
+
}
|
|
36
|
+
//# sourceMappingURL=logger.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"logger.js","sourceRoot":"","sources":["../../../src/log/logger.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;AAUjC,MAAM,aAAa;IACjB,YAAoB,OAAe;QAAf,YAAO,GAAP,OAAO,CAAQ;IAAG,CAAC;IAEvC,KAAK,CAAC,OAAe,EAAE,GAAG,IAAW;QACnC,OAAO,CAAC,KAAK,CAAC,IAAI,IAAI,CAAC,OAAO,KAAK,OAAO,EAAE,EAAE,GAAG,IAAI,CAAC,CAAC;IACzD,CAAC;IAED,IAAI,CAAC,OAAe,EAAE,GAAG,IAAW;QAClC,OAAO,CAAC,IAAI,CAAC,IAAI,IAAI,CAAC,OAAO,KAAK,OAAO,EAAE,EAAE,GAAG,IAAI,CAAC,CAAC;IACxD,CAAC;IAED,IAAI,CAAC,OAAe,EAAE,GAAG,IAAW;QAClC,OAAO,CAAC,IAAI,CAAC,IAAI,IAAI,CAAC,OAAO,KAAK,OAAO,EAAE,EAAE,GAAG,IAAI,CAAC,CAAC;IACxD,CAAC;IAED,KAAK,CAAC,OAAe,EAAE,GAAG,IAAW;QACnC,OAAO,CAAC,KAAK,CAAC,IAAI,IAAI,CAAC,OAAO,KAAK,OAAO,EAAE,EAAE,GAAG,IAAI,CAAC,CAAC;IACzD,CAAC;CACF;AAED,MAAM,UAAU,SAAS,CAAC,OAAe;IACvC,OAAO,IAAI,aAAa,CAAC,OAAO,CAAC,CAAC;AACpC,CAAC"}
|
|
@@ -0,0 +1,95 @@
|
|
|
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 { WSMessageType, } from '../types/core.js';
|
|
17
|
+
import { newLogger } from '../log/logger.js';
|
|
18
|
+
import { SDKErrors, newError } from '../i18n/errors.js';
|
|
19
|
+
const log = newLogger('engine_client');
|
|
20
|
+
/**
|
|
21
|
+
* Client for handlers to call back to the workflow engine.
|
|
22
|
+
* Implements the EngineAPI interface and handles the round-trip
|
|
23
|
+
* communication pattern for async operations like submitting transactions.
|
|
24
|
+
*/
|
|
25
|
+
export class EngineClient {
|
|
26
|
+
constructor(runtime) {
|
|
27
|
+
this.inflightRequests = new Map();
|
|
28
|
+
this.runtime = runtime;
|
|
29
|
+
}
|
|
30
|
+
/**
|
|
31
|
+
* Submit async transactions to the workflow engine
|
|
32
|
+
*/
|
|
33
|
+
async submitAsyncTransactions(authRef, transactions) {
|
|
34
|
+
if (!this.runtime.isWebSocketConnected()) {
|
|
35
|
+
throw newError(SDKErrors.MsgSDKEngineNotConnected);
|
|
36
|
+
}
|
|
37
|
+
const activeContext = this.runtime.getActiveHandlerContext();
|
|
38
|
+
if (!activeContext) {
|
|
39
|
+
throw newError(SDKErrors.MsgSDKEngineReqNoActiveRequest);
|
|
40
|
+
}
|
|
41
|
+
const requestId = this.generateId();
|
|
42
|
+
log.debug('Submitting async transactions', {
|
|
43
|
+
requestId,
|
|
44
|
+
authRef,
|
|
45
|
+
count: transactions.length
|
|
46
|
+
});
|
|
47
|
+
const request = {
|
|
48
|
+
messageType: WSMessageType.ENGINE_API_SUBMIT_TRANSACTIONS,
|
|
49
|
+
id: requestId,
|
|
50
|
+
activeRequestId: activeContext.requestId,
|
|
51
|
+
authRef: authRef,
|
|
52
|
+
transactions: transactions,
|
|
53
|
+
};
|
|
54
|
+
return this.roundTrip(request, requestId);
|
|
55
|
+
}
|
|
56
|
+
/**
|
|
57
|
+
* Handle response for inflight request
|
|
58
|
+
*/
|
|
59
|
+
handleResponse(message) {
|
|
60
|
+
const inflight = this.inflightRequests.get(message.id);
|
|
61
|
+
if (inflight) {
|
|
62
|
+
this.inflightRequests.delete(message.id);
|
|
63
|
+
if (message.error) {
|
|
64
|
+
log.error('EngineAPI request failed', {
|
|
65
|
+
id: message.id,
|
|
66
|
+
error: message.error
|
|
67
|
+
});
|
|
68
|
+
inflight.reject(new Error(message.error));
|
|
69
|
+
}
|
|
70
|
+
else {
|
|
71
|
+
log.debug('EngineAPI request succeeded', {
|
|
72
|
+
id: message.id,
|
|
73
|
+
results: message.submissions?.length
|
|
74
|
+
});
|
|
75
|
+
inflight.resolve(message.submissions || []);
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
else {
|
|
79
|
+
log.warn('Received response for unknown request', { id: message.id });
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
/**
|
|
83
|
+
* Round-trip request/response pattern
|
|
84
|
+
*/
|
|
85
|
+
roundTrip(request, requestId) {
|
|
86
|
+
return new Promise((resolve, reject) => {
|
|
87
|
+
this.inflightRequests.set(requestId, { resolve, reject });
|
|
88
|
+
this.runtime.sendMessage(request);
|
|
89
|
+
});
|
|
90
|
+
}
|
|
91
|
+
generateId() {
|
|
92
|
+
return `${Date.now()}-${Math.random().toString(36).slice(2, 11)}`;
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
//# sourceMappingURL=engine_client.js.map
|