@versori/run 0.4.5 → 0.5.0-alpha.1
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/esm/src/connection/DirectConnectionFactory.d.ts +3 -5
- package/esm/src/connection/DirectConnectionFactory.d.ts.map +1 -1
- package/esm/src/connection/DirectConnectionFactory.js +0 -5
- package/esm/src/connection/internal/CredentialHolder.d.ts.map +1 -1
- package/esm/src/connection/internal/CredentialHolder.js +1 -1
- package/esm/src/connection/internal/FetchBuilder.d.ts +9 -2
- package/esm/src/connection/internal/FetchBuilder.d.ts.map +1 -1
- package/esm/src/connection/internal/FetchBuilder.js +120 -4
- package/esm/src/connection/internal/OutboundConnectionFactory.d.ts.map +1 -1
- package/esm/src/connection/internal/OutboundConnectionFactory.js +2 -2
- package/esm/src/context/Context.d.ts +1 -0
- package/esm/src/context/Context.d.ts.map +1 -1
- package/esm/src/context/Context.js +3 -0
- package/esm/src/context/ContextProvider.d.ts +1 -1
- package/esm/src/context/ContextProvider.d.ts.map +1 -1
- package/esm/src/context/ContextProvider.js +1 -1
- package/esm/src/dsl/Workflow.d.ts.map +1 -1
- package/esm/src/dsl/Workflow.js +2 -0
- package/esm/src/dsl/http/types.d.ts +2 -0
- package/esm/src/dsl/http/types.d.ts.map +1 -1
- package/esm/src/dsl/http/versori/configloader.js +1 -1
- package/esm/src/dsl/http/versori/cronapi.d.ts +2 -3
- package/esm/src/dsl/http/versori/cronapi.d.ts.map +1 -1
- package/esm/src/dsl/http/versori/cronapi.js +14 -15
- package/esm/src/dsl/http/versori/kvapi/core/OpenAPI.js +1 -1
- package/esm/src/dsl/http/versori/webhookmiddleware.d.ts.map +1 -1
- package/esm/src/dsl/http/versori/webhookmiddleware.js +69 -38
- package/esm/src/dsl/triggers/WebhookTrigger.d.ts.map +1 -1
- package/esm/src/dsl/triggers/WebhookTrigger.js +3 -1
- package/esm/src/internal/InternalAuth.d.ts +0 -1
- package/esm/src/internal/InternalAuth.d.ts.map +1 -1
- package/esm/src/internal/InternalAuth.js +1 -14
- package/esm/src/internal/constants.d.ts +3 -1
- package/esm/src/internal/constants.d.ts.map +1 -1
- package/esm/src/internal/constants.js +4 -1
- package/esm/src/internal/supervisor.d.ts +25 -0
- package/esm/src/internal/supervisor.d.ts.map +1 -0
- package/esm/src/internal/supervisor.js +156 -0
- package/esm/src/interpreter/durable/DurableInterpreter.d.ts +8 -2
- package/esm/src/interpreter/durable/DurableInterpreter.d.ts.map +1 -1
- package/esm/src/interpreter/durable/DurableInterpreter.js +80 -15
- package/esm/src/interpreter/durable/ObservableCompiler.d.ts +6 -1
- package/esm/src/interpreter/durable/ObservableCompiler.d.ts.map +1 -1
- package/esm/src/interpreter/durable/Queue.js +1 -1
- package/esm/src/interpreter/durable/compilers/catch.d.ts.map +1 -1
- package/esm/src/interpreter/durable/compilers/catch.js +1 -0
- package/esm/src/interpreter/durable/compilers/fn.d.ts.map +1 -1
- package/esm/src/interpreter/durable/compilers/fn.js +19 -4
- package/esm/src/interpreter/durable/compilers/http.d.ts.map +1 -1
- package/esm/src/interpreter/durable/compilers/http.js +40 -7
- package/esm/src/interpreter/durable/compilers/schedule.d.ts.map +1 -1
- package/esm/src/interpreter/durable/compilers/schedule.js +2 -1
- package/esm/src/interpreter/durable/compilers/webhook.d.ts.map +1 -1
- package/esm/src/interpreter/durable/compilers/webhook.js +14 -4
- package/esm/src/interpreter/memory/MemoryInterpreter.d.ts +7 -1
- package/esm/src/interpreter/memory/MemoryInterpreter.d.ts.map +1 -1
- package/esm/src/interpreter/memory/MemoryInterpreter.js +79 -14
- package/esm/src/interpreter/memory/ObservableCompiler.d.ts +6 -1
- package/esm/src/interpreter/memory/ObservableCompiler.d.ts.map +1 -1
- package/esm/src/interpreter/memory/compilers/catch.d.ts.map +1 -1
- package/esm/src/interpreter/memory/compilers/catch.js +1 -0
- package/esm/src/interpreter/memory/compilers/fn.d.ts.map +1 -1
- package/esm/src/interpreter/memory/compilers/fn.js +19 -16
- package/esm/src/interpreter/memory/compilers/http.d.ts.map +1 -1
- package/esm/src/interpreter/memory/compilers/http.js +39 -6
- package/esm/src/interpreter/memory/compilers/schedule.d.ts.map +1 -1
- package/esm/src/interpreter/memory/compilers/schedule.js +2 -1
- package/esm/src/interpreter/memory/compilers/webhook.d.ts.map +1 -1
- package/esm/src/interpreter/memory/compilers/webhook.js +15 -4
- package/esm/src/issues/Issues.js +1 -1
- package/esm/src/kv/nats/NatsKeyValueProvider.d.ts.map +1 -1
- package/esm/src/kv/nats/NatsKeyValueProvider.js +2 -2
- package/esm/src/kv/sdk/SDKKeyValueProvider.d.ts.map +1 -1
- package/esm/src/kv/sdk/SDKKeyValueProvider.js +3 -3
- package/esm/src/observability/logging/ConsoleLogger.d.ts.map +1 -1
- package/package.json +3 -1
- package/script/src/connection/DirectConnectionFactory.d.ts +3 -5
- package/script/src/connection/DirectConnectionFactory.d.ts.map +1 -1
- package/script/src/connection/DirectConnectionFactory.js +0 -5
- package/script/src/connection/internal/CredentialHolder.d.ts.map +1 -1
- package/script/src/connection/internal/CredentialHolder.js +1 -1
- package/script/src/connection/internal/FetchBuilder.d.ts +9 -2
- package/script/src/connection/internal/FetchBuilder.d.ts.map +1 -1
- package/script/src/connection/internal/FetchBuilder.js +143 -4
- package/script/src/connection/internal/OutboundConnectionFactory.d.ts.map +1 -1
- package/script/src/connection/internal/OutboundConnectionFactory.js +2 -2
- package/script/src/context/Context.d.ts +1 -0
- package/script/src/context/Context.d.ts.map +1 -1
- package/script/src/context/Context.js +3 -0
- package/script/src/context/ContextProvider.d.ts +1 -1
- package/script/src/context/ContextProvider.d.ts.map +1 -1
- package/script/src/context/ContextProvider.js +1 -1
- package/script/src/dsl/Workflow.d.ts.map +1 -1
- package/script/src/dsl/Workflow.js +2 -0
- package/script/src/dsl/http/types.d.ts +2 -0
- package/script/src/dsl/http/types.d.ts.map +1 -1
- package/script/src/dsl/http/versori/configloader.js +1 -1
- package/script/src/dsl/http/versori/cronapi.d.ts +2 -3
- package/script/src/dsl/http/versori/cronapi.d.ts.map +1 -1
- package/script/src/dsl/http/versori/cronapi.js +14 -15
- package/script/src/dsl/http/versori/kvapi/core/OpenAPI.js +1 -1
- package/script/src/dsl/http/versori/webhookmiddleware.d.ts.map +1 -1
- package/script/src/dsl/http/versori/webhookmiddleware.js +69 -38
- package/script/src/dsl/triggers/WebhookTrigger.d.ts.map +1 -1
- package/script/src/dsl/triggers/WebhookTrigger.js +3 -1
- package/script/src/internal/InternalAuth.d.ts +0 -1
- package/script/src/internal/InternalAuth.d.ts.map +1 -1
- package/script/src/internal/InternalAuth.js +0 -13
- package/script/src/internal/constants.d.ts +3 -1
- package/script/src/internal/constants.d.ts.map +1 -1
- package/script/src/internal/constants.js +5 -2
- package/script/src/internal/supervisor.d.ts +25 -0
- package/script/src/internal/supervisor.d.ts.map +1 -0
- package/script/src/internal/supervisor.js +163 -0
- package/script/src/interpreter/durable/DurableInterpreter.d.ts +8 -2
- package/script/src/interpreter/durable/DurableInterpreter.d.ts.map +1 -1
- package/script/src/interpreter/durable/DurableInterpreter.js +85 -20
- package/script/src/interpreter/durable/ObservableCompiler.d.ts +6 -1
- package/script/src/interpreter/durable/ObservableCompiler.d.ts.map +1 -1
- package/script/src/interpreter/durable/Queue.js +1 -1
- package/script/src/interpreter/durable/compilers/catch.d.ts.map +1 -1
- package/script/src/interpreter/durable/compilers/catch.js +1 -0
- package/script/src/interpreter/durable/compilers/fn.d.ts.map +1 -1
- package/script/src/interpreter/durable/compilers/fn.js +19 -4
- package/script/src/interpreter/durable/compilers/http.d.ts.map +1 -1
- package/script/src/interpreter/durable/compilers/http.js +40 -7
- package/script/src/interpreter/durable/compilers/schedule.d.ts.map +1 -1
- package/script/src/interpreter/durable/compilers/schedule.js +2 -1
- package/script/src/interpreter/durable/compilers/webhook.d.ts.map +1 -1
- package/script/src/interpreter/durable/compilers/webhook.js +14 -4
- package/script/src/interpreter/memory/MemoryInterpreter.d.ts +7 -1
- package/script/src/interpreter/memory/MemoryInterpreter.d.ts.map +1 -1
- package/script/src/interpreter/memory/MemoryInterpreter.js +78 -13
- package/script/src/interpreter/memory/ObservableCompiler.d.ts +6 -1
- package/script/src/interpreter/memory/ObservableCompiler.d.ts.map +1 -1
- package/script/src/interpreter/memory/compilers/catch.d.ts.map +1 -1
- package/script/src/interpreter/memory/compilers/catch.js +1 -0
- package/script/src/interpreter/memory/compilers/fn.d.ts.map +1 -1
- package/script/src/interpreter/memory/compilers/fn.js +19 -16
- package/script/src/interpreter/memory/compilers/http.d.ts.map +1 -1
- package/script/src/interpreter/memory/compilers/http.js +39 -6
- package/script/src/interpreter/memory/compilers/schedule.d.ts.map +1 -1
- package/script/src/interpreter/memory/compilers/schedule.js +2 -1
- package/script/src/interpreter/memory/compilers/webhook.d.ts.map +1 -1
- package/script/src/interpreter/memory/compilers/webhook.js +15 -4
- package/script/src/issues/Issues.js +1 -1
- package/script/src/kv/nats/NatsKeyValueProvider.d.ts.map +1 -1
- package/script/src/kv/nats/NatsKeyValueProvider.js +2 -2
- package/script/src/kv/sdk/SDKKeyValueProvider.d.ts.map +1 -1
- package/script/src/kv/sdk/SDKKeyValueProvider.js +3 -3
- package/script/src/observability/logging/ConsoleLogger.d.ts.map +1 -1
- package/esm/deps/jsr.io/@std/encoding/1.0.10/_common64.d.ts +0 -35
- package/esm/deps/jsr.io/@std/encoding/1.0.10/_common64.d.ts.map +0 -1
- package/esm/deps/jsr.io/@std/encoding/1.0.10/_common64.js +0 -113
- package/esm/deps/jsr.io/@std/encoding/1.0.10/_common_detach.d.ts +0 -4
- package/esm/deps/jsr.io/@std/encoding/1.0.10/_common_detach.d.ts.map +0 -1
- package/esm/deps/jsr.io/@std/encoding/1.0.10/_common_detach.js +0 -13
- package/esm/deps/jsr.io/@std/encoding/1.0.10/_types.d.ts +0 -9
- package/esm/deps/jsr.io/@std/encoding/1.0.10/_types.d.ts.map +0 -1
- package/esm/deps/jsr.io/@std/encoding/1.0.10/_types.js +0 -2
- package/esm/deps/jsr.io/@std/encoding/1.0.10/base64.d.ts +0 -40
- package/esm/deps/jsr.io/@std/encoding/1.0.10/base64.d.ts.map +0 -1
- package/esm/deps/jsr.io/@std/encoding/1.0.10/base64.js +0 -82
- package/esm/src/connection/CredentialsProvider.d.ts +0 -17
- package/esm/src/connection/CredentialsProvider.d.ts.map +0 -1
- package/esm/src/connection/CredentialsProvider.js +0 -63
- package/esm/src/credentials/CredentialsProvider.d.ts +0 -49
- package/esm/src/credentials/CredentialsProvider.d.ts.map +0 -1
- package/esm/src/credentials/CredentialsProvider.js +0 -102
- package/esm/src/dsl/http/versori/constants.d.ts +0 -20
- package/esm/src/dsl/http/versori/constants.d.ts.map +0 -1
- package/esm/src/dsl/http/versori/constants.js +0 -37
- package/esm/src/internal/cli.d.ts +0 -2
- package/esm/src/internal/cli.d.ts.map +0 -1
- package/esm/src/internal/cli.js +0 -32
- package/script/deps/jsr.io/@std/encoding/1.0.10/_common64.d.ts +0 -35
- package/script/deps/jsr.io/@std/encoding/1.0.10/_common64.d.ts.map +0 -1
- package/script/deps/jsr.io/@std/encoding/1.0.10/_common64.js +0 -119
- package/script/deps/jsr.io/@std/encoding/1.0.10/_common_detach.d.ts +0 -4
- package/script/deps/jsr.io/@std/encoding/1.0.10/_common_detach.d.ts.map +0 -1
- package/script/deps/jsr.io/@std/encoding/1.0.10/_common_detach.js +0 -16
- package/script/deps/jsr.io/@std/encoding/1.0.10/_types.d.ts +0 -9
- package/script/deps/jsr.io/@std/encoding/1.0.10/_types.d.ts.map +0 -1
- package/script/deps/jsr.io/@std/encoding/1.0.10/_types.js +0 -3
- package/script/deps/jsr.io/@std/encoding/1.0.10/base64.d.ts +0 -40
- package/script/deps/jsr.io/@std/encoding/1.0.10/base64.d.ts.map +0 -1
- package/script/deps/jsr.io/@std/encoding/1.0.10/base64.js +0 -86
- package/script/src/connection/CredentialsProvider.d.ts +0 -17
- package/script/src/connection/CredentialsProvider.d.ts.map +0 -1
- package/script/src/connection/CredentialsProvider.js +0 -67
- package/script/src/credentials/CredentialsProvider.d.ts +0 -49
- package/script/src/credentials/CredentialsProvider.d.ts.map +0 -1
- package/script/src/credentials/CredentialsProvider.js +0 -106
- package/script/src/dsl/http/versori/constants.d.ts +0 -20
- package/script/src/dsl/http/versori/constants.d.ts.map +0 -1
- package/script/src/dsl/http/versori/constants.js +0 -40
- package/script/src/internal/cli.d.ts +0 -2
- package/script/src/internal/cli.d.ts.map +0 -1
- package/script/src/internal/cli.js +0 -35
|
@@ -10,6 +10,8 @@
|
|
|
10
10
|
* As of the Change Date, in accordance with the Business Source License,
|
|
11
11
|
* use of this software will be governed by the Apache License, Version 2.0.
|
|
12
12
|
*/
|
|
13
|
+
import { create } from '@bufbuild/protobuf';
|
|
14
|
+
import { timestampMs } from '@bufbuild/protobuf/wkt';
|
|
13
15
|
import opentelemetry from '@opentelemetry/api';
|
|
14
16
|
import { OTLPTraceExporter } from '@opentelemetry/exporter-trace-otlp-proto';
|
|
15
17
|
import { resourceFromAttributes } from '@opentelemetry/resources';
|
|
@@ -19,22 +21,54 @@ import { catchError, EMPTY, mergeMap, of, tap } from 'rxjs';
|
|
|
19
21
|
import { DirectConnectionFactory } from '../../connection/DirectConnectionFactory.js';
|
|
20
22
|
import { ContextProviderImpl } from '../../context/ContextProvider.js';
|
|
21
23
|
import { VersoriConfigReader } from '../../dsl/http/versori/configloader.js';
|
|
22
|
-
import { envVarEnvId, envVarEnvironmentName, envVarLocalRun, envVarOrgId, envVarOrgSlug, envVarOtelTracesURL, envVarProjectId, envVarSDKApiBaseURL, envVarVersion, } from '../../dsl/http/versori/constants.js';
|
|
23
24
|
import { CronAPIClient } from '../../dsl/http/versori/cronapi.js';
|
|
24
25
|
import { WorkflowImpl } from '../../dsl/Workflow.js';
|
|
26
|
+
import { envCronPort, envPort, envReadyCheckURL, envVarEnvId, envVarEnvironmentName, envVarOrgId, envVarOrgSlug, envVarOtelTracesURL, envVarProjectId, envVarSDKApiBaseURL, envVarVersion, } from '../../internal/constants.js';
|
|
27
|
+
import { Fake, registerCrons, registerWebhooks, enabled as supervisorEnabled } from '../../internal/supervisor.js';
|
|
25
28
|
import { IssueImpl } from '../../issues/Issues.js';
|
|
26
29
|
import { MemoryKeyValueProvider } from '../../kv/memory/MemoryKeyValueProvider.js';
|
|
27
30
|
import { SDKKeyValueProvider } from '../../kv/sdk/SDKKeyValueProvider.js';
|
|
28
31
|
import { ConsoleLogger } from '../../observability/logging/ConsoleLogger.js';
|
|
32
|
+
import { credentialv1alpha1 } from '../../services/credentials/mod.js';
|
|
29
33
|
import { PlatformApiImpl } from '../../services/platform/PlatformApi.js';
|
|
30
34
|
import { ObservableCompiler } from './ObservableCompiler.js';
|
|
31
35
|
import { QueueImpl } from './Queue.js';
|
|
32
|
-
function getKVProvider(
|
|
33
|
-
if (
|
|
36
|
+
function getKVProvider() {
|
|
37
|
+
if (supervisorEnabled) {
|
|
34
38
|
return Promise.resolve(new MemoryKeyValueProvider());
|
|
35
39
|
}
|
|
36
40
|
return SDKKeyValueProvider.fromEnv();
|
|
37
41
|
}
|
|
42
|
+
function getCredentialsProvider(d) {
|
|
43
|
+
return {
|
|
44
|
+
async getRaw(name, _activationId) {
|
|
45
|
+
const response = await d['credentials'].get({ id: name, organisationId: '' });
|
|
46
|
+
if (!response.credential) {
|
|
47
|
+
throw new Error(`Failed to get credential: ${name}`);
|
|
48
|
+
}
|
|
49
|
+
const rawData = create(credentialv1alpha1.CredentialDataRawSchema, response.credential.data);
|
|
50
|
+
return rawData.raw;
|
|
51
|
+
},
|
|
52
|
+
async getAccessToken(name, forceRefresh, _activationId) {
|
|
53
|
+
const response = await d['tokens'].getToken({ credentialId: name, forceRefresh: forceRefresh || false });
|
|
54
|
+
if (!response.token) {
|
|
55
|
+
throw new Error(`Failed to get token for credential: ${name}`);
|
|
56
|
+
}
|
|
57
|
+
return {
|
|
58
|
+
accessToken: response.token.accessToken,
|
|
59
|
+
tokenType: response.token.tokenType,
|
|
60
|
+
expiry: response.token.expiry ? new Date(timestampMs(response.token.expiry)) : undefined,
|
|
61
|
+
};
|
|
62
|
+
},
|
|
63
|
+
async getOAuth1Metadata(name, _activationId) {
|
|
64
|
+
const response = await d['oauth1'].getAuthorizationMetadata({ credentialId: name });
|
|
65
|
+
if (!response) {
|
|
66
|
+
throw new Error(`Failed to get OAuth1 metadata for credential: ${name}`);
|
|
67
|
+
}
|
|
68
|
+
return response;
|
|
69
|
+
},
|
|
70
|
+
};
|
|
71
|
+
}
|
|
38
72
|
/**
|
|
39
73
|
* DurableInterpreter is an interpreter for executing Versori workflows with support for durable, queue-based workflow
|
|
40
74
|
* execution. It supports all trigger types including the {@link workflow} trigger which allows workflows to be started
|
|
@@ -60,7 +94,7 @@ function getKVProvider(runLocal) {
|
|
|
60
94
|
* ```
|
|
61
95
|
*/
|
|
62
96
|
export class DurableInterpreter {
|
|
63
|
-
constructor(log, compiler, contextProvider, webhookRouter, cronRouter, cronRegistry, platformApi, cnxFetchFactory, cronProvider, tracer, issue, cfgReader, queueProvider, otelSDK) {
|
|
97
|
+
constructor(log, compiler, contextProvider, webhookRouter, cronRouter, cronRegistry, webhookRegistry, platformApi, cnxFetchFactory, cronProvider, tracer, issue, cfgReader, queueProvider, otelSDK) {
|
|
64
98
|
Object.defineProperty(this, "log", {
|
|
65
99
|
enumerable: true,
|
|
66
100
|
configurable: true,
|
|
@@ -97,6 +131,12 @@ export class DurableInterpreter {
|
|
|
97
131
|
writable: true,
|
|
98
132
|
value: cronRegistry
|
|
99
133
|
});
|
|
134
|
+
Object.defineProperty(this, "webhookRegistry", {
|
|
135
|
+
enumerable: true,
|
|
136
|
+
configurable: true,
|
|
137
|
+
writable: true,
|
|
138
|
+
value: webhookRegistry
|
|
139
|
+
});
|
|
100
140
|
Object.defineProperty(this, "platformApi", {
|
|
101
141
|
enumerable: true,
|
|
102
142
|
configurable: true,
|
|
@@ -195,7 +235,6 @@ export class DurableInterpreter {
|
|
|
195
235
|
const otelTracesURL = Deno.env.get(envVarOtelTracesURL);
|
|
196
236
|
let otelSDK;
|
|
197
237
|
const configReader = VersoriConfigReader.fromEnv(log);
|
|
198
|
-
const runLocal = Deno.env.get(envVarLocalRun) === 'true';
|
|
199
238
|
await waitForReady(log);
|
|
200
239
|
// Do NOT change those attributes, they are used by the API to filter on
|
|
201
240
|
const resource = resourceFromAttributes({
|
|
@@ -217,21 +256,31 @@ export class DurableInterpreter {
|
|
|
217
256
|
log.info('Starting OpenTelemetry SDK');
|
|
218
257
|
otelSDK.start();
|
|
219
258
|
}
|
|
259
|
+
else if (supervisorEnabled) {
|
|
260
|
+
otelSDK = new NodeSDK({
|
|
261
|
+
traceExporter: new Fake(),
|
|
262
|
+
serviceName: serviceName,
|
|
263
|
+
resource: resource,
|
|
264
|
+
});
|
|
265
|
+
log.info('Starting Testing OpenTelemetry SDK');
|
|
266
|
+
otelSDK.start();
|
|
267
|
+
}
|
|
220
268
|
const tracer = opentelemetry.trace.getTracer(serviceName, version);
|
|
269
|
+
const cnxFactory = DirectConnectionFactory.fromEnv(log);
|
|
270
|
+
const credentialsProvider = getCredentialsProvider(cnxFactory);
|
|
221
271
|
const queueProvider = await QueueImpl.fromEnv(log);
|
|
222
|
-
const connectionFactory = DirectConnectionFactory.fromEnv(log);
|
|
223
272
|
const issuesProvider = new IssueImpl(log);
|
|
224
273
|
if (options.contextProvider) {
|
|
225
274
|
// no need to set up a key-value provider if options.contextProvider is already
|
|
226
275
|
// initialised.
|
|
227
|
-
return new DurableInterpreter(log, compiler, options.contextProvider, express.Router(), express.Router(), new Map(), PlatformApiImpl.fromEnv(),
|
|
276
|
+
return new DurableInterpreter(log, compiler, options.contextProvider, express.Router(), express.Router(), new Map(), new Map(), PlatformApiImpl.fromEnv(), cnxFactory, CronAPIClient.fromEnv(), tracer, issuesProvider, configReader, queueProvider, otelSDK);
|
|
228
277
|
}
|
|
229
|
-
const kvp = await getKVProvider(
|
|
278
|
+
const kvp = await getKVProvider();
|
|
230
279
|
const platformApi = PlatformApiImpl.fromEnv();
|
|
231
280
|
const organisationId = Deno.env.get(envVarOrgId) || 'development';
|
|
232
281
|
const environmentId = Deno.env.get(envVarEnvId) || 'development';
|
|
233
|
-
const ctxProvider = new ContextProviderImpl(log, kvp,
|
|
234
|
-
return new DurableInterpreter(log, compiler, ctxProvider, express.Router(), express.Router(), new Map(), PlatformApiImpl.fromEnv(),
|
|
282
|
+
const ctxProvider = new ContextProviderImpl(log, kvp, credentialsProvider, platformApi, organisationId, environmentId, issuesProvider);
|
|
283
|
+
return new DurableInterpreter(log, compiler, ctxProvider, express.Router(), express.Router(), new Map(), new Map(), PlatformApiImpl.fromEnv(), cnxFactory, CronAPIClient.fromEnv(), tracer, issuesProvider, configReader, queueProvider, otelSDK);
|
|
235
284
|
}
|
|
236
285
|
register(workflow, options) {
|
|
237
286
|
const localAbortController = new AbortController();
|
|
@@ -248,6 +297,7 @@ export class DurableInterpreter {
|
|
|
248
297
|
tracer: this.tracer,
|
|
249
298
|
contextProvider: this.contextProvider,
|
|
250
299
|
webhookRouter: this.webhookRouter,
|
|
300
|
+
webhookRegistry: this.webhookRegistry,
|
|
251
301
|
queueProvider: this.queueProvider,
|
|
252
302
|
cronRouter: this.cronRouter,
|
|
253
303
|
cronRegistry: this.cronRegistry,
|
|
@@ -271,9 +321,9 @@ export class DurableInterpreter {
|
|
|
271
321
|
this.registeredWorkflows.push(registration);
|
|
272
322
|
return registration;
|
|
273
323
|
}
|
|
274
|
-
start() {
|
|
275
|
-
const port = Deno.env.get(
|
|
276
|
-
const cronPort = Deno.env.get(
|
|
324
|
+
async start() {
|
|
325
|
+
const port = Deno.env.get(envPort) || 3000;
|
|
326
|
+
const cronPort = Deno.env.get(envCronPort) || 3001;
|
|
277
327
|
const webhookApp = express();
|
|
278
328
|
const cronApp = express();
|
|
279
329
|
cronApp.use(express.json());
|
|
@@ -297,11 +347,17 @@ export class DurableInterpreter {
|
|
|
297
347
|
ctx.log.error('DurableInterpreter.executionError', {
|
|
298
348
|
error: err instanceof Error ? err.toString() : err,
|
|
299
349
|
});
|
|
350
|
+
this.tracer.startActiveSpan('done', (span) => {
|
|
351
|
+
span.setAttribute('error.message', err instanceof Error ? err.toString() : err);
|
|
352
|
+
span.setAttribute('execution.id', ctx.executionId);
|
|
353
|
+
span.setAttribute('result', 'fail');
|
|
354
|
+
span.end();
|
|
355
|
+
});
|
|
300
356
|
try {
|
|
301
357
|
ctx.options.onError?.(ctx.withData(err));
|
|
302
358
|
}
|
|
303
359
|
catch (err) {
|
|
304
|
-
ctx.log.error('DurableInterpreter.
|
|
360
|
+
ctx.log.error('DurableInterpreter.onError Error: failed to call onError handler', { error: err instanceof Error ? err.toString() : err });
|
|
305
361
|
ctx.options.onError?.(ctx.withData({
|
|
306
362
|
message: 'Internal server error',
|
|
307
363
|
error: err instanceof Error ? err.toString() : err,
|
|
@@ -316,6 +372,11 @@ export class DurableInterpreter {
|
|
|
316
372
|
durationMs,
|
|
317
373
|
data: ctx.data,
|
|
318
374
|
});
|
|
375
|
+
this.tracer.startActiveSpan('done', (span) => {
|
|
376
|
+
span.setAttribute('execution.id', ctx.executionId);
|
|
377
|
+
span.setAttribute('result', 'pass');
|
|
378
|
+
span.end();
|
|
379
|
+
});
|
|
319
380
|
try {
|
|
320
381
|
ctx.options.onSuccess?.(ctx);
|
|
321
382
|
}
|
|
@@ -363,6 +424,9 @@ export class DurableInterpreter {
|
|
|
363
424
|
});
|
|
364
425
|
throw new Error('Unable to register scheduler tasks with central cron provider');
|
|
365
426
|
}
|
|
427
|
+
// register with supervisor
|
|
428
|
+
await registerCrons(this.cronRegistry);
|
|
429
|
+
await registerWebhooks(this.webhookRegistry);
|
|
366
430
|
this.webhookServer = webhookApp.listen(port, () => {
|
|
367
431
|
this.log.info(`Express server listening on port ${port}`);
|
|
368
432
|
});
|
|
@@ -382,6 +446,7 @@ export class DurableInterpreter {
|
|
|
382
446
|
if (this.cronServer) {
|
|
383
447
|
this.cronServer.close();
|
|
384
448
|
}
|
|
449
|
+
this.otelSDK?.shutdown();
|
|
385
450
|
// Remove all signal listeners
|
|
386
451
|
for (const registration of this.registeredWorkflows) {
|
|
387
452
|
Deno.removeSignalListener('SIGINT', registration.sigintListener);
|
|
@@ -434,7 +499,7 @@ export class DurableInterpreter {
|
|
|
434
499
|
}
|
|
435
500
|
}
|
|
436
501
|
async function waitForReady(log) {
|
|
437
|
-
const readyCheckUrl = Deno.env.get(
|
|
502
|
+
const readyCheckUrl = Deno.env.get(envReadyCheckURL);
|
|
438
503
|
if (!readyCheckUrl) {
|
|
439
504
|
return Promise.resolve();
|
|
440
505
|
}
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { Tracer } from '@opentelemetry/api';
|
|
2
2
|
import { Router } from 'express';
|
|
3
3
|
import { Observable, OperatorFunction } from 'rxjs';
|
|
4
|
+
import { ConnectionFactory } from '../../connection/types.js';
|
|
4
5
|
import { ContextImpl } from '../../context/Context.js';
|
|
5
6
|
import { ContextProvider } from '../../context/ContextProvider.js';
|
|
6
7
|
import { ConfigReader } from '../../dsl/http/types.js';
|
|
@@ -11,7 +12,6 @@ import { Logger } from '../../observability/logging/Logger.js';
|
|
|
11
12
|
import { PlatformApi } from '../../services/platform/mod.js';
|
|
12
13
|
import { ContextOperatorFunction, TaskCompiler, TriggerCompiler } from './compilers/types.js';
|
|
13
14
|
import { QueueAPI } from './Queue.js';
|
|
14
|
-
import { ConnectionFactory } from '../../connection/types.js';
|
|
15
15
|
export type DurableCompilerContext = {
|
|
16
16
|
compiler: ObservableCompiler;
|
|
17
17
|
log: Logger;
|
|
@@ -22,6 +22,11 @@ export type DurableCompilerContext = {
|
|
|
22
22
|
queueProvider: QueueAPI;
|
|
23
23
|
issueProvider: IssueAPI;
|
|
24
24
|
webhookRouter: Router;
|
|
25
|
+
webhookRegistry: Map<string, {
|
|
26
|
+
method: string;
|
|
27
|
+
path: string;
|
|
28
|
+
options: any;
|
|
29
|
+
}>;
|
|
25
30
|
cronRouter: Router;
|
|
26
31
|
configReader: ConfigReader;
|
|
27
32
|
cronRegistry: Map<string, string>;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ObservableCompiler.d.ts","sourceRoot":"","sources":["../../../../src/src/interpreter/durable/ObservableCompiler.ts"],"names":[],"mappings":"AAaA,OAAO,EAAE,MAAM,EAAE,MAAM,oBAAoB,CAAC;AAC5C,OAAO,EAAE,MAAM,EAAE,MAAM,SAAS,CAAC;AACjC,OAAO,EAAE,UAAU,EAAE,gBAAgB,EAAE,MAAM,MAAM,CAAC;AACpD,OAAO,EAAE,WAAW,EAAE,MAAM,0BAA0B,CAAC;AACvD,OAAO,EAAE,eAAe,EAAE,MAAM,kCAAkC,CAAC;AACnE,OAAO,EAAE,YAAY,EAAE,MAAM,yBAAyB,CAAC;AACvD,OAAO,EAAE,IAAI,EAAY,MAAM,mBAAmB,CAAC;AACnD,OAAO,EAAE,OAAO,EAAe,MAAM,sBAAsB,CAAC;AAC5D,OAAO,EAAE,QAAQ,EAAE,MAAM,wBAAwB,CAAC;AAClD,OAAO,EAAE,MAAM,EAAE,MAAM,uCAAuC,CAAC;AAC/D,OAAO,EAAE,WAAW,EAAE,MAAM,gCAAgC,CAAC;AAU7D,OAAO,EAAE,uBAAuB,EAAE,YAAY,EAAE,eAAe,EAAE,MAAM,sBAAsB,CAAC;AAG9F,OAAO,EAAE,QAAQ,EAAE,MAAM,YAAY,CAAC;
|
|
1
|
+
{"version":3,"file":"ObservableCompiler.d.ts","sourceRoot":"","sources":["../../../../src/src/interpreter/durable/ObservableCompiler.ts"],"names":[],"mappings":"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"}
|
|
@@ -10,7 +10,7 @@
|
|
|
10
10
|
* As of the Change Date, in accordance with the Business Source License,
|
|
11
11
|
* use of this software will be governed by the Apache License, Version 2.0.
|
|
12
12
|
*/
|
|
13
|
-
import { envVarEnvId, envVarProjectId, envVarSDKApiBaseURL, } from '../../
|
|
13
|
+
import { envVarEnvId, envVarProjectId, envVarSDKApiBaseURL, } from '../../internal/constants.js';
|
|
14
14
|
import { ConsoleLogger } from '../../mod.js';
|
|
15
15
|
export class QueueImpl {
|
|
16
16
|
constructor(baseUrl, projectId, environmentId, log) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"catch.d.ts","sourceRoot":"","sources":["../../../../../src/src/interpreter/durable/compilers/catch.ts"],"names":[],"mappings":"AAgBA,OAAO,EAAE,SAAS,EAAE,MAAM,iCAAiC,CAAC;AAG5D,OAAO,EAA2B,YAAY,EAAE,MAAM,YAAY,CAAC;
|
|
1
|
+
{"version":3,"file":"catch.d.ts","sourceRoot":"","sources":["../../../../../src/src/interpreter/durable/compilers/catch.ts"],"names":[],"mappings":"AAgBA,OAAO,EAAE,SAAS,EAAE,MAAM,iCAAiC,CAAC;AAG5D,OAAO,EAA2B,YAAY,EAAE,MAAM,YAAY,CAAC;AAoFnE,eAAO,MAAM,aAAa,EAAE,YAAY,CAAC,GAAG,EAAE,GAAG,EAAE,SAAS,CAAC,GAAG,EAAE,GAAG,CAAC,CAGrE,CAAC"}
|
|
@@ -22,6 +22,7 @@ function compileCatch(compilerCtx, task) {
|
|
|
22
22
|
return compilerCtx.tracer.startActiveSpan(`catch`, (span) => {
|
|
23
23
|
span.setAttribute('execution.id', ctx.executionId);
|
|
24
24
|
span.setAttribute('task.type', 'catch');
|
|
25
|
+
span.setAttribute('type', 'task');
|
|
25
26
|
if (error instanceof Error) {
|
|
26
27
|
span.recordException(error);
|
|
27
28
|
span.setAttribute('error.message', error.message);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"fn.d.ts","sourceRoot":"","sources":["../../../../../src/src/interpreter/durable/compilers/fn.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"fn.d.ts","sourceRoot":"","sources":["../../../../../src/src/interpreter/durable/compilers/fn.ts"],"names":[],"mappings":"AA+BA,OAAO,EAAE,MAAM,EAAE,MAAM,8BAA8B,CAAC;AAGtD,OAAO,EAA2B,YAAY,EAAE,MAAM,YAAY,CAAC;AA0CnE,eAAO,MAAM,UAAU,EAAE,YAAY,CAAC,GAAG,EAAE,GAAG,EAAE,MAAM,CAAC,GAAG,EAAE,GAAG,CAAC,CAG/D,CAAC"}
|
|
@@ -12,19 +12,34 @@
|
|
|
12
12
|
*/
|
|
13
13
|
import { mergeMap, tap } from 'rxjs';
|
|
14
14
|
import { FnTask } from '../../../dsl/tasks/FnTask.js';
|
|
15
|
+
import { enabled as supervisorEnabled } from '../../../internal/supervisor.js';
|
|
15
16
|
function compileFn(compilerCtx, task) {
|
|
16
17
|
return (src) => src.pipe(tap({
|
|
17
18
|
complete: () => compilerCtx.log.debug('fn.complete'),
|
|
18
19
|
}), mergeMap(async (ctx) => {
|
|
19
20
|
return await compilerCtx.tracer.startActiveSpan(`fn-${task.id}`, async (span) => {
|
|
20
21
|
span.setAttribute('task.id', task.id);
|
|
22
|
+
span.setAttribute('type', 'task');
|
|
23
|
+
span.setAttribute('task.type', 'fn');
|
|
21
24
|
span.setAttribute('execution.id', ctx.executionId);
|
|
22
|
-
|
|
25
|
+
try {
|
|
26
|
+
const spanContext = span.spanContext();
|
|
27
|
+
const ctxWithLogger = ctx.withLogger(ctx.log.child({ spanId: spanContext.spanId, traceId: spanContext.traceId }));
|
|
28
|
+
let result;
|
|
29
|
+
if (typeof ctx.idx === 'number') {
|
|
30
|
+
result = ctx.withData(await task._fn(ctxWithLogger, ctx.idx));
|
|
31
|
+
}
|
|
32
|
+
else {
|
|
33
|
+
result = ctx.withData(await task._fn(ctxWithLogger));
|
|
34
|
+
}
|
|
35
|
+
if (supervisorEnabled) {
|
|
36
|
+
span.setAttribute('response.body', JSON.stringify(result.data));
|
|
37
|
+
}
|
|
38
|
+
return result;
|
|
39
|
+
}
|
|
40
|
+
finally {
|
|
23
41
|
span.end();
|
|
24
|
-
return ctx.withData(await task._fn(ctx, ctx.idx));
|
|
25
42
|
}
|
|
26
|
-
span.end();
|
|
27
|
-
return ctx.withData(await task._fn(ctx));
|
|
28
43
|
});
|
|
29
44
|
}));
|
|
30
45
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"http.d.ts","sourceRoot":"","sources":["../../../../../src/src/interpreter/durable/compilers/http.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"http.d.ts","sourceRoot":"","sources":["../../../../../src/src/interpreter/durable/compilers/http.ts"],"names":[],"mappings":"AAqBA,OAAO,EAAmB,YAAY,EAAE,MAAM,gCAAgC,CAAC;AAG/E,OAAO,EAA2B,YAAY,EAAE,MAAM,YAAY,CAAC;AAuHnE,eAAO,MAAM,YAAY,EAAE,YAAY,CAAC,GAAG,EAAE,GAAG,EAAE,YAAY,CAAC,GAAG,EAAE,GAAG,EAAE,GAAG,CAAC,CAG5E,CAAC"}
|
|
@@ -12,18 +12,32 @@
|
|
|
12
12
|
*/
|
|
13
13
|
import { mergeMap } from 'rxjs';
|
|
14
14
|
import { tap } from 'rxjs/operators';
|
|
15
|
-
import { HttpContextImpl, HttpTaskImpl } from '../../../dsl/tasks/HttpTask.js';
|
|
16
15
|
import { DynamicFetchFactory } from '../../../connection/DynamicFetchFactory.js';
|
|
16
|
+
import { FetchBuilder } from '../../../connection/internal/FetchBuilder.js';
|
|
17
17
|
import { StaticFetchFactory } from '../../../connection/StaticFetchFactory.js';
|
|
18
|
+
import { HttpContextImpl, HttpTaskImpl } from '../../../dsl/tasks/HttpTask.js';
|
|
19
|
+
import { enabled as supervisorEnabled } from '../../../internal/supervisor.js';
|
|
18
20
|
function compileHttp(compilerCtx, task) {
|
|
19
21
|
const cnxMap = compilerCtx.configReader.getCnxMapping(task.opts.connection);
|
|
20
22
|
let fetchFactory;
|
|
21
23
|
if (!cnxMap) {
|
|
22
|
-
compilerCtx.log.
|
|
23
|
-
|
|
24
|
+
compilerCtx.log.warn(`Connection ${task.opts.connection} not found, using default fetch with no credentials`);
|
|
25
|
+
if (supervisorEnabled) {
|
|
26
|
+
// missing connection map and we are in supervised mode, so we use the fake fetcher
|
|
27
|
+
fetchFactory = Promise.resolve(new StaticFetchFactory(new FetchBuilder(globalThis.fetch, { name: task.opts.connection }).buildSupervisedFetch()));
|
|
28
|
+
}
|
|
29
|
+
else {
|
|
30
|
+
// missing connection map and not in supervised mode, so we use global fetch
|
|
31
|
+
fetchFactory = Promise.resolve(new StaticFetchFactory(globalThis.fetch));
|
|
32
|
+
}
|
|
24
33
|
}
|
|
25
34
|
else if (cnxMap.dynamic) {
|
|
26
|
-
|
|
35
|
+
if (cnxMap.mockWithAI) {
|
|
36
|
+
fetchFactory = Promise.resolve(new StaticFetchFactory(new FetchBuilder(globalThis.fetch, { name: task.opts.connection }).buildSupervisedFetch()));
|
|
37
|
+
}
|
|
38
|
+
else {
|
|
39
|
+
fetchFactory = Promise.resolve(new DynamicFetchFactory(compilerCtx.cnxFactory, compilerCtx.platformApi, compilerCtx.organisationId, cnxMap.templateId));
|
|
40
|
+
}
|
|
27
41
|
}
|
|
28
42
|
else {
|
|
29
43
|
fetchFactory = compilerCtx.platformApi.getConnection({
|
|
@@ -33,8 +47,21 @@ function compileHttp(compilerCtx, task) {
|
|
|
33
47
|
},
|
|
34
48
|
throwOnError: true,
|
|
35
49
|
})
|
|
36
|
-
.then(({ data }) =>
|
|
37
|
-
.
|
|
50
|
+
.then(({ data }) => {
|
|
51
|
+
if (cnxMap.mockWithAI) {
|
|
52
|
+
// use the fake fetcher that calls the supervisor to generate a mock reponse
|
|
53
|
+
return new StaticFetchFactory(new FetchBuilder(globalThis.fetch, data).buildSupervisedFetch());
|
|
54
|
+
}
|
|
55
|
+
return Promise.all([compilerCtx.cnxFactory.fetcher(data), data.baseUrl ?? ''])
|
|
56
|
+
.then(([fetcher, baseUrl]) => new StaticFetchFactory(fetcher, baseUrl));
|
|
57
|
+
})
|
|
58
|
+
.catch((err) => {
|
|
59
|
+
compilerCtx.log.error(`Failed to get connection ${task.opts.connection}`, err);
|
|
60
|
+
if (supervisorEnabled) {
|
|
61
|
+
return new StaticFetchFactory(new FetchBuilder(globalThis.fetch, { name: task.opts.connection }).build());
|
|
62
|
+
}
|
|
63
|
+
throw err;
|
|
64
|
+
});
|
|
38
65
|
}
|
|
39
66
|
async function http(ctx) {
|
|
40
67
|
const [fetch, baseUrl] = await fetchFactory.then((ff) => Promise.all([ff.fetcher(ctx), ff.baseUrl(ctx)]));
|
|
@@ -48,10 +75,16 @@ function compileHttp(compilerCtx, task) {
|
|
|
48
75
|
return compilerCtx.tracer.startActiveSpan(`http-${task.id}`, async (span) => {
|
|
49
76
|
span.setAttribute('task.id', task.id);
|
|
50
77
|
span.setAttribute('task.type', 'http');
|
|
78
|
+
span.setAttribute('type', 'task');
|
|
51
79
|
span.setAttribute('execution.id', ctx.executionId);
|
|
52
80
|
span.setAttribute('connection.name', task.opts.connection);
|
|
81
|
+
const spanContext = span.spanContext();
|
|
53
82
|
try {
|
|
54
|
-
|
|
83
|
+
const result = await http(ctx.withLogger(ctx.log.child({ spanId: spanContext.spanId, traceId: spanContext.traceId })));
|
|
84
|
+
if (supervisorEnabled) {
|
|
85
|
+
span.setAttribute('response.body', JSON.stringify(result.data));
|
|
86
|
+
}
|
|
87
|
+
return result;
|
|
55
88
|
}
|
|
56
89
|
catch (error) {
|
|
57
90
|
if (error instanceof Error) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"schedule.d.ts","sourceRoot":"","sources":["../../../../../src/src/interpreter/durable/compilers/schedule.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"schedule.d.ts","sourceRoot":"","sources":["../../../../../src/src/interpreter/durable/compilers/schedule.ts"],"names":[],"mappings":"AAiBA,OAAO,EAAE,YAAY,EAAE,eAAe,EAAE,MAAM,0CAA0C,CAAC;AAQzF,OAAO,EAAE,eAAe,EAAE,MAAM,YAAY,CAAC;AAmJ7C,eAAO,MAAM,gBAAgB,EAAE,eAAe,CAAC,YAAY,EAAE,eAAe,CAG3E,CAAC"}
|
|
@@ -11,8 +11,8 @@
|
|
|
11
11
|
* use of this software will be governed by the Apache License, Version 2.0.
|
|
12
12
|
*/
|
|
13
13
|
import { Observable } from 'rxjs';
|
|
14
|
-
import { envVarEnvId, envVarEnvironmentName, envVarOrgId, envVarProjectId, } from '../../../dsl/http/versori/constants.js';
|
|
15
14
|
import { ScheduleTrigger } from '../../../dsl/triggers/ScheduleTrigger.js';
|
|
15
|
+
import { envVarEnvId, envVarEnvironmentName, envVarOrgId, envVarProjectId, } from '../../../internal/constants.js';
|
|
16
16
|
function compileSchedule(ctx, trigger, signal) {
|
|
17
17
|
return new Observable((subscriber) => {
|
|
18
18
|
// Add HTTP endpoint for manual triggering
|
|
@@ -103,6 +103,7 @@ function compileSchedule(ctx, trigger, signal) {
|
|
|
103
103
|
await ctx.tracer.startActiveSpan(`schedule-${trigger.id}`, async (span) => {
|
|
104
104
|
span.setAttribute('task.id', trigger.id);
|
|
105
105
|
span.setAttribute('task.type', 'schedule');
|
|
106
|
+
span.setAttribute('type', 'task');
|
|
106
107
|
span.setAttribute('schedule', trigger.schedule);
|
|
107
108
|
span.setAttribute('project.id', projectId);
|
|
108
109
|
span.setAttribute('environment.id', environmentId);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"webhook.d.ts","sourceRoot":"","sources":["../../../../../src/src/interpreter/durable/compilers/webhook.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"webhook.d.ts","sourceRoot":"","sources":["../../../../../src/src/interpreter/durable/compilers/webhook.ts"],"names":[],"mappings":"AA2BA,OAAO,EAAE,WAAW,EAAE,cAAc,EAAE,MAAM,yCAAyC,CAAC;AAGtF,OAAO,EAAE,eAAe,EAAE,MAAM,YAAY,CAAC;AAuD7C,eAAO,MAAM,eAAe,EAAE,eAAe,CAAC,WAAW,EAAE,cAAc,CAwTxE,CAAC"}
|
|
@@ -12,12 +12,12 @@
|
|
|
12
12
|
*/
|
|
13
13
|
import cors from 'cors';
|
|
14
14
|
import express from 'express';
|
|
15
|
+
import xmlparser from 'express-xml-bodyparser';
|
|
15
16
|
import { pipeline } from 'node:stream/promises';
|
|
16
17
|
import { Observable } from 'rxjs';
|
|
17
18
|
import { createActIdDynamicWebhookMiddleware, createStaticWebhookMiddleware, createUserIdDynamicWebhookMiddleware, } from '../../../dsl/http/versori/webhookmiddleware.js';
|
|
18
19
|
import { WebhookTrigger } from '../../../dsl/triggers/WebhookTrigger.js';
|
|
19
20
|
import { envVarEnvId } from '../../../internal/constants.js';
|
|
20
|
-
import xmlparser from 'express-xml-bodyparser';
|
|
21
21
|
const xml2jsDefaults = {
|
|
22
22
|
explicitArray: false,
|
|
23
23
|
normalize: false,
|
|
@@ -103,6 +103,7 @@ export const webhookCompiler = {
|
|
|
103
103
|
else {
|
|
104
104
|
ctx.webhookRouter.use(express.raw({ type: '*/*', limit: '50mb' }));
|
|
105
105
|
}
|
|
106
|
+
ctx.webhookRegistry.set(trigger.id, { method, path: `/${trigger.id}`, options: trigger.options });
|
|
106
107
|
return new Observable((subscriber) => {
|
|
107
108
|
if (!ctx.webhookRouter) {
|
|
108
109
|
throw new Error('Router not available in compiler context');
|
|
@@ -131,8 +132,11 @@ export const webhookCompiler = {
|
|
|
131
132
|
await ctx.tracer.startActiveSpan(`webhook-${trigger.id}`, (span) => {
|
|
132
133
|
span.setAttribute('task.id', trigger.id);
|
|
133
134
|
span.setAttribute('task.type', 'webhook');
|
|
135
|
+
span.setAttribute('type', 'task');
|
|
134
136
|
const staticActivation = res.locals.activation;
|
|
135
|
-
|
|
137
|
+
let executionCtx = ctx.contextProvider.create(staticActivation, req.body, ctxOptionsFn(req, res));
|
|
138
|
+
const spanContext = span.spanContext();
|
|
139
|
+
executionCtx = executionCtx.withLogger(executionCtx.log.child({ spanId: spanContext.spanId, traceId: spanContext.traceId }));
|
|
136
140
|
span.setAttribute('execution.id', executionCtx.executionId);
|
|
137
141
|
try {
|
|
138
142
|
subscriber.next(executionCtx);
|
|
@@ -167,6 +171,7 @@ export const webhookCompiler = {
|
|
|
167
171
|
await ctx.tracer.startActiveSpan(`webhook-${trigger.id}`, (span) => {
|
|
168
172
|
span.setAttribute('task.id', trigger.id);
|
|
169
173
|
span.setAttribute('task.type', 'webhook');
|
|
174
|
+
span.setAttribute('type', 'task');
|
|
170
175
|
span.setAttribute('user.id', req.params.userId);
|
|
171
176
|
const userId = req.params.userId;
|
|
172
177
|
const activation = res.locals.activation;
|
|
@@ -183,7 +188,9 @@ export const webhookCompiler = {
|
|
|
183
188
|
span.end();
|
|
184
189
|
return;
|
|
185
190
|
}
|
|
186
|
-
|
|
191
|
+
let executionCtx = ctx.contextProvider.create(activation, req.body, ctxOptionsFn(req, res));
|
|
192
|
+
const spanContext = span.spanContext();
|
|
193
|
+
executionCtx = executionCtx.withLogger(executionCtx.log.child({ spanId: spanContext.spanId, traceId: spanContext.traceId }));
|
|
187
194
|
span.setAttribute('execution.id', executionCtx.executionId);
|
|
188
195
|
const errors = [];
|
|
189
196
|
try {
|
|
@@ -222,6 +229,7 @@ export const webhookCompiler = {
|
|
|
222
229
|
}), async (req, res) => {
|
|
223
230
|
await ctx.tracer.startActiveSpan(`webhook-${trigger.id}`, (span) => {
|
|
224
231
|
span.setAttribute('task.id', trigger.id);
|
|
232
|
+
span.setAttribute('type', 'task');
|
|
225
233
|
span.setAttribute('task.type', 'webhook');
|
|
226
234
|
span.setAttribute('activation.id', req.params.activationId);
|
|
227
235
|
const activation = res.locals.activation;
|
|
@@ -237,7 +245,9 @@ export const webhookCompiler = {
|
|
|
237
245
|
span.end();
|
|
238
246
|
return;
|
|
239
247
|
}
|
|
240
|
-
|
|
248
|
+
let activationCtx = ctx.contextProvider.create(activation, req.body, ctxOptionsFn(req, res));
|
|
249
|
+
const spanContext = span.spanContext();
|
|
250
|
+
activationCtx = activationCtx.withLogger(activationCtx.log.child({ spanId: spanContext.spanId, traceId: spanContext.traceId }));
|
|
241
251
|
span.setAttribute('execution.id', activationCtx.executionId);
|
|
242
252
|
try {
|
|
243
253
|
subscriber.next(activationCtx);
|
|
@@ -43,6 +43,11 @@ type Registration = {
|
|
|
43
43
|
sigintListener: () => void;
|
|
44
44
|
subscription?: Subscription;
|
|
45
45
|
};
|
|
46
|
+
type WebhookRegistry = Map<string, {
|
|
47
|
+
method: string;
|
|
48
|
+
path: string;
|
|
49
|
+
options: any;
|
|
50
|
+
}>;
|
|
46
51
|
/**
|
|
47
52
|
* MemoryInterpreter is the default interpreter for executing Versori workflows. It handles registration and execution
|
|
48
53
|
* of workflows triggered by schedules and webhooks.
|
|
@@ -71,6 +76,7 @@ export declare class MemoryInterpreter {
|
|
|
71
76
|
private readonly webhookRouter;
|
|
72
77
|
private readonly cronRouter;
|
|
73
78
|
private cronRegistry;
|
|
79
|
+
private webhookRegistry;
|
|
74
80
|
private readonly cnxFactory;
|
|
75
81
|
private readonly cronProvider;
|
|
76
82
|
private readonly tracer;
|
|
@@ -82,7 +88,7 @@ export declare class MemoryInterpreter {
|
|
|
82
88
|
private cronServer?;
|
|
83
89
|
private shutdownServer?;
|
|
84
90
|
private isShuttingDown;
|
|
85
|
-
constructor(log: Logger, compiler: ObservableCompiler, contextProvider: ContextProvider, webhookRouter: Router, cronRouter: Router, cronRegistry: Map<string, string>, cnxFactory: DirectConnectionFactory, cronProvider: CronProvider, tracer: Tracer, issuesProvider: IssueAPI, cfgReader: ConfigReader, otelSDK?: NodeSDK | undefined);
|
|
91
|
+
constructor(log: Logger, compiler: ObservableCompiler, contextProvider: ContextProvider, webhookRouter: Router, cronRouter: Router, cronRegistry: Map<string, string>, webhookRegistry: WebhookRegistry, cnxFactory: DirectConnectionFactory, cronProvider: CronProvider, tracer: Tracer, issuesProvider: IssueAPI, cfgReader: ConfigReader, otelSDK?: NodeSDK | undefined);
|
|
86
92
|
static newInstance(options?: MemoryInterpreterOptions): Promise<MemoryInterpreter>;
|
|
87
93
|
register<O>(workflow: Workflow<O>, options?: MemoryInterpreterOptions): Registration;
|
|
88
94
|
start(): Promise<void>;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"MemoryInterpreter.d.ts","sourceRoot":"","sources":["../../../../src/src/interpreter/memory/MemoryInterpreter.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"MemoryInterpreter.d.ts","sourceRoot":"","sources":["../../../../src/src/interpreter/memory/MemoryInterpreter.ts"],"names":[],"mappings":"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"}
|