@versori/run 0.1.0-alpha.9 → 0.2.0-alpha.10
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/_dnt.shims.d.ts +1 -5
- package/esm/_dnt.shims.d.ts.map +1 -1
- package/esm/_dnt.shims.js +1 -5
- package/esm/deps/jsr.io/@nats-io/transport-deno/3.0.2/src/deno_transport.d.ts +1 -2
- package/esm/deps/jsr.io/@nats-io/transport-deno/3.0.2/src/deno_transport.d.ts.map +1 -1
- package/esm/deps/jsr.io/@nats-io/transport-deno/3.0.2/src/deno_transport.js +6 -7
- package/{script/deps/jsr.io/@std/fmt/1.0.6 → esm/deps/jsr.io/@std/fmt/1.0.7}/colors.d.ts.map +1 -1
- package/{script/deps/jsr.io/@std/fs/1.0.16 → esm/deps/jsr.io/@std/fs/1.0.17}/exists.d.ts +1 -0
- package/esm/deps/jsr.io/@std/fs/1.0.17/exists.d.ts.map +1 -0
- package/esm/deps/jsr.io/@std/fs/{1.0.16 → 1.0.17}/exists.js +10 -12
- package/esm/deps/jsr.io/@std/log/0.224.14/base_handler.d.ts +0 -21
- package/esm/deps/jsr.io/@std/log/0.224.14/base_handler.d.ts.map +1 -1
- package/esm/deps/jsr.io/@std/log/0.224.14/console_handler.js +1 -1
- package/esm/deps/jsr.io/@std/log/0.224.14/file_handler.d.ts +2 -3
- package/esm/deps/jsr.io/@std/log/0.224.14/file_handler.d.ts.map +1 -1
- package/esm/deps/jsr.io/@std/log/0.224.14/file_handler.js +1 -2
- package/esm/deps/jsr.io/@std/log/0.224.14/rotating_file_handler.d.ts.map +1 -1
- package/esm/deps/jsr.io/@std/log/0.224.14/rotating_file_handler.js +7 -9
- package/esm/src/context/Context.d.ts +16 -4
- package/esm/src/context/Context.d.ts.map +1 -1
- package/esm/src/context/Context.js +31 -10
- package/esm/src/context/ContextProvider.d.ts +3 -4
- package/esm/src/context/ContextProvider.d.ts.map +1 -1
- package/esm/src/context/ContextProvider.js +5 -5
- package/esm/src/dsl/http/types.d.ts +13 -2
- package/esm/src/dsl/http/types.d.ts.map +1 -1
- package/esm/src/dsl/http/versori/activation.d.ts +13 -0
- package/esm/src/dsl/http/versori/activation.d.ts.map +1 -0
- package/esm/src/dsl/http/versori/activation.js +65 -0
- package/esm/src/dsl/http/versori/configloader.d.ts.map +1 -1
- package/esm/src/dsl/http/versori/configloader.js +2 -3
- package/esm/src/dsl/http/versori/constants.d.ts +5 -0
- package/esm/src/dsl/http/versori/constants.d.ts.map +1 -1
- package/esm/src/dsl/http/versori/constants.js +5 -0
- package/esm/src/dsl/http/versori/credentials/client.d.ts +1 -4
- package/esm/src/dsl/http/versori/credentials/client.d.ts.map +1 -1
- package/esm/src/dsl/http/versori/credentials/client.js +3 -16
- package/esm/src/dsl/http/versori/cronapi.d.ts +10 -0
- package/esm/src/dsl/http/versori/cronapi.d.ts.map +1 -0
- package/esm/src/dsl/http/versori/cronapi.js +51 -0
- package/esm/src/dsl/http/versori/internalauth.d.ts.map +1 -1
- package/esm/src/dsl/http/versori/internalauth.js +5 -6
- package/esm/src/dsl/http/versori/platformapi.d.ts +4 -1
- package/esm/src/dsl/http/versori/platformapi.d.ts.map +1 -1
- package/esm/src/dsl/http/versori/platformapi.js +41 -10
- package/esm/src/dsl/http/versori/roundtripper.d.ts +3 -2
- package/esm/src/dsl/http/versori/roundtripper.d.ts.map +1 -1
- package/esm/src/dsl/http/versori/roundtripper.js +128 -78
- package/esm/src/dsl/tasks/HttpTask.d.ts +1 -1
- package/esm/src/dsl/tasks/HttpTask.d.ts.map +1 -1
- package/esm/src/dsl/tasks/HttpTask.js +1 -1
- package/esm/src/dsl/triggers/WebhookTrigger.d.ts +45 -3
- package/esm/src/dsl/triggers/WebhookTrigger.d.ts.map +1 -1
- package/esm/src/dsl/triggers/WebhookTrigger.js +10 -6
- package/esm/src/interpreter/memory/MemoryInterpreter.d.ts +10 -3
- package/esm/src/interpreter/memory/MemoryInterpreter.d.ts.map +1 -1
- package/esm/src/interpreter/memory/MemoryInterpreter.js +121 -13
- package/esm/src/interpreter/memory/ObservableCompiler.d.ts +1 -0
- package/esm/src/interpreter/memory/ObservableCompiler.d.ts.map +1 -1
- package/esm/src/interpreter/memory/compilers/schedule.d.ts.map +1 -1
- package/esm/src/interpreter/memory/compilers/schedule.js +19 -24
- package/esm/src/interpreter/memory/compilers/webhook.d.ts.map +1 -1
- package/esm/src/interpreter/memory/compilers/webhook.js +132 -25
- package/esm/src/kv/nats/NatsKeyValueProvider.d.ts +0 -1
- package/esm/src/kv/nats/NatsKeyValueProvider.d.ts.map +1 -1
- package/esm/src/kv/nats/NatsKeyValueProvider.js +7 -8
- package/esm/src/observability/logging/ConsoleLogger.d.ts.map +1 -1
- package/esm/src/observability/logging/ConsoleLogger.js +55 -10
- package/package.json +3 -6
- package/script/_dnt.shims.d.ts +1 -5
- package/script/_dnt.shims.d.ts.map +1 -1
- package/script/_dnt.shims.js +2 -7
- package/script/deps/jsr.io/@nats-io/transport-deno/3.0.2/src/deno_transport.d.ts +1 -2
- package/script/deps/jsr.io/@nats-io/transport-deno/3.0.2/src/deno_transport.d.ts.map +1 -1
- package/script/deps/jsr.io/@nats-io/transport-deno/3.0.2/src/deno_transport.js +9 -33
- package/{esm/deps/jsr.io/@std/fmt/1.0.6 → script/deps/jsr.io/@std/fmt/1.0.7}/colors.d.ts.map +1 -1
- package/{esm/deps/jsr.io/@std/fs/1.0.16 → script/deps/jsr.io/@std/fs/1.0.17}/exists.d.ts +1 -0
- package/script/deps/jsr.io/@std/fs/1.0.17/exists.d.ts.map +1 -0
- package/script/deps/jsr.io/@std/fs/{1.0.16 → 1.0.17}/exists.js +10 -35
- package/script/deps/jsr.io/@std/log/0.224.14/base_handler.d.ts +0 -21
- package/script/deps/jsr.io/@std/log/0.224.14/base_handler.d.ts.map +1 -1
- package/script/deps/jsr.io/@std/log/0.224.14/console_handler.js +1 -1
- package/script/deps/jsr.io/@std/log/0.224.14/file_handler.d.ts +2 -3
- package/script/deps/jsr.io/@std/log/0.224.14/file_handler.d.ts.map +1 -1
- package/script/deps/jsr.io/@std/log/0.224.14/file_handler.js +1 -25
- package/script/deps/jsr.io/@std/log/0.224.14/rotating_file_handler.d.ts.map +1 -1
- package/script/deps/jsr.io/@std/log/0.224.14/rotating_file_handler.js +7 -32
- package/script/src/context/Context.d.ts +16 -4
- package/script/src/context/Context.d.ts.map +1 -1
- package/script/src/context/Context.js +31 -10
- package/script/src/context/ContextProvider.d.ts +3 -4
- package/script/src/context/ContextProvider.d.ts.map +1 -1
- package/script/src/context/ContextProvider.js +5 -5
- package/script/src/dsl/http/types.d.ts +13 -2
- package/script/src/dsl/http/types.d.ts.map +1 -1
- package/script/src/dsl/http/versori/activation.d.ts +13 -0
- package/script/src/dsl/http/versori/activation.d.ts.map +1 -0
- package/script/src/dsl/http/versori/activation.js +69 -0
- package/script/src/dsl/http/versori/configloader.d.ts.map +1 -1
- package/script/src/dsl/http/versori/configloader.js +2 -26
- package/script/src/dsl/http/versori/constants.d.ts +5 -0
- package/script/src/dsl/http/versori/constants.d.ts.map +1 -1
- package/script/src/dsl/http/versori/constants.js +6 -1
- package/script/src/dsl/http/versori/credentials/client.d.ts +1 -4
- package/script/src/dsl/http/versori/credentials/client.d.ts.map +1 -1
- package/script/src/dsl/http/versori/credentials/client.js +2 -15
- package/script/src/dsl/http/versori/cronapi.d.ts +10 -0
- package/script/src/dsl/http/versori/cronapi.d.ts.map +1 -0
- package/script/src/dsl/http/versori/cronapi.js +55 -0
- package/script/src/dsl/http/versori/internalauth.d.ts.map +1 -1
- package/script/src/dsl/http/versori/internalauth.js +5 -29
- package/script/src/dsl/http/versori/platformapi.d.ts +4 -1
- package/script/src/dsl/http/versori/platformapi.d.ts.map +1 -1
- package/script/src/dsl/http/versori/platformapi.js +41 -33
- package/script/src/dsl/http/versori/roundtripper.d.ts +3 -2
- package/script/src/dsl/http/versori/roundtripper.d.ts.map +1 -1
- package/script/src/dsl/http/versori/roundtripper.js +128 -101
- package/script/src/dsl/tasks/HttpTask.d.ts +1 -1
- package/script/src/dsl/tasks/HttpTask.d.ts.map +1 -1
- package/script/src/dsl/tasks/HttpTask.js +1 -1
- package/script/src/dsl/triggers/WebhookTrigger.d.ts +45 -3
- package/script/src/dsl/triggers/WebhookTrigger.d.ts.map +1 -1
- package/script/src/dsl/triggers/WebhookTrigger.js +10 -6
- package/script/src/interpreter/memory/MemoryInterpreter.d.ts +10 -3
- package/script/src/interpreter/memory/MemoryInterpreter.d.ts.map +1 -1
- package/script/src/interpreter/memory/MemoryInterpreter.js +121 -36
- package/script/src/interpreter/memory/ObservableCompiler.d.ts +1 -0
- package/script/src/interpreter/memory/ObservableCompiler.d.ts.map +1 -1
- package/script/src/interpreter/memory/compilers/schedule.d.ts.map +1 -1
- package/script/src/interpreter/memory/compilers/schedule.js +19 -24
- package/script/src/interpreter/memory/compilers/webhook.d.ts.map +1 -1
- package/script/src/interpreter/memory/compilers/webhook.js +135 -25
- package/script/src/kv/nats/NatsKeyValueProvider.d.ts +0 -1
- package/script/src/kv/nats/NatsKeyValueProvider.d.ts.map +1 -1
- package/script/src/kv/nats/NatsKeyValueProvider.js +7 -31
- package/script/src/observability/logging/ConsoleLogger.d.ts.map +1 -1
- package/script/src/observability/logging/ConsoleLogger.js +55 -10
- package/esm/deps/jsr.io/@std/fs/1.0.16/exists.d.ts.map +0 -1
- package/script/deps/jsr.io/@std/fs/1.0.16/exists.d.ts.map +0 -1
- /package/esm/deps/jsr.io/@std/fmt/{1.0.6 → 1.0.7}/colors.d.ts +0 -0
- /package/esm/deps/jsr.io/@std/fmt/{1.0.6 → 1.0.7}/colors.js +0 -0
- /package/script/deps/jsr.io/@std/fmt/{1.0.6 → 1.0.7}/colors.d.ts +0 -0
- /package/script/deps/jsr.io/@std/fmt/{1.0.6 → 1.0.7}/colors.js +0 -0
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { Router } from 'express';
|
|
2
|
-
import { Observable } from 'rxjs';
|
|
2
|
+
import { Observable, Subscription } from 'rxjs';
|
|
3
3
|
import { ContextProvider } from '../../context/ContextProvider.js';
|
|
4
|
-
import { ConnectionProvider, RoundTripperFactory } from '../../dsl/http/types.js';
|
|
4
|
+
import { ConnectionProvider, CronProvider, RoundTripperFactory } from '../../dsl/http/types.js';
|
|
5
5
|
import { Workflow } from '../../dsl/Workflow.js';
|
|
6
6
|
import { Logger } from '../../observability/logging/Logger.js';
|
|
7
7
|
import { ObservableCompiler } from './ObservableCompiler.js';
|
|
@@ -18,6 +18,7 @@ type Registration = {
|
|
|
18
18
|
task$: ContextOperatorFunction<any, any, any>;
|
|
19
19
|
localAbortController: AbortController;
|
|
20
20
|
sigintListener: () => void;
|
|
21
|
+
subscription?: Subscription;
|
|
21
22
|
};
|
|
22
23
|
export declare class MemoryInterpreter {
|
|
23
24
|
private readonly log;
|
|
@@ -25,12 +26,18 @@ export declare class MemoryInterpreter {
|
|
|
25
26
|
private readonly contextProvider;
|
|
26
27
|
private readonly roundTripperFactory;
|
|
27
28
|
private readonly router;
|
|
29
|
+
private cronRegistry;
|
|
28
30
|
private readonly connectionProvider;
|
|
31
|
+
private readonly cronProvider;
|
|
29
32
|
private registeredWorkflows;
|
|
30
|
-
|
|
33
|
+
private server?;
|
|
34
|
+
private shutdownServer?;
|
|
35
|
+
private isShuttingDown;
|
|
36
|
+
constructor(log: Logger, compiler: ObservableCompiler, contextProvider: ContextProvider, roundTripperFactory: RoundTripperFactory, router: Router, cronRegistry: Map<string, string>, connectionProvider: ConnectionProvider, cronProvider: CronProvider);
|
|
31
37
|
static newInstance(options?: MemoryInterpreterOptions): Promise<MemoryInterpreter>;
|
|
32
38
|
register<O>(workflow: Workflow<O>, options?: MemoryInterpreterOptions): Registration;
|
|
33
39
|
start(): Promise<void>;
|
|
40
|
+
stop(): Promise<void>;
|
|
34
41
|
}
|
|
35
42
|
export {};
|
|
36
43
|
//# sourceMappingURL=MemoryInterpreter.d.ts.map
|
|
@@ -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":"AAAA,OAAgB,EAAqB,MAAM,EAAE,MAAM,SAAS,CAAC;AAC7D,OAAO,EAA+B,UAAU,EAAW,YAAY,EAAE,MAAM,MAAM,CAAC;AACtF,OAAO,EAAE,eAAe,EAAuB,MAAM,kCAAkC,CAAC;AAExF,OAAO,EAAE,kBAAkB,EAAE,YAAY,EAAE,mBAAmB,EAAE,MAAM,yBAAyB,CAAC;AAGhG,OAAO,EAAE,QAAQ,EAAgB,MAAM,uBAAuB,CAAC;AAI/D,OAAO,EAAE,MAAM,EAAE,MAAM,uCAAuC,CAAC;AAC/D,OAAO,EAAmB,kBAAkB,EAAE,MAAM,yBAAyB,CAAC;AAC9E,OAAO,EAAE,WAAW,EAAE,uBAAuB,EAAE,MAAM,cAAc,CAAC;AAIpE,MAAM,MAAM,wBAAwB,GAAG;IACnC,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,QAAQ,CAAC,EAAE,kBAAkB,CAAC;IAC9B,eAAe,CAAC,EAAE,eAAe,CAAC;IAClC,MAAM,CAAC,EAAE,WAAW,CAAC;IACrB,sBAAsB,CAAC,EAAE,OAAO,CAAC;CACpC,CAAC;AAEF,KAAK,YAAY,GAAG;IAChB,QAAQ,EAAE,UAAU,CAAC,WAAW,CAAC,GAAG,EAAE,IAAI,CAAC,CAAC,CAAC;IAC7C,KAAK,EAAE,uBAAuB,CAAC,GAAG,EAAE,GAAG,EAAE,GAAG,CAAC,CAAC;IAC9C,oBAAoB,EAAE,eAAe,CAAC;IACtC,cAAc,EAAE,MAAM,IAAI,CAAC;IAC3B,YAAY,CAAC,EAAE,YAAY,CAAC;CAC/B,CAAA;AAED,qBAAa,iBAAiB;IAOtB,OAAO,CAAC,QAAQ,CAAC,GAAG;IACpB,OAAO,CAAC,QAAQ,CAAC,QAAQ;IACzB,OAAO,CAAC,QAAQ,CAAC,eAAe;IAChC,OAAO,CAAC,QAAQ,CAAC,mBAAmB;IACpC,OAAO,CAAC,QAAQ,CAAC,MAAM;IACvB,OAAO,CAAC,YAAY;IACpB,OAAO,CAAC,QAAQ,CAAC,kBAAkB;IACnC,OAAO,CAAC,QAAQ,CAAC,YAAY;IAbjC,OAAO,CAAC,mBAAmB,CAA2B;IACtD,OAAO,CAAC,MAAM,CAAC,CAAS;IACxB,OAAO,CAAC,cAAc,CAAC,CAAa;IACpC,OAAO,CAAC,cAAc,CAAS;gBAGV,GAAG,EAAE,MAAM,EACX,QAAQ,EAAE,kBAAkB,EAC5B,eAAe,EAAE,eAAe,EAChC,mBAAmB,EAAE,mBAAmB,EACxC,MAAM,EAAE,MAAM,EACvB,YAAY,EAAE,GAAG,CAAC,MAAM,EAAE,MAAM,CAAC,EACxB,kBAAkB,EAAE,kBAAkB,EACtC,YAAY,EAAE,YAAY;WASlC,WAAW,CAAC,OAAO,GAAE,wBAA6B,GAAG,OAAO,CAAC,iBAAiB,CAAC;IAwC5F,QAAQ,CAAC,CAAC,EAAE,QAAQ,EAAE,QAAQ,CAAC,CAAC,CAAC,EAAE,OAAO,CAAC,EAAE,wBAAwB;IA8C/D,KAAK,IAAI,OAAO,CAAC,IAAI,CAAC;IA2ItB,IAAI,IAAI,OAAO,CAAC,IAAI,CAAC;CAK9B"}
|
|
@@ -1,33 +1,9 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
-
if (k2 === undefined) k2 = k;
|
|
4
|
-
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
-
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
-
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
-
}
|
|
8
|
-
Object.defineProperty(o, k2, desc);
|
|
9
|
-
}) : (function(o, m, k, k2) {
|
|
10
|
-
if (k2 === undefined) k2 = k;
|
|
11
|
-
o[k2] = m[k];
|
|
12
|
-
}));
|
|
13
|
-
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
-
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
-
}) : function(o, v) {
|
|
16
|
-
o["default"] = v;
|
|
17
|
-
});
|
|
18
|
-
var __importStar = (this && this.__importStar) || function (mod) {
|
|
19
|
-
if (mod && mod.__esModule) return mod;
|
|
20
|
-
var result = {};
|
|
21
|
-
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
22
|
-
__setModuleDefault(result, mod);
|
|
23
|
-
return result;
|
|
24
|
-
};
|
|
25
2
|
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
26
3
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
27
4
|
};
|
|
28
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
29
6
|
exports.MemoryInterpreter = void 0;
|
|
30
|
-
const dntShim = __importStar(require("../../../_dnt.shims.js"));
|
|
31
7
|
const express_1 = __importDefault(require("express"));
|
|
32
8
|
const rxjs_1 = require("rxjs");
|
|
33
9
|
const ContextProvider_js_1 = require("../../context/ContextProvider.js");
|
|
@@ -39,8 +15,9 @@ const MemoryKeyValueProvider_js_1 = require("../../kv/memory/MemoryKeyValueProvi
|
|
|
39
15
|
const NatsKeyValueProvider_js_1 = require("../../kv/nats/NatsKeyValueProvider.js");
|
|
40
16
|
const ConsoleLogger_js_1 = require("../../observability/logging/ConsoleLogger.js");
|
|
41
17
|
const ObservableCompiler_js_1 = require("./ObservableCompiler.js");
|
|
18
|
+
const cronapi_js_1 = require("../../dsl/http/versori/cronapi.js");
|
|
42
19
|
class MemoryInterpreter {
|
|
43
|
-
constructor(log, compiler, contextProvider, roundTripperFactory, router, connectionProvider) {
|
|
20
|
+
constructor(log, compiler, contextProvider, roundTripperFactory, router, cronRegistry, connectionProvider, cronProvider) {
|
|
44
21
|
Object.defineProperty(this, "log", {
|
|
45
22
|
enumerable: true,
|
|
46
23
|
configurable: true,
|
|
@@ -71,18 +48,53 @@ class MemoryInterpreter {
|
|
|
71
48
|
writable: true,
|
|
72
49
|
value: router
|
|
73
50
|
});
|
|
51
|
+
Object.defineProperty(this, "cronRegistry", {
|
|
52
|
+
enumerable: true,
|
|
53
|
+
configurable: true,
|
|
54
|
+
writable: true,
|
|
55
|
+
value: cronRegistry
|
|
56
|
+
});
|
|
74
57
|
Object.defineProperty(this, "connectionProvider", {
|
|
75
58
|
enumerable: true,
|
|
76
59
|
configurable: true,
|
|
77
60
|
writable: true,
|
|
78
61
|
value: connectionProvider
|
|
79
62
|
});
|
|
63
|
+
Object.defineProperty(this, "cronProvider", {
|
|
64
|
+
enumerable: true,
|
|
65
|
+
configurable: true,
|
|
66
|
+
writable: true,
|
|
67
|
+
value: cronProvider
|
|
68
|
+
});
|
|
80
69
|
Object.defineProperty(this, "registeredWorkflows", {
|
|
81
70
|
enumerable: true,
|
|
82
71
|
configurable: true,
|
|
83
72
|
writable: true,
|
|
84
73
|
value: []
|
|
85
74
|
});
|
|
75
|
+
Object.defineProperty(this, "server", {
|
|
76
|
+
enumerable: true,
|
|
77
|
+
configurable: true,
|
|
78
|
+
writable: true,
|
|
79
|
+
value: void 0
|
|
80
|
+
});
|
|
81
|
+
Object.defineProperty(this, "shutdownServer", {
|
|
82
|
+
enumerable: true,
|
|
83
|
+
configurable: true,
|
|
84
|
+
writable: true,
|
|
85
|
+
value: void 0
|
|
86
|
+
});
|
|
87
|
+
Object.defineProperty(this, "isShuttingDown", {
|
|
88
|
+
enumerable: true,
|
|
89
|
+
configurable: true,
|
|
90
|
+
writable: true,
|
|
91
|
+
value: false
|
|
92
|
+
});
|
|
93
|
+
if (typeof this.log === 'undefined') {
|
|
94
|
+
// this captures the old way of instantiating the MemoryInterpreter and provides an
|
|
95
|
+
// error message back to the user to let them know they should use the new way.
|
|
96
|
+
throw new Error('MemoryInterpreter should not be instantiated directly. Use MemoryInterpreter.newInstance() instead.');
|
|
97
|
+
}
|
|
86
98
|
}
|
|
87
99
|
static async newInstance(options = {}) {
|
|
88
100
|
const log = options.logger || new ConsoleLogger_js_1.ConsoleLogger('debug');
|
|
@@ -93,12 +105,12 @@ class MemoryInterpreter {
|
|
|
93
105
|
if (options.contextProvider) {
|
|
94
106
|
// no need to set up a key-value provider if options.contextProvider is already
|
|
95
107
|
// initialised.
|
|
96
|
-
return new MemoryInterpreter(log, compiler, options.contextProvider, roundTripperFactory, express_1.default.Router(), platformapi_js_1.PlatformAPIClient.fromEnv());
|
|
108
|
+
return new MemoryInterpreter(log, compiler, options.contextProvider, roundTripperFactory, express_1.default.Router(), new Map(), platformapi_js_1.PlatformAPIClient.fromEnv(), cronapi_js_1.CronAPIClient.fromEnv());
|
|
97
109
|
}
|
|
98
110
|
const kvp = await (options.skipVersoriCredentials
|
|
99
111
|
? new MemoryKeyValueProvider_js_1.MemoryKeyValueProvider()
|
|
100
112
|
: NatsKeyValueProvider_js_1.NatsKeyValueProvider.fromEnv());
|
|
101
|
-
return new MemoryInterpreter(log, compiler, new ContextProvider_js_1.ContextProviderImpl(log, kvp), roundTripperFactory, express_1.default.Router(), platformapi_js_1.PlatformAPIClient.fromEnv());
|
|
113
|
+
return new MemoryInterpreter(log, compiler, new ContextProvider_js_1.ContextProviderImpl(log, kvp), roundTripperFactory, express_1.default.Router(), new Map(), platformapi_js_1.PlatformAPIClient.fromEnv(), cronapi_js_1.CronAPIClient.fromEnv());
|
|
102
114
|
}
|
|
103
115
|
register(workflow, options) {
|
|
104
116
|
const localAbortController = new AbortController();
|
|
@@ -115,6 +127,7 @@ class MemoryInterpreter {
|
|
|
115
127
|
contextProvider: this.contextProvider,
|
|
116
128
|
roundTripperFactory: this.roundTripperFactory,
|
|
117
129
|
router: this.router,
|
|
130
|
+
cronRegistry: this.cronRegistry,
|
|
118
131
|
connectionProvider: this.connectionProvider
|
|
119
132
|
};
|
|
120
133
|
const trigger$ = this.compiler.compileTrigger(compilerContext, workflow.trigger, combinedSignal);
|
|
@@ -132,7 +145,7 @@ class MemoryInterpreter {
|
|
|
132
145
|
return registration;
|
|
133
146
|
}
|
|
134
147
|
async start() {
|
|
135
|
-
const port =
|
|
148
|
+
const port = Deno.env.get('PORT') || 3000;
|
|
136
149
|
const app = (0, express_1.default)();
|
|
137
150
|
app.use(express_1.default.json()); // Add JSON body parser middleware
|
|
138
151
|
// Add health check route
|
|
@@ -143,12 +156,22 @@ class MemoryInterpreter {
|
|
|
143
156
|
app.use(this.router);
|
|
144
157
|
// Start all registered workflows
|
|
145
158
|
for (const registration of this.registeredWorkflows) {
|
|
146
|
-
|
|
147
|
-
registration.trigger$
|
|
159
|
+
Deno.addSignalListener('SIGINT', registration.sigintListener);
|
|
160
|
+
registration.subscription = registration.trigger$
|
|
148
161
|
.pipe((0, rxjs_1.tap)((ctx) => {
|
|
149
162
|
ctx.log.info('MemoryInterpreter.executionStarted', { data: ctx.data });
|
|
150
|
-
}), (0, rxjs_1.mergeMap)((ctx) => (0, rxjs_1.of)(ctx).pipe(registration.task$, (0, rxjs_1.catchError)((
|
|
151
|
-
ctx.log.error('MemoryInterpreter.executionError', { error });
|
|
163
|
+
}), (0, rxjs_1.mergeMap)((ctx) => (0, rxjs_1.of)(ctx).pipe(registration.task$, (0, rxjs_1.catchError)((err) => {
|
|
164
|
+
ctx.log.error('MemoryInterpreter.executionError', { error: err instanceof Error ? err.toString() : err });
|
|
165
|
+
try {
|
|
166
|
+
ctx.options.onError?.(ctx.withData(err));
|
|
167
|
+
}
|
|
168
|
+
catch (err) {
|
|
169
|
+
ctx.log.error('MemoryInterpreter.onErrorError: failed to call onError handler', { error: err instanceof Error ? err.toString() : err });
|
|
170
|
+
ctx.options.onError?.(ctx.withData({
|
|
171
|
+
message: 'Internal server error',
|
|
172
|
+
error: err instanceof Error ? err.toString() : err,
|
|
173
|
+
}));
|
|
174
|
+
}
|
|
152
175
|
return rxjs_1.EMPTY;
|
|
153
176
|
}))))
|
|
154
177
|
.subscribe({
|
|
@@ -158,21 +181,83 @@ class MemoryInterpreter {
|
|
|
158
181
|
durationMs,
|
|
159
182
|
data: ctx.data,
|
|
160
183
|
});
|
|
184
|
+
try {
|
|
185
|
+
ctx.options.onSuccess?.(ctx);
|
|
186
|
+
}
|
|
187
|
+
catch (err) {
|
|
188
|
+
ctx.log.error('MemoryInterpreter.onSuccessError: failed to call onSuccess handler', { error: err instanceof Error ? err.toString() : err });
|
|
189
|
+
ctx.options.onSuccess?.(ctx.withData({
|
|
190
|
+
message: 'Internal server error',
|
|
191
|
+
error: err instanceof Error ? err.toString() : err,
|
|
192
|
+
}));
|
|
193
|
+
}
|
|
161
194
|
this.contextProvider.destroy(ctx);
|
|
162
195
|
},
|
|
163
196
|
error: (err) => {
|
|
164
|
-
this.log.error('MemoryInterpreter.error', { error: err });
|
|
165
|
-
|
|
197
|
+
this.log.error('MemoryInterpreter.error', { error: err instanceof Error ? err.toString() : err });
|
|
198
|
+
Deno.removeSignalListener('SIGINT', registration.sigintListener);
|
|
166
199
|
},
|
|
167
200
|
complete: () => {
|
|
168
201
|
this.log.info('MemoryInterpreter.workflowCompleted');
|
|
169
|
-
|
|
202
|
+
Deno.removeSignalListener('SIGINT', registration.sigintListener);
|
|
170
203
|
},
|
|
171
204
|
});
|
|
205
|
+
registration.subscription.add(() => {
|
|
206
|
+
registration.subscription = undefined;
|
|
207
|
+
});
|
|
208
|
+
}
|
|
209
|
+
try {
|
|
210
|
+
this.cronProvider.updateCrons(this.cronRegistry);
|
|
172
211
|
}
|
|
173
|
-
|
|
212
|
+
catch (err) {
|
|
213
|
+
this.log.error('MemoryInterpreter.updateCronsError', { error: err instanceof Error ? err.toString() : err });
|
|
214
|
+
throw new Error('Unable to register scheduler tasks with central cron provider');
|
|
215
|
+
}
|
|
216
|
+
this.server = app.listen(port, () => {
|
|
174
217
|
this.log.info(`Express server listening on http://localhost:${port}`);
|
|
175
218
|
});
|
|
219
|
+
this.shutdownServer = () => {
|
|
220
|
+
if (this.isShuttingDown) {
|
|
221
|
+
return;
|
|
222
|
+
}
|
|
223
|
+
this.isShuttingDown = true;
|
|
224
|
+
this.log.info('Shutting down server');
|
|
225
|
+
// Close the server
|
|
226
|
+
if (this.server) {
|
|
227
|
+
this.server.close();
|
|
228
|
+
}
|
|
229
|
+
// Remove all signal listeners
|
|
230
|
+
for (const registration of this.registeredWorkflows) {
|
|
231
|
+
Deno.removeSignalListener('SIGINT', registration.sigintListener);
|
|
232
|
+
// Unsubscribe from all observables
|
|
233
|
+
if (registration.subscription) {
|
|
234
|
+
registration.subscription.unsubscribe();
|
|
235
|
+
}
|
|
236
|
+
// Abort all controllers
|
|
237
|
+
registration.localAbortController.abort();
|
|
238
|
+
}
|
|
239
|
+
// Remove the server shutdown listener
|
|
240
|
+
if (this.shutdownServer) {
|
|
241
|
+
Deno.removeSignalListener('SIGINT', this.shutdownServer);
|
|
242
|
+
}
|
|
243
|
+
};
|
|
244
|
+
Deno.addSignalListener('SIGINT', this.shutdownServer);
|
|
245
|
+
return new Promise((resolve) => {
|
|
246
|
+
if (this.server) {
|
|
247
|
+
this.server.on('close', () => {
|
|
248
|
+
this.log.info('Server closed');
|
|
249
|
+
resolve();
|
|
250
|
+
});
|
|
251
|
+
}
|
|
252
|
+
else {
|
|
253
|
+
resolve();
|
|
254
|
+
}
|
|
255
|
+
});
|
|
256
|
+
}
|
|
257
|
+
async stop() {
|
|
258
|
+
if (this.shutdownServer) {
|
|
259
|
+
this.shutdownServer();
|
|
260
|
+
}
|
|
176
261
|
}
|
|
177
262
|
}
|
|
178
263
|
exports.MemoryInterpreter = MemoryInterpreter;
|
|
@@ -14,6 +14,7 @@ export type CompilerContext = {
|
|
|
14
14
|
roundTripperFactory: RoundTripperFactory;
|
|
15
15
|
connectionProvider: ConnectionProvider;
|
|
16
16
|
router: Router;
|
|
17
|
+
cronRegistry: Map<string, string>;
|
|
17
18
|
};
|
|
18
19
|
export type CompilerFunc<In = any, Out = any, T extends Task<In, Out> = Task<In, Out>> = (ctx: CompilerContext, task: T) => OperatorFunction<In, Out>;
|
|
19
20
|
export declare class ObservableCompiler {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ObservableCompiler.d.ts","sourceRoot":"","sources":["../../../../src/src/interpreter/memory/ObservableCompiler.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,gBAAgB,EAAE,MAAM,MAAM,CAAC;AACpD,OAAO,EAAE,IAAI,EAAY,MAAM,mBAAmB,CAAC;AACnD,OAAO,EAAE,MAAM,EAAE,MAAM,uCAAuC,CAAC;AAO/D,OAAO,EAAE,uBAAuB,EAAE,YAAY,EAAE,eAAe,EAAE,MAAM,sBAAsB,CAAC;AAE9F,OAAO,EAAE,OAAO,EAAe,MAAM,sBAAsB,CAAC;AAG5D,OAAO,EAAE,eAAe,EAAE,MAAM,kCAAkC,CAAC;AACnE,OAAO,EAAE,WAAW,EAAE,MAAM,0BAA0B,CAAC;AAEvD,OAAO,EAAE,kBAAkB,EAAE,mBAAmB,EAAE,MAAM,yBAAyB,CAAC;AAClF,OAAO,EAAE,MAAM,EAAE,MAAM,SAAS,CAAC;AAEjC,MAAM,MAAM,eAAe,GAAG;IAC1B,QAAQ,EAAE,kBAAkB,CAAC;IAC7B,GAAG,EAAE,MAAM,CAAC;IACZ,eAAe,EAAE,eAAe,CAAC;IACjC,mBAAmB,EAAE,mBAAmB,CAAC;IACzC,kBAAkB,EAAE,kBAAkB,CAAC;IACvC,MAAM,EAAE,MAAM,CAAC;
|
|
1
|
+
{"version":3,"file":"ObservableCompiler.d.ts","sourceRoot":"","sources":["../../../../src/src/interpreter/memory/ObservableCompiler.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,gBAAgB,EAAE,MAAM,MAAM,CAAC;AACpD,OAAO,EAAE,IAAI,EAAY,MAAM,mBAAmB,CAAC;AACnD,OAAO,EAAE,MAAM,EAAE,MAAM,uCAAuC,CAAC;AAO/D,OAAO,EAAE,uBAAuB,EAAE,YAAY,EAAE,eAAe,EAAE,MAAM,sBAAsB,CAAC;AAE9F,OAAO,EAAE,OAAO,EAAe,MAAM,sBAAsB,CAAC;AAG5D,OAAO,EAAE,eAAe,EAAE,MAAM,kCAAkC,CAAC;AACnE,OAAO,EAAE,WAAW,EAAE,MAAM,0BAA0B,CAAC;AAEvD,OAAO,EAAE,kBAAkB,EAAE,mBAAmB,EAAE,MAAM,yBAAyB,CAAC;AAClF,OAAO,EAAE,MAAM,EAAE,MAAM,SAAS,CAAC;AAEjC,MAAM,MAAM,eAAe,GAAG;IAC1B,QAAQ,EAAE,kBAAkB,CAAC;IAC7B,GAAG,EAAE,MAAM,CAAC;IACZ,eAAe,EAAE,eAAe,CAAC;IACjC,mBAAmB,EAAE,mBAAmB,CAAC;IACzC,kBAAkB,EAAE,kBAAkB,CAAC;IACvC,MAAM,EAAE,MAAM,CAAC;IACf,YAAY,EAAE,GAAG,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;CACrC,CAAC;AAEF,MAAM,MAAM,YAAY,CAAC,EAAE,GAAG,GAAG,EAAE,GAAG,GAAG,GAAG,EAAE,CAAC,SAAS,IAAI,CAAC,EAAE,EAAE,GAAG,CAAC,GAAG,IAAI,CAAC,EAAE,EAAE,GAAG,CAAC,IAAI,CACrF,GAAG,EAAE,eAAe,EACpB,IAAI,EAAE,CAAC,KACN,gBAAgB,CAAC,EAAE,EAAE,GAAG,CAAC,CAAC;AAE/B,qBAAa,kBAAkB;IAC3B,OAAO,CAAC,aAAa,CAAkD;IACvE,OAAO,CAAC,gBAAgB,CAAgD;;IAgBxE,WAAW,CAAC,EAAE,GAAG,GAAG,EAAE,GAAG,GAAG,GAAG,EAAE,KAAK,GAAG,IAAI,EACzC,GAAG,EAAE,eAAe,EACpB,IAAI,EAAE,IAAI,CAAC,EAAE,EAAE,GAAG,CAAC,GACpB,uBAAuB,CAAC,EAAE,EAAE,GAAG,EAAE,KAAK,CAAC;IAe1C,cAAc,CAAC,GAAG,GAAG,GAAG,EAAE,CAAC,SAAS,OAAO,CAAC,GAAG,CAAC,GAAG,OAAO,CAAC,GAAG,CAAC,EAC3D,GAAG,EAAE,eAAe,EACpB,OAAO,EAAE,CAAC,EACV,MAAM,EAAE,WAAW,GACpB,UAAU,CAAC,WAAW,CAAC,GAAG,EAAE,IAAI,CAAC,CAAC;IAerC,YAAY,CAAC,EAAE,EAAE,GAAG,EAAE,CAAC,SAAS,IAAI,CAAC,EAAE,EAAE,GAAG,CAAC,EAAE,QAAQ,EAAE,YAAY,CAAC,EAAE,EAAE,GAAG,EAAE,CAAC,CAAC;IAKjF,eAAe,CAAC,GAAG,EAAE,CAAC,SAAS,OAAO,CAAC,GAAG,CAAC,EAAE,QAAQ,EAAE,eAAe,CAAC,GAAG,EAAE,CAAC,CAAC;CAIjF"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"schedule.d.ts","sourceRoot":"","sources":["../../../../../src/src/interpreter/memory/compilers/schedule.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,YAAY,EAAE,eAAe,EAAE,MAAM,0CAA0C,CAAC;AAEzF,OAAO,EAAE,eAAe,EAAE,MAAM,YAAY,CAAC;
|
|
1
|
+
{"version":3,"file":"schedule.d.ts","sourceRoot":"","sources":["../../../../../src/src/interpreter/memory/compilers/schedule.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,YAAY,EAAE,eAAe,EAAE,MAAM,0CAA0C,CAAC;AAEzF,OAAO,EAAE,eAAe,EAAE,MAAM,YAAY,CAAC;AAuF7C,eAAO,MAAM,gBAAgB,EAAE,eAAe,CAAC,YAAY,EAAE,eAAe,CAG3E,CAAC"}
|
|
@@ -1,15 +1,18 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.scheduleCompiler = void 0;
|
|
4
|
-
const cron_1 = require("cron");
|
|
5
4
|
const rxjs_1 = require("rxjs");
|
|
6
5
|
const ScheduleTrigger_js_1 = require("../../../dsl/triggers/ScheduleTrigger.js");
|
|
7
6
|
function compileSchedule(ctx, trigger, signal) {
|
|
8
7
|
return new rxjs_1.Observable((subscriber) => {
|
|
8
|
+
// Add HTTP endpoint for manual triggering
|
|
9
|
+
if (!ctx.router) {
|
|
10
|
+
throw new Error('Router not available in compiler context');
|
|
11
|
+
}
|
|
9
12
|
const client = ctx.connectionProvider;
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
+
ctx.cronRegistry.set(trigger.id, trigger.schedule);
|
|
14
|
+
ctx.router.post(`/cron/${trigger.id}`, async (req, res) => {
|
|
15
|
+
try {
|
|
13
16
|
if (trigger.activationPredicate === undefined) {
|
|
14
17
|
const executionCtx = ctx.contextProvider.create({}, undefined);
|
|
15
18
|
try {
|
|
@@ -18,6 +21,7 @@ function compileSchedule(ctx, trigger, signal) {
|
|
|
18
21
|
catch (error) {
|
|
19
22
|
executionCtx.log.error('execution error inside schedule', { error });
|
|
20
23
|
}
|
|
24
|
+
res.status(200).json({ status: 'triggered', executionId: executionCtx.executionId });
|
|
21
25
|
return;
|
|
22
26
|
}
|
|
23
27
|
const activations = await client.listActivations();
|
|
@@ -30,10 +34,11 @@ function compileSchedule(ctx, trigger, signal) {
|
|
|
30
34
|
catch (error) {
|
|
31
35
|
executionCtx.log.error('execution error inside schedule', { error });
|
|
32
36
|
}
|
|
37
|
+
res.status(200).json({ status: 'triggered', executionId: executionCtx.executionId });
|
|
33
38
|
return;
|
|
34
39
|
}
|
|
35
40
|
activations.forEach((activation) => {
|
|
36
|
-
const executionCtx = ctx.contextProvider.create({}, activation);
|
|
41
|
+
const executionCtx = ctx.contextProvider.create({}, { activation });
|
|
37
42
|
executionCtx.log.info('no activations found, continuing');
|
|
38
43
|
try {
|
|
39
44
|
subscriber.next(executionCtx);
|
|
@@ -42,31 +47,21 @@ function compileSchedule(ctx, trigger, signal) {
|
|
|
42
47
|
executionCtx.log.error('execution error inside schedule', { error });
|
|
43
48
|
}
|
|
44
49
|
});
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
}
|
|
50
|
-
|
|
51
|
-
subscriber.complete();
|
|
52
|
-
},
|
|
53
|
-
errorHandler: (error) => {
|
|
54
|
-
ctx.log.error('schedule execution error', { error });
|
|
55
|
-
subscriber.error(error);
|
|
56
|
-
},
|
|
57
|
-
start: true,
|
|
50
|
+
res.status(200).json({ status: 'triggered' });
|
|
51
|
+
}
|
|
52
|
+
catch (error) {
|
|
53
|
+
executionCtx.log.error('execution error inside schedule', { error });
|
|
54
|
+
res.status(500).json({ error: 'Failed to trigger schedule' });
|
|
55
|
+
}
|
|
58
56
|
});
|
|
59
57
|
function cleanup() {
|
|
60
|
-
ctx.log.debug('
|
|
61
|
-
|
|
58
|
+
ctx.log.debug('scheduler trigger stopped');
|
|
59
|
+
subscriber.complete();
|
|
62
60
|
}
|
|
63
61
|
signal.addEventListener('abort', cleanup, { once: true });
|
|
64
62
|
return () => {
|
|
65
63
|
signal.removeEventListener('abort', cleanup);
|
|
66
|
-
ctx.log.debug('
|
|
67
|
-
// call job.stop() directly rather than using cleanup since cleanup is called when the
|
|
68
|
-
// signal is aborted and we don't want duplicate logs when the unsubscription happens.
|
|
69
|
-
job.stop();
|
|
64
|
+
ctx.log.debug('scheduler execution unsubscribed');
|
|
70
65
|
};
|
|
71
66
|
});
|
|
72
67
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"webhook.d.ts","sourceRoot":"","sources":["../../../../../src/src/interpreter/memory/compilers/webhook.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"webhook.d.ts","sourceRoot":"","sources":["../../../../../src/src/interpreter/memory/compilers/webhook.ts"],"names":[],"mappings":"AAOA,OAAO,EAAE,WAAW,EAAE,cAAc,EAAE,MAAM,yCAAyC,CAAC;AAEtF,OAAO,EAAE,eAAe,EAAE,MAAM,YAAY,CAAC;AAgD7C,eAAO,MAAM,eAAe,EAAE,eAAe,CAAC,WAAW,EAAE,cAAc,CA+LxE,CAAC"}
|
|
@@ -1,74 +1,175 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
2
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
6
|
exports.webhookCompiler = void 0;
|
|
4
7
|
// In src/interpreter/memory/compilers/webhook.ts
|
|
8
|
+
const cors_1 = __importDefault(require("cors"));
|
|
5
9
|
const rxjs_1 = require("rxjs");
|
|
10
|
+
const promises_1 = require("node:stream/promises");
|
|
6
11
|
const WebhookTrigger_js_1 = require("../../../dsl/triggers/WebhookTrigger.js");
|
|
12
|
+
const DEFAULT_SYNC_ON_SUCCESS = (ctx) => new Response(JSON.stringify(ctx.data), {
|
|
13
|
+
status: 200,
|
|
14
|
+
headers: {
|
|
15
|
+
'Content-Type': 'application/json',
|
|
16
|
+
'X-Execution-Id': ctx.executionId,
|
|
17
|
+
},
|
|
18
|
+
});
|
|
19
|
+
const DEFAULT_SYNC_ON_ERROR = (ctx) => new Response(JSON.stringify({ message: 'Internal server error', error: ctx.data }), {
|
|
20
|
+
status: 500,
|
|
21
|
+
headers: {
|
|
22
|
+
'Content-Type': 'application/json',
|
|
23
|
+
'X-Execution-Id': ctx.executionId,
|
|
24
|
+
},
|
|
25
|
+
});
|
|
26
|
+
const DEFAULT_ASYNC_ON_SUCCESS = (ctx) => new Response(JSON.stringify({
|
|
27
|
+
status: 'accepted',
|
|
28
|
+
executionId: ctx.executionId,
|
|
29
|
+
}), {
|
|
30
|
+
status: 202,
|
|
31
|
+
headers: {
|
|
32
|
+
'Content-Type': 'application/json',
|
|
33
|
+
'X-Execution-Id': ctx.executionId,
|
|
34
|
+
},
|
|
35
|
+
});
|
|
36
|
+
const DEFAULT_ASYNC_ON_ERROR = (ctx) => new Response(JSON.stringify({
|
|
37
|
+
message: 'Internal server error',
|
|
38
|
+
executionId: ctx.executionId,
|
|
39
|
+
}), {
|
|
40
|
+
status: 500,
|
|
41
|
+
headers: {
|
|
42
|
+
'Content-Type': 'application/json',
|
|
43
|
+
'X-Execution-Id': ctx.executionId,
|
|
44
|
+
},
|
|
45
|
+
});
|
|
7
46
|
exports.webhookCompiler = {
|
|
8
47
|
ctor: WebhookTrigger_js_1.WebhookTrigger,
|
|
9
48
|
compile: (ctx, trigger, signal) => {
|
|
49
|
+
const { response: { mode = 'async', } = {}, cors: corsOptions, } = trigger.options;
|
|
50
|
+
const isSync = mode === 'sync';
|
|
51
|
+
const isAsync = mode === 'async';
|
|
52
|
+
if (!isSync && !isAsync) {
|
|
53
|
+
throw new Error('Invalid response mode, must be either "sync" or "async"');
|
|
54
|
+
}
|
|
55
|
+
let onSuccess = isSync ? DEFAULT_SYNC_ON_SUCCESS : DEFAULT_ASYNC_ON_SUCCESS;
|
|
56
|
+
let onError = isSync ? DEFAULT_SYNC_ON_ERROR : DEFAULT_ASYNC_ON_ERROR;
|
|
57
|
+
if (trigger.options.response?.onSuccess) {
|
|
58
|
+
onSuccess = trigger.options.response.onSuccess;
|
|
59
|
+
}
|
|
60
|
+
if (trigger.options.response?.onError) {
|
|
61
|
+
onError = trigger.options.response.onError;
|
|
62
|
+
}
|
|
63
|
+
const ctxOptionsFn = (res) => ({
|
|
64
|
+
onSuccess: (ctx) => {
|
|
65
|
+
if (isSync) {
|
|
66
|
+
sendResponse(res, onSuccess(ctx));
|
|
67
|
+
}
|
|
68
|
+
},
|
|
69
|
+
onError: (ctx) => {
|
|
70
|
+
if (isSync) {
|
|
71
|
+
sendResponse(res, onError(ctx));
|
|
72
|
+
}
|
|
73
|
+
},
|
|
74
|
+
});
|
|
10
75
|
return new rxjs_1.Observable((subscriber) => {
|
|
11
76
|
if (!ctx.router) {
|
|
12
77
|
throw new Error('Router not available in compiler context');
|
|
13
78
|
}
|
|
14
79
|
// add the webhook endpoint to the router
|
|
15
80
|
ctx.log.info('webhook endpoint added:', { trigger });
|
|
81
|
+
if (corsOptions) {
|
|
82
|
+
if (typeof corsOptions === 'boolean') {
|
|
83
|
+
ctx.router.use((0, cors_1.default)());
|
|
84
|
+
}
|
|
85
|
+
else {
|
|
86
|
+
ctx.router.use((0, cors_1.default)(corsOptions));
|
|
87
|
+
}
|
|
88
|
+
}
|
|
16
89
|
// endpoint for sans user because I'm not quite sure how the dynamic routing works
|
|
17
90
|
ctx.router.post(`/${trigger.id}`, (req, res) => {
|
|
18
|
-
const executionCtx = ctx.contextProvider.create(req.body,
|
|
91
|
+
const executionCtx = ctx.contextProvider.create(req.body, ctxOptionsFn(res));
|
|
19
92
|
try {
|
|
20
93
|
subscriber.next(executionCtx);
|
|
21
|
-
|
|
94
|
+
if (isAsync) {
|
|
95
|
+
sendResponse(res, onSuccess(executionCtx));
|
|
96
|
+
}
|
|
22
97
|
}
|
|
23
98
|
catch (error) {
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
99
|
+
executionCtx.log.error('webhook execution error', {
|
|
100
|
+
error: JSON.stringify(error),
|
|
101
|
+
});
|
|
102
|
+
if (isAsync) {
|
|
103
|
+
sendResponse(res, onError(executionCtx.withData(error)));
|
|
104
|
+
}
|
|
27
105
|
}
|
|
28
106
|
});
|
|
29
107
|
// this endpoint will trigger the workflow for each activation given by the external user ID
|
|
30
108
|
ctx.router.post(`/${trigger.id}/users/:userId`, async (req, res) => {
|
|
31
|
-
const userId = req.params.userId
|
|
32
|
-
if (!userId) {
|
|
33
|
-
res.status(400).json({ status: 'error', message: 'User ID is required' });
|
|
34
|
-
return;
|
|
35
|
-
}
|
|
109
|
+
const userId = req.params.userId;
|
|
36
110
|
const activations = await ctx.connectionProvider.getUserActivations(userId);
|
|
37
111
|
if (!activations || activations.length === 0) {
|
|
38
|
-
res.status(404).json({
|
|
112
|
+
res.status(404).json({
|
|
113
|
+
status: 'error',
|
|
114
|
+
message: `No activations found for user: ${userId}`,
|
|
115
|
+
});
|
|
39
116
|
return;
|
|
40
117
|
}
|
|
118
|
+
const executionCtx = ctx.contextProvider.create(req.body, ctxOptionsFn(res));
|
|
119
|
+
const errors = [];
|
|
41
120
|
activations.forEach((activation) => {
|
|
42
|
-
const
|
|
121
|
+
const activationCtx = executionCtx.withActivation(activation);
|
|
43
122
|
try {
|
|
44
|
-
subscriber.next(
|
|
123
|
+
subscriber.next(activationCtx);
|
|
45
124
|
}
|
|
46
125
|
catch (error) {
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
126
|
+
activationCtx.log.error('webhook execution error', {
|
|
127
|
+
error: JSON.stringify(error),
|
|
128
|
+
});
|
|
129
|
+
errors.push({
|
|
130
|
+
activationId: activation.id,
|
|
131
|
+
error,
|
|
132
|
+
});
|
|
50
133
|
}
|
|
51
134
|
});
|
|
52
|
-
|
|
135
|
+
if (isAsync) {
|
|
136
|
+
if (errors.length === 0) {
|
|
137
|
+
sendResponse(res, onSuccess(executionCtx));
|
|
138
|
+
}
|
|
139
|
+
else {
|
|
140
|
+
sendResponse(res, onError(executionCtx.withData(errors)));
|
|
141
|
+
}
|
|
142
|
+
}
|
|
53
143
|
});
|
|
54
144
|
// this endpoint will trigger the workflow only for the activation given by its ID
|
|
55
145
|
ctx.router.post(`/${trigger.id}/activations/:activationId`, async (req, res) => {
|
|
56
|
-
const activationId = req.params.activationId
|
|
146
|
+
const activationId = req.params.activationId;
|
|
57
147
|
const activation = await ctx.connectionProvider.getActivation(activationId);
|
|
58
148
|
if (!activation) {
|
|
59
149
|
// TODO report back actual errors
|
|
60
|
-
res.status(404).json({
|
|
150
|
+
res.status(404).json({
|
|
151
|
+
status: 'error',
|
|
152
|
+
message: `No activation found for ID: ${activationId}`,
|
|
153
|
+
});
|
|
61
154
|
return;
|
|
62
155
|
}
|
|
63
|
-
const
|
|
156
|
+
const activationCtx = ctx.contextProvider.create(req.body, {
|
|
157
|
+
...ctxOptionsFn(res),
|
|
158
|
+
activation,
|
|
159
|
+
});
|
|
64
160
|
try {
|
|
65
|
-
subscriber.next(
|
|
66
|
-
|
|
161
|
+
subscriber.next(activationCtx);
|
|
162
|
+
if (isAsync) {
|
|
163
|
+
sendResponse(res, onSuccess(activationCtx));
|
|
164
|
+
}
|
|
67
165
|
}
|
|
68
166
|
catch (error) {
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
167
|
+
activationCtx.log.error('webhook execution error', {
|
|
168
|
+
error: JSON.stringify(error),
|
|
169
|
+
});
|
|
170
|
+
if (isAsync) {
|
|
171
|
+
sendResponse(res, onError(activationCtx.withData(error)));
|
|
172
|
+
}
|
|
72
173
|
}
|
|
73
174
|
});
|
|
74
175
|
function cleanup() {
|
|
@@ -83,3 +184,12 @@ exports.webhookCompiler = {
|
|
|
83
184
|
});
|
|
84
185
|
},
|
|
85
186
|
};
|
|
187
|
+
function sendResponse(res, response) {
|
|
188
|
+
res.status(response.status);
|
|
189
|
+
response.headers.forEach((value, key) => {
|
|
190
|
+
res.setHeader(key, value);
|
|
191
|
+
});
|
|
192
|
+
if (response.body) {
|
|
193
|
+
(0, promises_1.pipeline)(response.body, res);
|
|
194
|
+
}
|
|
195
|
+
}
|
|
@@ -19,7 +19,6 @@ export declare class NatsKeyValueProvider implements KeyValueProvider, AsyncDisp
|
|
|
19
19
|
private constructor();
|
|
20
20
|
static newInstance(opts?: Partial<NatsKeyValueProviderOptions>): Promise<NatsKeyValueProvider>;
|
|
21
21
|
static fromEnv(): Promise<NatsKeyValueProvider>;
|
|
22
|
-
[Symbol.asyncDispose](): PromiseLike<void>;
|
|
23
22
|
kv(options: KVOptions): KeyValue;
|
|
24
23
|
destroy(options: DestroyOptions): Promise<void>;
|
|
25
24
|
private subjectPrefix;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"NatsKeyValueProvider.d.ts","sourceRoot":"","sources":["../../../../src/src/kv/nats/NatsKeyValueProvider.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"NatsKeyValueProvider.d.ts","sourceRoot":"","sources":["../../../../src/src/kv/nats/NatsKeyValueProvider.ts"],"names":[],"mappings":"AAEA,OAAO,EAA+B,UAAU,EAAE,MAAM,+DAA+D,CAAC;AACxH,OAAO,EACH,cAAc,EAEd,QAAQ,EACR,gBAAgB,EAChB,SAAS,EACZ,MAAM,gBAAgB,CAAC;AA4CxB,MAAM,MAAM,2BAA2B,GAAG;IACtC,cAAc,EAAE,MAAM,CAAC;IACvB,SAAS,EAAE,MAAM,CAAC;IAClB,WAAW,EAAE,MAAM,CAAC;IACpB,IAAI,EAAE;QACF,GAAG,EAAE,MAAM,CAAC;QACZ,SAAS,CAAC,EAAE,MAAM,CAAC;QACnB,GAAG,CAAC,EAAE,UAAU,CAAC;KACpB,CAAC;CACL,CAAC;AAuBF,qBAAa,oBAAqB,YAAW,gBAAgB,EAAE,eAAe;IAEtE,OAAO,CAAC,QAAQ,CAAC,GAAG;IACpB,OAAO,CAAC,QAAQ,CAAC,UAAU;IAC3B,OAAO,CAAC,QAAQ,CAAC,cAAc;IAC/B,OAAO,CAAC,QAAQ,CAAC,gBAAgB;IACjC,OAAO,CAAC,QAAQ,CAAC,IAAI;IALzB,OAAO;WAQM,WAAW,CACpB,IAAI,GAAE,OAAO,CAAC,2BAA2B,CAAM,GAChD,OAAO,CAAC,oBAAoB,CAAC;IA0BhC,MAAM,CAAC,OAAO,IAAI,OAAO,CAAC,oBAAoB,CAAC;IAQ/C,EAAE,CAAC,OAAO,EAAE,SAAS,GAAG,QAAQ;IAqB1B,OAAO,CAAC,OAAO,EAAE,cAAc,GAAG,OAAO,CAAC,IAAI,CAAC;IAuBrD,OAAO,CAAC,aAAa;CAYxB"}
|