@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":"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,+DAAiD;AACjD,wCAA4D;AAE5D,MAAM,EAAE,UAAU,EAAE,GAAG,aAAa,CAAC;AAE9B,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;AAPW,QAAA,KAAK,SAOhB;AAEF,gCAAgC;AACzB,MAAM,KAAK,GAAG,CAAC,IAAY,EAAE,KAAc,EAAW,EAAE,CAAC,CAAC;IAC/D,EAAE,EAAE,kBAAW,CAAC,GAAG;IACnB,IAAI;IACJ,KAAK;CACN,CAAC,CAAC;AAJU,QAAA,KAAK,SAIf;AAEI,MAAM,QAAQ,GAAG,CAAC,IAAY,EAAW,EAAE,CAAC,CAAC;IAClD,EAAE,EAAE,kBAAW,CAAC,MAAM;IACtB,IAAI;CACL,CAAC,CAAC;AAHU,QAAA,QAAQ,YAGlB;AAEI,MAAM,SAAS,GAAG,CAAC,IAAY,EAAE,KAAc,EAAW,EAAE,CAAC,CAAC;IACnE,EAAE,EAAE,kBAAW,CAAC,OAAO;IACvB,IAAI;IACJ,KAAK;CACN,CAAC,CAAC;AAJU,QAAA,SAAS,aAInB;AAEI,MAAM,MAAM,GAAG,CAAC,IAAY,EAAE,IAAY,EAAW,EAAE,CAAC,CAAC;IAC9D,EAAE,EAAE,kBAAW,CAAC,IAAI;IACpB,IAAI;IACJ,IAAI;CACL,CAAC,CAAC;AAJU,QAAA,MAAM,UAIhB;AAEI,MAAM,MAAM,GAAG,CAAC,IAAY,EAAE,IAAY,EAAW,EAAE,CAAC,CAAC;IAC9D,EAAE,EAAE,kBAAW,CAAC,IAAI;IACpB,IAAI;IACJ,IAAI;CACL,CAAC,CAAC;AAJU,QAAA,MAAM,UAIhB;AAEI,MAAM,MAAM,GAAG,CAAC,IAAY,EAAE,KAAc,EAAW,EAAE,CAAC,CAAC;IAChE,EAAE,EAAE,kBAAW,CAAC,IAAI;IACpB,IAAI;IACJ,KAAK;CACN,CAAC,CAAC;AAJU,QAAA,MAAM,UAIhB"}
|
|
@@ -0,0 +1,54 @@
|
|
|
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 { HandlerRuntime } from '../runtime/handler_runtime.js';
|
|
17
|
+
export class WorkflowEngineClient {
|
|
18
|
+
constructor(config) {
|
|
19
|
+
const runtimeConfig = {
|
|
20
|
+
url: config.url,
|
|
21
|
+
providerName: config.providerName,
|
|
22
|
+
providerMetadata: config.providerMetadata,
|
|
23
|
+
authToken: config.authToken,
|
|
24
|
+
authHeaderName: config.authHeaderName,
|
|
25
|
+
headers: config.headers,
|
|
26
|
+
options: config.options,
|
|
27
|
+
reconnectDelay: config.reconnectDelay,
|
|
28
|
+
maxAttempts: config.maxAttempts,
|
|
29
|
+
};
|
|
30
|
+
this.runtime = new HandlerRuntime(runtimeConfig);
|
|
31
|
+
}
|
|
32
|
+
registerTransactionHandler(name, handler) {
|
|
33
|
+
this.runtime.registerTransactionHandler(name, handler);
|
|
34
|
+
}
|
|
35
|
+
registerEventSource(name, handler) {
|
|
36
|
+
this.runtime.registerEventSource(name, handler);
|
|
37
|
+
}
|
|
38
|
+
registerEventProcessor(name, handler) {
|
|
39
|
+
this.runtime.registerEventProcessor(name, handler);
|
|
40
|
+
}
|
|
41
|
+
async connect() {
|
|
42
|
+
await this.runtime.start();
|
|
43
|
+
}
|
|
44
|
+
disconnect() {
|
|
45
|
+
this.runtime.stop();
|
|
46
|
+
}
|
|
47
|
+
close() {
|
|
48
|
+
this.disconnect();
|
|
49
|
+
}
|
|
50
|
+
isConnected() {
|
|
51
|
+
return this.runtime.isWebSocketConnected();
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
//# sourceMappingURL=client.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"client.js","sourceRoot":"","sources":["../../../src/client/client.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,EAAE,cAAc,EAAwB,MAAM,4BAA4B,CAAC;AAelF,MAAM,OAAO,oBAAoB;IAG/B,YAAY,MAAkC;QAC5C,MAAM,aAAa,GAAyB;YAC1C,GAAG,EAAE,MAAM,CAAC,GAAG;YACf,YAAY,EAAE,MAAM,CAAC,YAAY;YACjC,gBAAgB,EAAE,MAAM,CAAC,gBAAgB;YACzC,SAAS,EAAE,MAAM,CAAC,SAAS;YAC3B,cAAc,EAAE,MAAM,CAAC,cAAc;YACrC,OAAO,EAAE,MAAM,CAAC,OAAO;YACvB,OAAO,EAAE,MAAM,CAAC,OAAO;YACvB,cAAc,EAAE,MAAM,CAAC,cAAc;YACrC,WAAW,EAAE,MAAM,CAAC,WAAW;SAChC,CAAC;QAEF,IAAI,CAAC,OAAO,GAAG,IAAI,cAAc,CAAC,aAAa,CAAC,CAAC;IACnD,CAAC;IAED,0BAA0B,CAAC,IAAY,EAAE,OAA2B;QAClE,IAAI,CAAC,OAAO,CAAC,0BAA0B,CAAC,IAAI,EAAE,OAAO,CAAC,CAAC;IACzD,CAAC;IAED,mBAAmB,CAAC,IAAY,EAAE,OAAoB;QACpD,IAAI,CAAC,OAAO,CAAC,mBAAmB,CAAC,IAAI,EAAE,OAAO,CAAC,CAAC;IAClD,CAAC;IAED,sBAAsB,CAAC,IAAY,EAAE,OAAuB;QAC1D,IAAI,CAAC,OAAO,CAAC,sBAAsB,CAAC,IAAI,EAAE,OAAO,CAAC,CAAC;IACrD,CAAC;IAED,KAAK,CAAC,OAAO;QACX,MAAM,IAAI,CAAC,OAAO,CAAC,KAAK,EAAE,CAAC;IAC7B,CAAC;IAED,UAAU;QACR,IAAI,CAAC,OAAO,CAAC,IAAI,EAAE,CAAC;IACtB,CAAC;IAED,KAAK;QACH,IAAI,CAAC,UAAU,EAAE,CAAC;IACpB,CAAC;IAED,WAAW;QACT,OAAO,IAAI,CAAC,OAAO,CAAC,oBAAoB,EAAE,CAAC;IAC7C,CAAC;CACF"}
|
|
@@ -0,0 +1,238 @@
|
|
|
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
|
+
* REST Client for Workflow Engine API
|
|
18
|
+
*
|
|
19
|
+
* Provides methods to interact with the workflow engine REST API including:
|
|
20
|
+
* - Workflow management (create, delete)
|
|
21
|
+
* - Transaction management (create, delete)
|
|
22
|
+
* - Stream management (create, delete, start, stop)
|
|
23
|
+
*/
|
|
24
|
+
import { newError, SDKErrors } from '../i18n/errors.js';
|
|
25
|
+
/**
|
|
26
|
+
* REST Client for Workflow Engine API
|
|
27
|
+
*/
|
|
28
|
+
export class WorkflowEngineRestClient {
|
|
29
|
+
constructor(config) {
|
|
30
|
+
// Build base URL from environment variables if not provided
|
|
31
|
+
if (!config?.url) {
|
|
32
|
+
if (!process.env.ACCOUNT) {
|
|
33
|
+
throw newError(SDKErrors.MsgSDKAccountNotSet);
|
|
34
|
+
}
|
|
35
|
+
if (!process.env.ENVIRONMENT) {
|
|
36
|
+
throw newError(SDKErrors.MsgSDKEnvironmentNotSet);
|
|
37
|
+
}
|
|
38
|
+
if (!process.env.WORKFLOW_ENGINE) {
|
|
39
|
+
throw newError(SDKErrors.MsgSDKWorkflowEngineNotSet);
|
|
40
|
+
}
|
|
41
|
+
this.baseUrl = `https://${process.env.ACCOUNT}/endpoint/${process.env.ENVIRONMENT}/${process.env.WORKFLOW_ENGINE}/rest`;
|
|
42
|
+
}
|
|
43
|
+
else {
|
|
44
|
+
let restUrl = config.url.replace(/\/ws$/, '');
|
|
45
|
+
if (!restUrl.endsWith('/rest')) {
|
|
46
|
+
restUrl += '/rest';
|
|
47
|
+
}
|
|
48
|
+
if (restUrl.startsWith('ws://')) {
|
|
49
|
+
restUrl = restUrl.replace('ws://', 'http://');
|
|
50
|
+
}
|
|
51
|
+
else if (config.url.startsWith('wss://')) {
|
|
52
|
+
restUrl = restUrl.replace('wss://', 'https://');
|
|
53
|
+
}
|
|
54
|
+
this.baseUrl = restUrl;
|
|
55
|
+
}
|
|
56
|
+
if (!config?.authToken) {
|
|
57
|
+
if (process.env.KEY_NAME && process.env.KEY_VALUE) {
|
|
58
|
+
this.authToken = `basic ${Buffer.from(`${process.env.KEY_NAME}:${process.env.KEY_VALUE}`).toString('base64')}`;
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
else {
|
|
62
|
+
this.authToken = config?.authToken;
|
|
63
|
+
}
|
|
64
|
+
this.authHeaderName = config?.authHeaderName || 'Authorization';
|
|
65
|
+
this.headers = config?.headers;
|
|
66
|
+
}
|
|
67
|
+
/**
|
|
68
|
+
* Gets the full REST API endpoint URL for workflows
|
|
69
|
+
*/
|
|
70
|
+
getWorkflowsEndpoint() {
|
|
71
|
+
return `${this.baseUrl}/api/v1/workflows`;
|
|
72
|
+
}
|
|
73
|
+
/**
|
|
74
|
+
* Gets the full REST API endpoint URL for a specific workflow
|
|
75
|
+
*/
|
|
76
|
+
getWorkflowEndpoint(workflowNameOrId) {
|
|
77
|
+
return `${this.baseUrl}/api/v1/workflows/${encodeURIComponent(workflowNameOrId)}`;
|
|
78
|
+
}
|
|
79
|
+
/**
|
|
80
|
+
* Gets the full REST API endpoint URL for transactions
|
|
81
|
+
*/
|
|
82
|
+
getTransactionsEndpoint() {
|
|
83
|
+
return `${this.baseUrl}/api/v1/transactions`;
|
|
84
|
+
}
|
|
85
|
+
/**
|
|
86
|
+
* Gets the full REST API endpoint URL for a specific transaction
|
|
87
|
+
*/
|
|
88
|
+
getTransactionEndpoint(idempotencyKeyOrId) {
|
|
89
|
+
return `${this.baseUrl}/api/v1/transactions/${encodeURIComponent(idempotencyKeyOrId)}`;
|
|
90
|
+
}
|
|
91
|
+
/**
|
|
92
|
+
* Gets the full REST API endpoint URL for streams
|
|
93
|
+
*/
|
|
94
|
+
getStreamsEndpoint() {
|
|
95
|
+
return `${this.baseUrl}/api/v1/streams`;
|
|
96
|
+
}
|
|
97
|
+
/**
|
|
98
|
+
* Gets the full REST API endpoint URL for a specific stream
|
|
99
|
+
*/
|
|
100
|
+
getStreamEndpoint(streamNameOrId) {
|
|
101
|
+
return `${this.baseUrl}/api/v1/streams/${encodeURIComponent(streamNameOrId)}`;
|
|
102
|
+
}
|
|
103
|
+
/**
|
|
104
|
+
* Makes an HTTP request with proper error handling
|
|
105
|
+
*/
|
|
106
|
+
async makeRequest(url, method, body, timeout) {
|
|
107
|
+
const headers = {
|
|
108
|
+
'accept': 'application/json',
|
|
109
|
+
'Content-Type': 'application/json',
|
|
110
|
+
...this.headers,
|
|
111
|
+
};
|
|
112
|
+
if (timeout) {
|
|
113
|
+
headers['Request-Timeout'] = `${timeout}m0s`;
|
|
114
|
+
}
|
|
115
|
+
// Add authorization if credentials are available
|
|
116
|
+
if (this.authToken) {
|
|
117
|
+
headers[this.authHeaderName] = this.authToken;
|
|
118
|
+
}
|
|
119
|
+
const response = await fetch(url, {
|
|
120
|
+
method,
|
|
121
|
+
headers,
|
|
122
|
+
body: body ? JSON.stringify(body) : undefined,
|
|
123
|
+
});
|
|
124
|
+
if (!response.ok) {
|
|
125
|
+
const errorText = await response.text();
|
|
126
|
+
throw new Error(`Failed to ${method} ${url}: ${response.status} ${response.statusText}\n${errorText}`);
|
|
127
|
+
}
|
|
128
|
+
// Handle 204 No Content responses
|
|
129
|
+
if (response.status === 204) {
|
|
130
|
+
return undefined;
|
|
131
|
+
}
|
|
132
|
+
return (await response.json());
|
|
133
|
+
}
|
|
134
|
+
// ============================================================================
|
|
135
|
+
// Workflow Methods
|
|
136
|
+
// ============================================================================
|
|
137
|
+
/**
|
|
138
|
+
* Creates a new workflow
|
|
139
|
+
*
|
|
140
|
+
* @param workflow - The workflow definition
|
|
141
|
+
* @param timeout - Optional timeout in seconds (default: 120)
|
|
142
|
+
* @returns Promise resolving to the created workflow
|
|
143
|
+
*/
|
|
144
|
+
async createWorkflow(workflow, timeout) {
|
|
145
|
+
const endpoint = this.getWorkflowsEndpoint();
|
|
146
|
+
return this.makeRequest(endpoint, 'POST', workflow, timeout);
|
|
147
|
+
}
|
|
148
|
+
/**
|
|
149
|
+
* Deletes a workflow by name or ID
|
|
150
|
+
*
|
|
151
|
+
* @param workflowNameOrId - The name or ID of the workflow to delete
|
|
152
|
+
* @param timeout - Optional timeout in seconds (default: 120)
|
|
153
|
+
* @returns Promise that resolves when the workflow is deleted
|
|
154
|
+
*/
|
|
155
|
+
async deleteWorkflow(workflowNameOrId, timeout) {
|
|
156
|
+
const endpoint = this.getWorkflowEndpoint(workflowNameOrId);
|
|
157
|
+
return this.makeRequest(endpoint, 'DELETE', undefined, timeout);
|
|
158
|
+
}
|
|
159
|
+
// ============================================================================
|
|
160
|
+
// Transaction Methods
|
|
161
|
+
// ============================================================================
|
|
162
|
+
/**
|
|
163
|
+
* Creates a new transaction
|
|
164
|
+
*
|
|
165
|
+
* @param transaction - The transaction request
|
|
166
|
+
* @param timeout - Optional timeout in seconds (default: 120)
|
|
167
|
+
* @returns Promise resolving to the transaction response
|
|
168
|
+
*/
|
|
169
|
+
async createTransaction(transaction, timeout) {
|
|
170
|
+
const endpoint = this.getTransactionsEndpoint();
|
|
171
|
+
return this.makeRequest(endpoint, 'POST', transaction, timeout);
|
|
172
|
+
}
|
|
173
|
+
/**
|
|
174
|
+
* Deletes a transaction by idempotency key or ID
|
|
175
|
+
*
|
|
176
|
+
* @param idempotencyKeyOrId - The idempotency key or ID of the transaction to delete
|
|
177
|
+
* @param timeout - Optional timeout in seconds (default: 120)
|
|
178
|
+
* @returns Promise that resolves when the transaction is deleted
|
|
179
|
+
*/
|
|
180
|
+
async deleteTransaction(idempotencyKeyOrId, timeout) {
|
|
181
|
+
const endpoint = this.getTransactionEndpoint(idempotencyKeyOrId);
|
|
182
|
+
return this.makeRequest(endpoint, 'DELETE', undefined, timeout);
|
|
183
|
+
}
|
|
184
|
+
// ============================================================================
|
|
185
|
+
// Stream Methods
|
|
186
|
+
// ============================================================================
|
|
187
|
+
/**
|
|
188
|
+
* Creates a new stream
|
|
189
|
+
*
|
|
190
|
+
* @param stream - The stream definition
|
|
191
|
+
* @param timeout - Optional timeout in seconds (default: 120)
|
|
192
|
+
* @returns Promise resolving to the created stream
|
|
193
|
+
*/
|
|
194
|
+
async createStream(stream, timeout) {
|
|
195
|
+
const endpoint = this.getStreamsEndpoint();
|
|
196
|
+
return this.makeRequest(endpoint, 'POST', stream, timeout);
|
|
197
|
+
}
|
|
198
|
+
/**
|
|
199
|
+
* Deletes a stream by name or ID
|
|
200
|
+
*
|
|
201
|
+
* @param streamNameOrId - The name or ID of the stream to delete
|
|
202
|
+
* @param force - Optional flag to force delete without waiting for handler cleanup
|
|
203
|
+
* @param timeout - Optional timeout in seconds (default: 120)
|
|
204
|
+
* @returns Promise that resolves when the stream is deleted
|
|
205
|
+
*/
|
|
206
|
+
async deleteStream(streamNameOrId, force, timeout) {
|
|
207
|
+
let endpoint = this.getStreamEndpoint(streamNameOrId);
|
|
208
|
+
if (force) {
|
|
209
|
+
endpoint += '?force=true';
|
|
210
|
+
}
|
|
211
|
+
return this.makeRequest(endpoint, 'DELETE', undefined, timeout);
|
|
212
|
+
}
|
|
213
|
+
/**
|
|
214
|
+
* Starts a stream by updating its started status to true
|
|
215
|
+
*
|
|
216
|
+
* @param streamNameOrId - The name or ID of the stream to start
|
|
217
|
+
* @param timeout - Optional timeout in seconds (default: 120)
|
|
218
|
+
* @returns Promise resolving to the updated stream
|
|
219
|
+
*/
|
|
220
|
+
async startStream(streamNameOrId, timeout) {
|
|
221
|
+
const endpoint = this.getStreamEndpoint(streamNameOrId);
|
|
222
|
+
const update = { started: true };
|
|
223
|
+
return this.makeRequest(endpoint, 'PATCH', update, timeout);
|
|
224
|
+
}
|
|
225
|
+
/**
|
|
226
|
+
* Stops a stream by updating its started status to false
|
|
227
|
+
*
|
|
228
|
+
* @param streamNameOrId - The name or ID of the stream to stop
|
|
229
|
+
* @param timeout - Optional timeout in seconds (default: 120)
|
|
230
|
+
* @returns Promise resolving to the updated stream
|
|
231
|
+
*/
|
|
232
|
+
async stopStream(streamNameOrId, timeout) {
|
|
233
|
+
const endpoint = this.getStreamEndpoint(streamNameOrId);
|
|
234
|
+
const update = { started: false };
|
|
235
|
+
return this.makeRequest(endpoint, 'PATCH', update, timeout);
|
|
236
|
+
}
|
|
237
|
+
}
|
|
238
|
+
//# sourceMappingURL=rest-client.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"rest-client.js","sourceRoot":"","sources":["../../../src/client/rest-client.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,i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B,QAAQ,EAAE,MAAM,EAAE,MAAM,EAAE,OAAO,CAAC,CAAC;IACnF,CAAC;IAED;;;;;;;OAOG;IACH,KAAK,CAAC,YAAY,CAChB,cAAsB,EACtB,KAAe,EACf,OAAgB;QAEhB,IAAI,QAAQ,GAAG,IAAI,CAAC,iBAAiB,CAAC,cAAc,CAAC,CAAC;QACtD,IAAI,KAAK,EAAE,CAAC;YACV,QAAQ,IAAI,aAAa,CAAC;QAC5B,CAAC;QACD,OAAO,IAAI,CAAC,WAAW,CAAO,QAAQ,EAAE,QAAQ,EAAE,SAAS,EAAE,OAAO,CAAC,CAAC;IACxE,CAAC;IAED;;;;;;OAMG;IACH,KAAK,CAAC,WAAW,CACf,cAAsB,EACtB,OAAgB;QAEhB,MAAM,QAAQ,GAAG,IAAI,CAAC,iBAAiB,CAAC,cAAc,CAAC,CAAC;QACxD,MAAM,MAAM,GAAwB,EAAE,OAAO,EAAE,IAAI,EAAE,CAAC;QACtD,OAAO,IAAI,CAAC,WAAW,CAAuB,QAAQ,EAAE,OAAO,EAAE,MAAM,EAAE,OAAO,CAAC,CAAC;IACpF,CAAC;IAED;;;;;;OAMG;IACH,KAAK,CAAC,UAAU,CACd,cAAsB,EACtB,OAAgB;QAEhB,MAAM,QAAQ,GAAG,IAAI,CAAC,iBAAiB,CAAC,cAAc,CAAC,CAAC;QACxD,MAAM,MAAM,GAAwB,EAAE,OAAO,EAAE,KAAK,EAAE,CAAC;QACvD,OAAO,IAAI,CAAC,WAAW,CAAuB,QAAQ,EAAE,OAAO,EAAE,MAAM,EAAE,OAAO,CAAC,CAAC;IACpF,CAAC;CACF"}
|
|
@@ -0,0 +1,113 @@
|
|
|
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 { newLogger } from '../log/logger.js';
|
|
17
|
+
import { SDKErrors, newError } from '../i18n/errors.js';
|
|
18
|
+
const log = newLogger('config');
|
|
19
|
+
/**
|
|
20
|
+
* Authentication type enum
|
|
21
|
+
*/
|
|
22
|
+
export var AuthType;
|
|
23
|
+
(function (AuthType) {
|
|
24
|
+
AuthType["BASIC"] = "basic";
|
|
25
|
+
AuthType["TOKEN"] = "token";
|
|
26
|
+
})(AuthType || (AuthType = {}));
|
|
27
|
+
/**
|
|
28
|
+
* Configuration utility for transforming WorkflowEngineConfig into client config
|
|
29
|
+
*
|
|
30
|
+
* The SDK receives configuration objects - it does not load from files.
|
|
31
|
+
* Applications using this SDK should load configuration themselves and pass it in.
|
|
32
|
+
*/
|
|
33
|
+
export class ConfigLoader {
|
|
34
|
+
/**
|
|
35
|
+
* Create WorkflowEngineClientConfig from WorkflowEngineConfig
|
|
36
|
+
*/
|
|
37
|
+
static createClientConfig(config, providerName) {
|
|
38
|
+
const auth = config.workflowEngine.auth;
|
|
39
|
+
let headerName;
|
|
40
|
+
let authValue;
|
|
41
|
+
// Use discriminated union to handle different auth types
|
|
42
|
+
switch (auth.type) {
|
|
43
|
+
case AuthType.BASIC: {
|
|
44
|
+
headerName = 'Authorization';
|
|
45
|
+
const credentials = Buffer.from(`${auth.username}:${auth.password}`).toString('base64');
|
|
46
|
+
authValue = `Basic ${credentials}`;
|
|
47
|
+
break;
|
|
48
|
+
}
|
|
49
|
+
case AuthType.TOKEN: {
|
|
50
|
+
headerName = auth.header || 'Authorization';
|
|
51
|
+
const scheme = auth.scheme || '';
|
|
52
|
+
authValue = scheme ? `${scheme} ${auth.token}` : auth.token;
|
|
53
|
+
break;
|
|
54
|
+
}
|
|
55
|
+
default: {
|
|
56
|
+
// TypeScript ensures this is unreachable if all cases are handled
|
|
57
|
+
const _exhaustive = auth;
|
|
58
|
+
throw newError(SDKErrors.MsgSDKConfigUnknownAuthType, _exhaustive.type);
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
// Convert HTTP(S) URL to WebSocket URL with /ws path
|
|
62
|
+
let wsUrl = config.workflowEngine.url;
|
|
63
|
+
if (wsUrl.startsWith('http://')) {
|
|
64
|
+
wsUrl = 'ws://' + wsUrl.substring(7);
|
|
65
|
+
}
|
|
66
|
+
else if (wsUrl.startsWith('https://')) {
|
|
67
|
+
wsUrl = 'wss://' + wsUrl.substring(8);
|
|
68
|
+
}
|
|
69
|
+
// Add /ws path if not already present
|
|
70
|
+
if (!wsUrl.endsWith('/ws')) {
|
|
71
|
+
wsUrl = wsUrl.replace(/\/$/, '') + '/ws';
|
|
72
|
+
}
|
|
73
|
+
return {
|
|
74
|
+
url: wsUrl,
|
|
75
|
+
providerName,
|
|
76
|
+
options: {
|
|
77
|
+
headers: {
|
|
78
|
+
[headerName]: authValue
|
|
79
|
+
}
|
|
80
|
+
},
|
|
81
|
+
maxAttempts: config.workflowEngine.maxRetries, // undefined = infinite retries
|
|
82
|
+
reconnectDelay: config.workflowEngine.retryDelay ? parseInt(config.workflowEngine.retryDelay.replace('s', '')) * 1000 : 2000
|
|
83
|
+
};
|
|
84
|
+
}
|
|
85
|
+
/**
|
|
86
|
+
* Log configuration summary (without sensitive data)
|
|
87
|
+
*/
|
|
88
|
+
static logConfigSummary(config) {
|
|
89
|
+
log.info('Configuration loaded:');
|
|
90
|
+
log.info(` Workflow Engine: ${config.workflowEngine.url}`);
|
|
91
|
+
const auth = config.workflowEngine.auth;
|
|
92
|
+
switch (auth.type) {
|
|
93
|
+
case AuthType.BASIC:
|
|
94
|
+
log.info(` Auth Type: ${AuthType.BASIC}`);
|
|
95
|
+
log.info(` Username: ${auth.username}`);
|
|
96
|
+
break;
|
|
97
|
+
case AuthType.TOKEN:
|
|
98
|
+
log.info(` Auth Type: ${AuthType.TOKEN}`);
|
|
99
|
+
log.info(` Auth Header: ${auth.header || 'Authorization'}`);
|
|
100
|
+
if (auth.scheme) {
|
|
101
|
+
log.info(` Auth Scheme: ${auth.scheme}`);
|
|
102
|
+
}
|
|
103
|
+
break;
|
|
104
|
+
}
|
|
105
|
+
if (config.workflowEngine.maxRetries) {
|
|
106
|
+
log.info(` Max Retries: ${config.workflowEngine.maxRetries}`);
|
|
107
|
+
}
|
|
108
|
+
if (config.workflowEngine.retryDelay) {
|
|
109
|
+
log.info(` Retry Delay: ${config.workflowEngine.retryDelay}`);
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
//# sourceMappingURL=config.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"config.js","sourceRoot":"","sources":["../../../src/config/config.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;AAIjC,OAAO,EAAE,SAAS,EAAE,MAAM,eAAe,CAAC;AAC1C,OAAO,EAAE,SAAS,EAAE,QAAQ,EAAE,MAAM,gBAAgB,CAAC;AAErD,MAAM,GAAG,GAAG,SAAS,CAAC,QAAQ,CAAC,CAAC;AAEhC;;GAEG;AACH,MAAM,CAAN,IAAY,QAGX;AAHD,WAAY,QAAQ;IAClB,2BAAe,CAAA;IACf,2BAAe,CAAA;AACjB,CAAC,EAHW,QAAQ,KAAR,QAAQ,QAGnB;AAyCD;;;;;GAKG;AACH,MAAM,OAAO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AAE,CAAC,CAAC;gBACzC,MAAM;YACR,KAAK,QAAQ,CAAC,KAAK;gBACjB,GAAG,CAAC,IAAI,CAAC,gBAAgB,QAAQ,CAAC,KAAK,EAAE,CAAC,CAAC;gBAC3C,GAAG,CAAC,IAAI,CAAC,kBAAkB,IAAI,CAAC,MAAM,IAAI,eAAe,EAAE,CAAC,CAAC;gBAC7D,IAAI,IAAI,CAAC,MAAM,EAAE,CAAC;oBAChB,GAAG,CAAC,IAAI,CAAC,kBAAkB,IAAI,CAAC,MAAM,EAAE,CAAC,CAAC;gBAC5C,CAAC;gBACD,MAAM;QACR,CAAC;QAED,IAAI,MAAM,CAAC,cAAc,CAAC,UAAU,EAAE,CAAC;YACrC,GAAG,CAAC,IAAI,CAAC,kBAAkB,MAAM,CAAC,cAAc,CAAC,UAAU,EAAE,CAAC,CAAC;QACjE,CAAC;QAED,IAAI,MAAM,CAAC,cAAc,CAAC,UAAU,EAAE,CAAC;YACrC,GAAG,CAAC,IAAI,CAAC,kBAAkB,MAAM,CAAC,cAAc,CAAC,UAAU,EAAE,CAAC,CAAC;QACjE,CAAC;IACL,CAAC;CACF"}
|
|
@@ -0,0 +1,167 @@
|
|
|
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 { newLogger } from '../log/logger.js';
|
|
17
|
+
import { getErrorMessage } from '../utils/errors.js';
|
|
18
|
+
const log = newLogger('event_source_factory');
|
|
19
|
+
/**
|
|
20
|
+
* Internal event source implementation.
|
|
21
|
+
*/
|
|
22
|
+
class EventSourceBase {
|
|
23
|
+
constructor(name, pollFn) {
|
|
24
|
+
this.confs = new Map();
|
|
25
|
+
this._name = name;
|
|
26
|
+
this.pollFn = pollFn;
|
|
27
|
+
}
|
|
28
|
+
name() {
|
|
29
|
+
return this._name;
|
|
30
|
+
}
|
|
31
|
+
withDeleteFn(deleteFn) {
|
|
32
|
+
this.deleteFn = deleteFn;
|
|
33
|
+
return this;
|
|
34
|
+
}
|
|
35
|
+
withConfigParser(parserFn) {
|
|
36
|
+
this.configParserFn = parserFn;
|
|
37
|
+
return this;
|
|
38
|
+
}
|
|
39
|
+
withInitialCheckpoint(buildFn) {
|
|
40
|
+
this.buildInitialCheckpointFn = buildFn;
|
|
41
|
+
return this;
|
|
42
|
+
}
|
|
43
|
+
withInitFn(initFn) {
|
|
44
|
+
this.initFn = initFn;
|
|
45
|
+
return this;
|
|
46
|
+
}
|
|
47
|
+
withCloseFn(closeFn) {
|
|
48
|
+
this.closeFn = closeFn;
|
|
49
|
+
return this;
|
|
50
|
+
}
|
|
51
|
+
async init(engAPI) {
|
|
52
|
+
if (this.initFn) {
|
|
53
|
+
await this.initFn(engAPI);
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
close() {
|
|
57
|
+
if (this.closeFn) {
|
|
58
|
+
this.closeFn();
|
|
59
|
+
}
|
|
60
|
+
this.confs.clear();
|
|
61
|
+
}
|
|
62
|
+
/**
|
|
63
|
+
* Build and parse config for a stream.
|
|
64
|
+
*/
|
|
65
|
+
async buildConf(info, configData) {
|
|
66
|
+
if (this.configParserFn) {
|
|
67
|
+
return await this.configParserFn(info, configData);
|
|
68
|
+
}
|
|
69
|
+
else {
|
|
70
|
+
// Simple JSON parsing (default)
|
|
71
|
+
return configData;
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
/**
|
|
75
|
+
* Build and cache config for a stream.
|
|
76
|
+
*/
|
|
77
|
+
async buildAndCacheConf(config, request) {
|
|
78
|
+
const info = {
|
|
79
|
+
streamId: request.streamId,
|
|
80
|
+
streamName: request.streamName,
|
|
81
|
+
};
|
|
82
|
+
const parsedConfig = await this.buildConf(info, config.config);
|
|
83
|
+
const esConf = {
|
|
84
|
+
...info,
|
|
85
|
+
config: parsedConfig,
|
|
86
|
+
};
|
|
87
|
+
this.confs.set(request.streamId, esConf);
|
|
88
|
+
return esConf;
|
|
89
|
+
}
|
|
90
|
+
/**
|
|
91
|
+
* Validate config and optionally set initial checkpoint.
|
|
92
|
+
*/
|
|
93
|
+
async eventSourceValidateConfig(result, request) {
|
|
94
|
+
try {
|
|
95
|
+
const parsedConfig = await this.buildConf({
|
|
96
|
+
streamId: request.streamId,
|
|
97
|
+
streamName: request.streamName,
|
|
98
|
+
}, request.config);
|
|
99
|
+
if (this.buildInitialCheckpointFn) {
|
|
100
|
+
const initialCheckpoint = await this.buildInitialCheckpointFn(parsedConfig);
|
|
101
|
+
result.initialCheckpoint = initialCheckpoint;
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
catch (error) {
|
|
105
|
+
log.error('Failed to validate config', { error });
|
|
106
|
+
result.error = getErrorMessage(error);
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
/**
|
|
110
|
+
* Poll for events.
|
|
111
|
+
* Mutates the `result` parameter to match the engine's output-by-reference API.
|
|
112
|
+
*/
|
|
113
|
+
async eventSourcePoll(config, result, request) {
|
|
114
|
+
try {
|
|
115
|
+
// Get or build cached config
|
|
116
|
+
let esConf = this.confs.get(request.streamId);
|
|
117
|
+
if (!esConf) {
|
|
118
|
+
esConf = await this.buildAndCacheConf(config, request);
|
|
119
|
+
}
|
|
120
|
+
// Get checkpoint from request, normalize undefined to null for poll function
|
|
121
|
+
const checkpointIn = request.checkpoint ?? null;
|
|
122
|
+
// Call user's poll function
|
|
123
|
+
const pollResult = await this.pollFn(esConf, checkpointIn);
|
|
124
|
+
// Map events to ListenerEvent format
|
|
125
|
+
result.events = pollResult.events.map((evt) => ({
|
|
126
|
+
idempotencyKey: evt.idempotencyKey,
|
|
127
|
+
topic: evt.topic,
|
|
128
|
+
data: evt.data,
|
|
129
|
+
}));
|
|
130
|
+
// Set checkpoint
|
|
131
|
+
result.checkpoint = pollResult.checkpointOut;
|
|
132
|
+
}
|
|
133
|
+
catch (error) {
|
|
134
|
+
log.error('Poll failed', { error });
|
|
135
|
+
result.error = getErrorMessage(error);
|
|
136
|
+
}
|
|
137
|
+
}
|
|
138
|
+
/**
|
|
139
|
+
* Delete event source and clear cached config.
|
|
140
|
+
*/
|
|
141
|
+
async eventSourceDelete(result, request) {
|
|
142
|
+
try {
|
|
143
|
+
if (this.deleteFn) {
|
|
144
|
+
await this.deleteFn({
|
|
145
|
+
streamId: request.streamId,
|
|
146
|
+
streamName: request.streamName,
|
|
147
|
+
});
|
|
148
|
+
}
|
|
149
|
+
this.confs.delete(request.streamId);
|
|
150
|
+
}
|
|
151
|
+
catch (error) {
|
|
152
|
+
log.error('Delete failed', { error });
|
|
153
|
+
result.error = getErrorMessage(error);
|
|
154
|
+
}
|
|
155
|
+
}
|
|
156
|
+
}
|
|
157
|
+
/**
|
|
158
|
+
* Create a new event source with a poll function.
|
|
159
|
+
*
|
|
160
|
+
* @param name - Handler name to register with the workflow engine
|
|
161
|
+
* @param pollFn - Function that polls for new events
|
|
162
|
+
* @returns EventSourceFactory for chaining configuration
|
|
163
|
+
*/
|
|
164
|
+
export function newEventSource(name, pollFn) {
|
|
165
|
+
return new EventSourceBase(name, pollFn);
|
|
166
|
+
}
|
|
167
|
+
//# sourceMappingURL=event_source.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"event_source.js","sourceRoot":"","sources":["../../../src/factories/event_source.ts"],"names":[],"mappings":"AAAA,iCAAiC;AACjC,EAAE;AACF,sCAAsC;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AAC,aAAa,EAAE,EAAE,KAAK,EAAE,CAAC,CAAC;YACpC,MAAM,CAAC,KAAK,GAAG,eAAe,CAAC,KAAK,CAAC,CAAC;QACxC,CAAC;IACH,CAAC;IAED;;OAEG;IACH,KAAK,CAAC,iBAAiB,CAAC,MAAyB,EAAE,OAAY;QAC7D,IAAI,CAAC;YACH,IAAI,IAAI,CAAC,QAAQ,EAAE,CAAC;gBAClB,MAAM,IAAI,CAAC,QAAQ,CAAC;oBAClB,QAAQ,EAAE,OAAO,CAAC,QAAQ;oBAC1B,UAAU,EAAE,OAAO,CAAC,UAAU;iBAC/B,CAAC,CAAC;YACL,CAAC;YAED,IAAI,CAAC,KAAK,CAAC,MAAM,CAAC,OAAO,CAAC,QAAQ,CAAC,CAAC;QACtC,CAAC;QAAC,OAAO,KAAK,EAAE,CAAC;YACf,GAAG,CAAC,KAAK,CAAC,eAAe,EAAE,EAAE,KAAK,EAAE,CAAC,CAAC;YACtC,MAAM,CAAC,KAAK,GAAG,eAAe,CAAC,KAAK,CAAC,CAAC;QACxC,CAAC;IACH,CAAC;CACF;AAED;;;;;;GAMG;AACH,MAAM,UAAU,cAAc,CAC5B,IAAY,EACZ,MAAqC;IAErC,OAAO,IAAI,eAAe,CAAa,IAAI,EAAE,MAAM,CAAC,CAAC;AACvD,CAAC"}
|
|
@@ -0,0 +1,63 @@
|
|
|
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 { evalDirected } from '../helpers/stage_director.js';
|
|
17
|
+
/**
|
|
18
|
+
* Internal base implementation for directed transaction handlers.
|
|
19
|
+
*/
|
|
20
|
+
class TransactionHandlerBase {
|
|
21
|
+
constructor(name, actionMap) {
|
|
22
|
+
this._name = name;
|
|
23
|
+
this.actionMap = actionMap;
|
|
24
|
+
}
|
|
25
|
+
name() {
|
|
26
|
+
return this._name;
|
|
27
|
+
}
|
|
28
|
+
withInitFn(initFn) {
|
|
29
|
+
this.initFn = initFn;
|
|
30
|
+
return this;
|
|
31
|
+
}
|
|
32
|
+
withCloseFn(closeFn) {
|
|
33
|
+
this.closeFn = closeFn;
|
|
34
|
+
return this;
|
|
35
|
+
}
|
|
36
|
+
async init(engAPI) {
|
|
37
|
+
if (this.initFn) {
|
|
38
|
+
await this.initFn(engAPI);
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
close() {
|
|
42
|
+
if (this.closeFn) {
|
|
43
|
+
this.closeFn();
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
async transactionHandlerBatch(reply, batch) {
|
|
47
|
+
await evalDirected(reply, batch, this.actionMap);
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
/**
|
|
51
|
+
* Create a new simple directed handler, with no initialization.
|
|
52
|
+
*
|
|
53
|
+
* A directed handler uses the StageDirector pattern to route transactions
|
|
54
|
+
* to different actions based on the input's `action` field.
|
|
55
|
+
*
|
|
56
|
+
* @param name Handler name
|
|
57
|
+
* @param actionMap Map of action names to their configurations
|
|
58
|
+
* @returns A TransactionHandlerFactory for chaining
|
|
59
|
+
*/
|
|
60
|
+
export function newDirectedTransactionHandler(name, actionMap) {
|
|
61
|
+
return new TransactionHandlerBase(name, actionMap);
|
|
62
|
+
}
|
|
63
|
+
//# sourceMappingURL=transaction_handler.js.map
|