@versori/run 0.2.14 → 0.2.16
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/context/AsyncWorkflow.d.ts +14 -0
- package/esm/src/context/AsyncWorkflow.d.ts.map +1 -0
- package/esm/src/context/AsyncWorkflow.js +89 -0
- package/esm/src/context/Context.d.ts +13 -1
- package/esm/src/context/Context.d.ts.map +1 -1
- package/esm/src/context/Context.js +44 -4
- package/esm/src/context/ContextProvider.d.ts +3 -1
- package/esm/src/context/ContextProvider.d.ts.map +1 -1
- package/esm/src/context/ContextProvider.js +9 -2
- package/esm/src/dsl/http/versori/constants.d.ts +1 -0
- package/esm/src/dsl/http/versori/constants.d.ts.map +1 -1
- package/esm/src/dsl/http/versori/constants.js +1 -0
- package/esm/src/dsl/tasks/HttpTask.d.ts +3 -0
- package/esm/src/dsl/tasks/HttpTask.d.ts.map +1 -1
- package/esm/src/dsl/tasks/HttpTask.js +3 -0
- package/esm/src/dsl/triggers/DurableTrigger.d.ts +18 -0
- package/esm/src/dsl/triggers/DurableTrigger.d.ts.map +1 -0
- package/esm/src/dsl/triggers/DurableTrigger.js +36 -0
- package/esm/src/dsl/triggers/mod.d.ts +1 -0
- package/esm/src/dsl/triggers/mod.d.ts.map +1 -1
- package/esm/src/dsl/triggers/mod.js +1 -0
- package/esm/src/interpreter/durable/DurableInterpreter.d.ts +52 -0
- package/esm/src/interpreter/durable/DurableInterpreter.d.ts.map +1 -0
- package/esm/src/interpreter/durable/DurableInterpreter.js +433 -0
- package/esm/src/interpreter/durable/ExecutionError.d.ts +6 -0
- package/esm/src/interpreter/durable/ExecutionError.d.ts.map +1 -0
- package/esm/src/interpreter/durable/ExecutionError.js +13 -0
- package/esm/src/interpreter/durable/ObservableCompiler.d.ts +35 -0
- package/esm/src/interpreter/durable/ObservableCompiler.d.ts.map +1 -0
- package/esm/src/interpreter/durable/ObservableCompiler.js +69 -0
- package/esm/src/interpreter/durable/Queue.d.ts +69 -0
- package/esm/src/interpreter/durable/Queue.d.ts.map +1 -0
- package/esm/src/interpreter/durable/Queue.js +149 -0
- package/esm/src/interpreter/durable/compilers/background.d.ts +4 -0
- package/esm/src/interpreter/durable/compilers/background.d.ts.map +1 -0
- package/esm/src/interpreter/durable/compilers/background.js +22 -0
- package/esm/src/interpreter/durable/compilers/catch.d.ts +4 -0
- package/esm/src/interpreter/durable/compilers/catch.d.ts.map +1 -0
- package/esm/src/interpreter/durable/compilers/catch.js +36 -0
- package/esm/src/interpreter/durable/compilers/chain.d.ts +3 -0
- package/esm/src/interpreter/durable/compilers/chain.d.ts.map +1 -0
- package/esm/src/interpreter/durable/compilers/chain.js +9 -0
- package/esm/src/interpreter/durable/compilers/durableworkflow.d.ts +8 -0
- package/esm/src/interpreter/durable/compilers/durableworkflow.d.ts.map +1 -0
- package/esm/src/interpreter/durable/compilers/durableworkflow.js +69 -0
- package/esm/src/interpreter/durable/compilers/fn.d.ts +4 -0
- package/esm/src/interpreter/durable/compilers/fn.d.ts.map +1 -0
- package/esm/src/interpreter/durable/compilers/fn.js +22 -0
- package/esm/src/interpreter/durable/compilers/http.d.ts +4 -0
- package/esm/src/interpreter/durable/compilers/http.d.ts.map +1 -0
- package/esm/src/interpreter/durable/compilers/http.js +44 -0
- package/esm/src/interpreter/durable/compilers/mod.d.ts +2 -0
- package/esm/src/interpreter/durable/compilers/mod.d.ts.map +1 -0
- package/esm/src/interpreter/durable/compilers/mod.js +1 -0
- package/esm/src/interpreter/durable/compilers/parallel.d.ts +4 -0
- package/esm/src/interpreter/durable/compilers/parallel.d.ts.map +1 -0
- package/esm/src/interpreter/durable/compilers/parallel.js +19 -0
- package/esm/src/interpreter/durable/compilers/schedule.d.ts +4 -0
- package/esm/src/interpreter/durable/compilers/schedule.d.ts.map +1 -0
- package/esm/src/interpreter/durable/compilers/schedule.js +94 -0
- package/esm/src/interpreter/durable/compilers/serial.d.ts +4 -0
- package/esm/src/interpreter/durable/compilers/serial.d.ts.map +1 -0
- package/esm/src/interpreter/durable/compilers/serial.js +16 -0
- package/esm/src/interpreter/durable/compilers/types.d.ts +15 -0
- package/esm/src/interpreter/durable/compilers/types.d.ts.map +1 -0
- package/esm/src/interpreter/durable/compilers/types.js +1 -0
- package/esm/src/interpreter/durable/compilers/unpack.d.ts +4 -0
- package/esm/src/interpreter/durable/compilers/unpack.d.ts.map +1 -0
- package/esm/src/interpreter/durable/compilers/unpack.js +22 -0
- package/esm/src/interpreter/durable/compilers/webhook.d.ts +4 -0
- package/esm/src/interpreter/durable/compilers/webhook.d.ts.map +1 -0
- package/esm/src/interpreter/durable/compilers/webhook.js +248 -0
- package/esm/src/interpreter/durable/mod.d.ts +5 -0
- package/esm/src/interpreter/durable/mod.d.ts.map +1 -0
- package/esm/src/interpreter/durable/mod.js +4 -0
- package/esm/src/interpreter/mod.d.ts +1 -0
- package/esm/src/interpreter/mod.d.ts.map +1 -1
- package/esm/src/interpreter/mod.js +1 -0
- package/package.json +1 -1
- package/script/src/context/AsyncWorkflow.d.ts +14 -0
- package/script/src/context/AsyncWorkflow.d.ts.map +1 -0
- package/script/src/context/AsyncWorkflow.js +93 -0
- package/script/src/context/Context.d.ts +13 -1
- package/script/src/context/Context.d.ts.map +1 -1
- package/script/src/context/Context.js +44 -4
- package/script/src/context/ContextProvider.d.ts +3 -1
- package/script/src/context/ContextProvider.d.ts.map +1 -1
- package/script/src/context/ContextProvider.js +9 -2
- package/script/src/dsl/http/versori/constants.d.ts +1 -0
- package/script/src/dsl/http/versori/constants.d.ts.map +1 -1
- package/script/src/dsl/http/versori/constants.js +2 -1
- package/script/src/dsl/tasks/HttpTask.d.ts +3 -0
- package/script/src/dsl/tasks/HttpTask.d.ts.map +1 -1
- package/script/src/dsl/tasks/HttpTask.js +3 -0
- package/script/src/dsl/triggers/DurableTrigger.d.ts +18 -0
- package/script/src/dsl/triggers/DurableTrigger.d.ts.map +1 -0
- package/script/src/dsl/triggers/DurableTrigger.js +41 -0
- package/script/src/dsl/triggers/mod.d.ts +1 -0
- package/script/src/dsl/triggers/mod.d.ts.map +1 -1
- package/script/src/dsl/triggers/mod.js +3 -1
- package/script/src/interpreter/durable/DurableInterpreter.d.ts +52 -0
- package/script/src/interpreter/durable/DurableInterpreter.d.ts.map +1 -0
- package/script/src/interpreter/durable/DurableInterpreter.js +440 -0
- package/script/src/interpreter/durable/ExecutionError.d.ts +6 -0
- package/script/src/interpreter/durable/ExecutionError.d.ts.map +1 -0
- package/script/src/interpreter/durable/ExecutionError.js +17 -0
- package/script/src/interpreter/durable/ObservableCompiler.d.ts +35 -0
- package/script/src/interpreter/durable/ObservableCompiler.d.ts.map +1 -0
- package/script/src/interpreter/durable/ObservableCompiler.js +73 -0
- package/script/src/interpreter/durable/Queue.d.ts +69 -0
- package/script/src/interpreter/durable/Queue.d.ts.map +1 -0
- package/script/src/interpreter/durable/Queue.js +154 -0
- package/script/src/interpreter/durable/compilers/background.d.ts +4 -0
- package/script/src/interpreter/durable/compilers/background.d.ts.map +1 -0
- package/script/src/interpreter/durable/compilers/background.js +25 -0
- package/script/src/interpreter/durable/compilers/catch.d.ts +4 -0
- package/script/src/interpreter/durable/compilers/catch.d.ts.map +1 -0
- package/script/src/interpreter/durable/compilers/catch.js +39 -0
- package/script/src/interpreter/durable/compilers/chain.d.ts +3 -0
- package/script/src/interpreter/durable/compilers/chain.d.ts.map +1 -0
- package/script/src/interpreter/durable/compilers/chain.js +12 -0
- package/script/src/interpreter/durable/compilers/durableworkflow.d.ts +8 -0
- package/script/src/interpreter/durable/compilers/durableworkflow.d.ts.map +1 -0
- package/script/src/interpreter/durable/compilers/durableworkflow.js +73 -0
- package/script/src/interpreter/durable/compilers/fn.d.ts +4 -0
- package/script/src/interpreter/durable/compilers/fn.d.ts.map +1 -0
- package/script/src/interpreter/durable/compilers/fn.js +25 -0
- package/script/src/interpreter/durable/compilers/http.d.ts +4 -0
- package/script/src/interpreter/durable/compilers/http.d.ts.map +1 -0
- package/script/src/interpreter/durable/compilers/http.js +47 -0
- package/script/src/interpreter/durable/compilers/mod.d.ts +2 -0
- package/script/src/interpreter/durable/compilers/mod.d.ts.map +1 -0
- package/script/src/interpreter/durable/compilers/mod.js +2 -0
- package/script/src/interpreter/durable/compilers/parallel.d.ts +4 -0
- package/script/src/interpreter/durable/compilers/parallel.d.ts.map +1 -0
- package/script/src/interpreter/durable/compilers/parallel.js +22 -0
- package/script/src/interpreter/durable/compilers/schedule.d.ts +4 -0
- package/script/src/interpreter/durable/compilers/schedule.d.ts.map +1 -0
- package/script/src/interpreter/durable/compilers/schedule.js +97 -0
- package/script/src/interpreter/durable/compilers/serial.d.ts +4 -0
- package/script/src/interpreter/durable/compilers/serial.d.ts.map +1 -0
- package/script/src/interpreter/durable/compilers/serial.js +19 -0
- package/script/src/interpreter/durable/compilers/types.d.ts +15 -0
- package/script/src/interpreter/durable/compilers/types.d.ts.map +1 -0
- package/script/src/interpreter/durable/compilers/types.js +2 -0
- package/script/src/interpreter/durable/compilers/unpack.d.ts +4 -0
- package/script/src/interpreter/durable/compilers/unpack.d.ts.map +1 -0
- package/script/src/interpreter/durable/compilers/unpack.js +25 -0
- package/script/src/interpreter/durable/compilers/webhook.d.ts +4 -0
- package/script/src/interpreter/durable/compilers/webhook.d.ts.map +1 -0
- package/script/src/interpreter/durable/compilers/webhook.js +254 -0
- package/script/src/interpreter/durable/mod.d.ts +5 -0
- package/script/src/interpreter/durable/mod.d.ts.map +1 -0
- package/script/src/interpreter/durable/mod.js +20 -0
- package/script/src/interpreter/mod.d.ts +1 -0
- package/script/src/interpreter/mod.d.ts.map +1 -1
- package/script/src/interpreter/mod.js +14 -0
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../../../../src/src/interpreter/durable/compilers/types.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,gBAAgB,EAAE,MAAM,MAAM,CAAC;AACpD,OAAO,EAAE,WAAW,EAAE,MAAM,6BAA6B,CAAC;AAC1D,OAAO,EAAE,IAAI,EAAE,MAAM,sBAAsB,CAAC;AAC5C,OAAO,EAAE,OAAO,EAAE,MAAM,yBAAyB,CAAC;AAClD,OAAO,EAAE,sBAAsB,EAAE,MAAM,0BAA0B,CAAC;AAElE,MAAM,WAAW,YAAY,CAAC,EAAE,EAAE,GAAG,EAAE,CAAC,SAAS,IAAI,CAAC,EAAE,EAAE,GAAG,CAAC;IAC1D,IAAI,EAAE,KAAK,GAAG,IAAI,EAAE,GAAG,EAAE,KAAK,CAAC,CAAC;IAChC,OAAO,EAAE,CAAC,KAAK,GAAG,IAAI,EAAE,GAAG,EAAE,sBAAsB,EAAE,IAAI,EAAE,CAAC,KAAK,uBAAuB,CAAC,EAAE,EAAE,GAAG,EAAE,KAAK,CAAC,CAAC;CAC5G;AAED,MAAM,WAAW,eAAe,CAAC,GAAG,EAAE,CAAC,SAAS,OAAO,CAAC,GAAG,CAAC;IACxD,OAAO,EAAE,CAAC,GAAG,EAAE,sBAAsB,EAAE,OAAO,EAAE,CAAC,EAAE,MAAM,EAAE,WAAW,KAAK,UAAU,CAAC,WAAW,CAAC,GAAG,EAAE,IAAI,CAAC,CAAC,CAAC;IAC9G,IAAI,EAAE,KAAK,GAAG,IAAI,EAAE,GAAG,EAAE,KAAK,CAAC,CAAC;CACnC;AAED,MAAM,MAAM,uBAAuB,CAAC,EAAE,EAAE,GAAG,EAAE,KAAK,GAAG,IAAI,IAAI,gBAAgB,CAAC,WAAW,CAAC,EAAE,EAAE,KAAK,CAAC,EAAE,WAAW,CAAC,GAAG,EAAE,KAAK,CAAC,CAAC,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"unpack.d.ts","sourceRoot":"","sources":["../../../../../src/src/interpreter/durable/compilers/unpack.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,UAAU,EAAE,MAAM,kCAAkC,CAAC;AAE9D,OAAO,EAA2B,YAAY,EAAE,MAAM,YAAY,CAAC;AA6BnE,eAAO,MAAM,cAAc,EAAE,YAAY,CAAC,GAAG,EAAE,GAAG,EAAE,UAAU,CAAC,GAAG,EAAE,GAAG,EAAE,GAAG,CAAC,CAG5E,CAAC"}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.unpackCompiler = void 0;
|
|
4
|
+
const rxjs_1 = require("rxjs");
|
|
5
|
+
const UnpackTask_js_1 = require("../../../dsl/tasks/UnpackTask.js");
|
|
6
|
+
function ensureArray(data) {
|
|
7
|
+
if (Array.isArray(data)) {
|
|
8
|
+
return data;
|
|
9
|
+
}
|
|
10
|
+
return [data];
|
|
11
|
+
}
|
|
12
|
+
function compileUnpack(ctx, task) {
|
|
13
|
+
const baseOperator = ctx.compiler.compileTask(ctx, task._base);
|
|
14
|
+
const mapper = task._mapper;
|
|
15
|
+
return (src) => src.pipe((0, rxjs_1.tap)({
|
|
16
|
+
complete: () => ctx.log.debug('unpack.complete')
|
|
17
|
+
}), baseOperator, (0, rxjs_1.map)((ctx) => {
|
|
18
|
+
const result = mapper?.(ctx.data) ?? ctx.data;
|
|
19
|
+
return ctx.withData(ensureArray(result));
|
|
20
|
+
}));
|
|
21
|
+
}
|
|
22
|
+
exports.unpackCompiler = {
|
|
23
|
+
ctor: UnpackTask_js_1.UnpackTask,
|
|
24
|
+
compile: compileUnpack,
|
|
25
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"webhook.d.ts","sourceRoot":"","sources":["../../../../../src/src/interpreter/durable/compilers/webhook.ts"],"names":[],"mappings":"AAOA,OAAO,EAAE,WAAW,EAAE,cAAc,EAAE,MAAM,yCAAyC,CAAC;AACtF,OAAO,EAAE,eAAe,EAAE,MAAM,YAAY,CAAC;AAmD7C,eAAO,MAAM,eAAe,EAAE,eAAe,CAAC,WAAW,EAAE,cAAc,CAuRxE,CAAC"}
|
|
@@ -0,0 +1,254 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.webhookCompiler = void 0;
|
|
7
|
+
const cors_1 = __importDefault(require("cors"));
|
|
8
|
+
const promises_1 = require("node:stream/promises");
|
|
9
|
+
const rxjs_1 = require("rxjs");
|
|
10
|
+
const WebhookTrigger_js_1 = require("../../../dsl/triggers/WebhookTrigger.js");
|
|
11
|
+
const webhookmiddleware_js_1 = require("../../../dsl/http/versori/webhookmiddleware.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
|
+
});
|
|
46
|
+
exports.webhookCompiler = {
|
|
47
|
+
ctor: WebhookTrigger_js_1.WebhookTrigger,
|
|
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
|
+
});
|
|
75
|
+
return new rxjs_1.Observable((subscriber) => {
|
|
76
|
+
if (!ctx.webhookRouter) {
|
|
77
|
+
throw new Error('Router not available in compiler context');
|
|
78
|
+
}
|
|
79
|
+
// add the webhook endpoint to the router
|
|
80
|
+
ctx.log.info('webhook endpoint added:', { trigger });
|
|
81
|
+
if (corsOptions) {
|
|
82
|
+
if (typeof corsOptions === 'boolean') {
|
|
83
|
+
ctx.webhookRouter.use((0, cors_1.default)());
|
|
84
|
+
}
|
|
85
|
+
else {
|
|
86
|
+
ctx.webhookRouter.use((0, cors_1.default)(corsOptions));
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
// endpoint for sans user because I'm not quite sure how the dynamic routing works
|
|
90
|
+
ctx.webhookRouter.post(`/${trigger.id}`, (0, webhookmiddleware_js_1.createStaticWebhookMiddleware)({
|
|
91
|
+
id: trigger.id,
|
|
92
|
+
connName: trigger.options.connection,
|
|
93
|
+
credentials: ctx.roundTripperFactory.credentials(),
|
|
94
|
+
cnxProvider: ctx.connectionProvider,
|
|
95
|
+
cfgReader: ctx.configReader,
|
|
96
|
+
log: ctx.log,
|
|
97
|
+
}), async (req, res) => {
|
|
98
|
+
await ctx.tracer.startActiveSpan(`webhook-${trigger.id}`, async (span) => {
|
|
99
|
+
span.setAttribute('task.id', trigger.id);
|
|
100
|
+
span.setAttribute('task.type', 'webhook');
|
|
101
|
+
let executionCtx = ctx.contextProvider.create(req.body, ctxOptionsFn(res));
|
|
102
|
+
const staticActivation = res.locals.activation;
|
|
103
|
+
if (staticActivation) {
|
|
104
|
+
executionCtx = executionCtx.withActivation(staticActivation);
|
|
105
|
+
}
|
|
106
|
+
span.setAttribute('execution.id', executionCtx.executionId);
|
|
107
|
+
try {
|
|
108
|
+
subscriber.next(executionCtx);
|
|
109
|
+
if (isAsync) {
|
|
110
|
+
sendResponse(res, onSuccess(executionCtx));
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
catch (error) {
|
|
114
|
+
executionCtx.log.error('webhook execution error', {
|
|
115
|
+
error: JSON.stringify(error),
|
|
116
|
+
});
|
|
117
|
+
if (isAsync) {
|
|
118
|
+
sendResponse(res, onError(executionCtx.withData(error)));
|
|
119
|
+
}
|
|
120
|
+
}
|
|
121
|
+
finally {
|
|
122
|
+
span.end();
|
|
123
|
+
}
|
|
124
|
+
});
|
|
125
|
+
});
|
|
126
|
+
// this endpoint will trigger the workflow for each activation given by the external user ID
|
|
127
|
+
ctx.webhookRouter.post(`/${trigger.id}/users/:userId`, (0, webhookmiddleware_js_1.createUserIdDynamicWebhookMiddleware)({
|
|
128
|
+
id: trigger.id,
|
|
129
|
+
connName: trigger.options.connection,
|
|
130
|
+
credentials: ctx.roundTripperFactory.credentials(),
|
|
131
|
+
cnxProvider: ctx.connectionProvider,
|
|
132
|
+
cfgReader: ctx.configReader,
|
|
133
|
+
log: ctx.log,
|
|
134
|
+
}), async (req, res) => {
|
|
135
|
+
await ctx.tracer.startActiveSpan(`webhook-${trigger.id}`, async (span) => {
|
|
136
|
+
span.setAttribute('task.id', trigger.id);
|
|
137
|
+
span.setAttribute('task.type', 'webhook');
|
|
138
|
+
span.setAttribute('user.id', req.params.userId);
|
|
139
|
+
const userId = req.params.userId;
|
|
140
|
+
const activation = res.locals.activation;
|
|
141
|
+
const activations = [activation];
|
|
142
|
+
// Right now we only support a user having one activation
|
|
143
|
+
// so this will need changing when we support multiple activations per user
|
|
144
|
+
// as will the middleware
|
|
145
|
+
if (!activations || activations.length === 0) {
|
|
146
|
+
res.status(404).json({
|
|
147
|
+
status: 'error',
|
|
148
|
+
message: `No activations found for user: ${userId}`,
|
|
149
|
+
});
|
|
150
|
+
span.setAttribute('error.message', `No activations found for user: ${userId}`);
|
|
151
|
+
span.setAttribute('http.status_code', '404');
|
|
152
|
+
span.end();
|
|
153
|
+
return;
|
|
154
|
+
}
|
|
155
|
+
const executionCtx = ctx.contextProvider.create(req.body, ctxOptionsFn(res));
|
|
156
|
+
span.setAttribute('execution.id', executionCtx.executionId);
|
|
157
|
+
const errors = [];
|
|
158
|
+
activations.forEach((activation) => {
|
|
159
|
+
const activationCtx = executionCtx.withActivation(activation);
|
|
160
|
+
try {
|
|
161
|
+
subscriber.next(activationCtx);
|
|
162
|
+
}
|
|
163
|
+
catch (error) {
|
|
164
|
+
activationCtx.log.error('webhook execution error', {
|
|
165
|
+
error: JSON.stringify(error),
|
|
166
|
+
});
|
|
167
|
+
errors.push({
|
|
168
|
+
activationId: activation.id,
|
|
169
|
+
error,
|
|
170
|
+
});
|
|
171
|
+
}
|
|
172
|
+
});
|
|
173
|
+
if (isAsync) {
|
|
174
|
+
if (errors.length === 0) {
|
|
175
|
+
sendResponse(res, onSuccess(executionCtx));
|
|
176
|
+
}
|
|
177
|
+
else {
|
|
178
|
+
sendResponse(res, onError(executionCtx.withData(errors)));
|
|
179
|
+
}
|
|
180
|
+
}
|
|
181
|
+
span.end();
|
|
182
|
+
});
|
|
183
|
+
});
|
|
184
|
+
// this endpoint will trigger the workflow only for the activation given by its ID
|
|
185
|
+
ctx.webhookRouter.post(`/${trigger.id}/activations/:activationId`, (0, webhookmiddleware_js_1.createActIdDynamicWebhookMiddleware)({
|
|
186
|
+
id: trigger.id,
|
|
187
|
+
connName: trigger.options.connection,
|
|
188
|
+
credentials: ctx.roundTripperFactory.credentials(),
|
|
189
|
+
cnxProvider: ctx.connectionProvider,
|
|
190
|
+
cfgReader: ctx.configReader,
|
|
191
|
+
log: ctx.log,
|
|
192
|
+
}), async (req, res) => {
|
|
193
|
+
await ctx.tracer.startActiveSpan(`webhook-${trigger.id}`, async (span) => {
|
|
194
|
+
span.setAttribute('task.id', trigger.id);
|
|
195
|
+
span.setAttribute('task.type', 'webhook');
|
|
196
|
+
span.setAttribute('activation.id', req.params.activationId);
|
|
197
|
+
const activation = res.locals.activation;
|
|
198
|
+
const activationId = activation.id || req.params.activationId;
|
|
199
|
+
if (!activation) {
|
|
200
|
+
// TODO report back actual errors
|
|
201
|
+
res.status(404).json({
|
|
202
|
+
status: 'error',
|
|
203
|
+
message: `No activation found for ID: ${activationId}`,
|
|
204
|
+
});
|
|
205
|
+
span.setAttribute('error.message', `No activation found for ID: ${activationId}`);
|
|
206
|
+
span.setAttribute('http.status_code', '404');
|
|
207
|
+
span.end();
|
|
208
|
+
return;
|
|
209
|
+
}
|
|
210
|
+
const activationCtx = ctx.contextProvider.create(req.body, {
|
|
211
|
+
...ctxOptionsFn(res),
|
|
212
|
+
activation,
|
|
213
|
+
});
|
|
214
|
+
span.setAttribute('execution.id', activationCtx.executionId);
|
|
215
|
+
try {
|
|
216
|
+
subscriber.next(activationCtx);
|
|
217
|
+
if (isAsync) {
|
|
218
|
+
sendResponse(res, onSuccess(activationCtx));
|
|
219
|
+
}
|
|
220
|
+
}
|
|
221
|
+
catch (error) {
|
|
222
|
+
activationCtx.log.error('webhook execution error', {
|
|
223
|
+
error: JSON.stringify(error),
|
|
224
|
+
});
|
|
225
|
+
if (isAsync) {
|
|
226
|
+
sendResponse(res, onError(activationCtx.withData(error)));
|
|
227
|
+
}
|
|
228
|
+
}
|
|
229
|
+
finally {
|
|
230
|
+
span.end();
|
|
231
|
+
}
|
|
232
|
+
});
|
|
233
|
+
});
|
|
234
|
+
function cleanup() {
|
|
235
|
+
ctx.log.debug('webhook trigger stopped');
|
|
236
|
+
subscriber.complete();
|
|
237
|
+
}
|
|
238
|
+
signal.addEventListener('abort', cleanup, { once: true });
|
|
239
|
+
return () => {
|
|
240
|
+
signal.removeEventListener('abort', cleanup);
|
|
241
|
+
ctx.log.debug('webhook execution unsubscribed');
|
|
242
|
+
};
|
|
243
|
+
});
|
|
244
|
+
},
|
|
245
|
+
};
|
|
246
|
+
function sendResponse(res, response) {
|
|
247
|
+
res.status(response.status);
|
|
248
|
+
response.headers.forEach((value, key) => {
|
|
249
|
+
res.setHeader(key, value);
|
|
250
|
+
});
|
|
251
|
+
if (response.body) {
|
|
252
|
+
(0, promises_1.pipeline)(response.body, res);
|
|
253
|
+
}
|
|
254
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"mod.d.ts","sourceRoot":"","sources":["../../../../src/src/interpreter/durable/mod.ts"],"names":[],"mappings":"AAAA,cAAc,yBAAyB,CAAC;AACxC,cAAc,yBAAyB,CAAC;AACxC,cAAc,qBAAqB,CAAC;AACpC,cAAc,oBAAoB,CAAC"}
|
|
@@ -0,0 +1,20 @@
|
|
|
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 __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
+
};
|
|
16
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
+
__exportStar(require("./DurableInterpreter.js"), exports);
|
|
18
|
+
__exportStar(require("./ObservableCompiler.js"), exports);
|
|
19
|
+
__exportStar(require("./ExecutionError.js"), exports);
|
|
20
|
+
__exportStar(require("./compilers/mod.js"), exports);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"mod.d.ts","sourceRoot":"","sources":["../../../src/src/interpreter/mod.ts"],"names":[],"mappings":"AAAA,cAAc,iBAAiB,CAAC"}
|
|
1
|
+
{"version":3,"file":"mod.d.ts","sourceRoot":"","sources":["../../../src/src/interpreter/mod.ts"],"names":[],"mappings":"AAAA,cAAc,iBAAiB,CAAC;AAChC,OAAO,KAAK,OAAO,MAAM,kBAAkB,CAAC"}
|
|
@@ -10,8 +10,22 @@ var __createBinding = (this && this.__createBinding) || (Object.create ? (functi
|
|
|
10
10
|
if (k2 === undefined) k2 = k;
|
|
11
11
|
o[k2] = m[k];
|
|
12
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
|
+
});
|
|
13
18
|
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
19
|
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
20
|
};
|
|
21
|
+
var __importStar = (this && this.__importStar) || function (mod) {
|
|
22
|
+
if (mod && mod.__esModule) return mod;
|
|
23
|
+
var result = {};
|
|
24
|
+
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
25
|
+
__setModuleDefault(result, mod);
|
|
26
|
+
return result;
|
|
27
|
+
};
|
|
16
28
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
29
|
+
exports.durable = void 0;
|
|
17
30
|
__exportStar(require("./memory/mod.js"), exports);
|
|
31
|
+
exports.durable = __importStar(require("./durable/mod.js"));
|