@versori/run 0.7.0-alpha.3 → 0.7.0-alpha.6
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/mod.d.ts +1 -1
- package/esm/mod.d.ts.map +1 -1
- package/esm/mod.js +1 -1
- package/esm/src/connection/VanillaConnectionFactory.d.ts +16 -0
- package/esm/src/connection/VanillaConnectionFactory.d.ts.map +1 -0
- package/esm/src/connection/VanillaConnectionFactory.js +23 -0
- package/esm/src/context/ActivationImpl.d.ts +2 -1
- package/esm/src/context/ActivationImpl.d.ts.map +1 -1
- package/esm/src/context/Context.d.ts +4 -2
- package/esm/src/context/Context.d.ts.map +1 -1
- package/esm/src/context/ContextProvider.d.ts +6 -6
- package/esm/src/context/ContextProvider.d.ts.map +1 -1
- package/esm/src/context/VanillaContext.d.ts +60 -0
- package/esm/src/context/VanillaContext.d.ts.map +1 -0
- package/esm/src/context/VanillaContext.js +296 -0
- package/esm/src/dsl/http/mod.d.ts +1 -1
- package/esm/src/dsl/http/mod.d.ts.map +1 -1
- package/esm/src/dsl/http/types.d.ts +19 -134
- package/esm/src/dsl/http/types.d.ts.map +1 -1
- package/esm/src/dsl/http/versori/configloader.d.ts.map +1 -1
- package/esm/src/dsl/http/versori/configloader.js +3 -0
- package/esm/src/dsl/tasks/HttpTask.d.ts +5 -5
- package/esm/src/dsl/tasks/HttpTask.d.ts.map +1 -1
- package/esm/src/dsl/triggers/ScheduleTrigger.d.ts +2 -2
- package/esm/src/dsl/triggers/ScheduleTrigger.d.ts.map +1 -1
- package/esm/src/interpreter/memory/MemoryInterpreter.d.ts +2 -2
- package/esm/src/interpreter/memory/MemoryInterpreter.d.ts.map +1 -1
- package/esm/src/interpreter/memory/compilers/schedule.d.ts.map +1 -1
- 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/esm/src/interpreter/vanilla/ExecutionError.d.ts +27 -0
- package/esm/src/interpreter/vanilla/ExecutionError.d.ts.map +1 -0
- package/esm/src/interpreter/vanilla/ExecutionError.js +48 -0
- package/esm/src/interpreter/vanilla/ObservableCompiler.d.ts +38 -0
- package/esm/src/interpreter/vanilla/ObservableCompiler.d.ts.map +1 -0
- package/esm/src/interpreter/vanilla/ObservableCompiler.js +95 -0
- package/esm/src/interpreter/vanilla/Queue.d.ts +72 -0
- package/esm/src/interpreter/vanilla/Queue.d.ts.map +1 -0
- package/esm/src/interpreter/vanilla/Queue.js +176 -0
- package/esm/src/interpreter/vanilla/VanillaInterpreter.d.ts +95 -0
- package/esm/src/interpreter/vanilla/VanillaInterpreter.d.ts.map +1 -0
- package/esm/src/interpreter/vanilla/VanillaInterpreter.js +428 -0
- package/esm/src/interpreter/vanilla/compilers/background.d.ts +4 -0
- package/esm/src/interpreter/vanilla/compilers/background.d.ts.map +1 -0
- package/esm/src/interpreter/vanilla/compilers/background.js +34 -0
- package/esm/src/interpreter/vanilla/compilers/catch.d.ts +4 -0
- package/esm/src/interpreter/vanilla/compilers/catch.d.ts.map +1 -0
- package/esm/src/interpreter/vanilla/compilers/catch.js +75 -0
- package/esm/src/interpreter/vanilla/compilers/chain.d.ts +3 -0
- package/esm/src/interpreter/vanilla/compilers/chain.d.ts.map +1 -0
- package/esm/src/interpreter/vanilla/compilers/chain.js +21 -0
- package/esm/src/interpreter/vanilla/compilers/durableworkflow.d.ts +8 -0
- package/esm/src/interpreter/vanilla/compilers/durableworkflow.d.ts.map +1 -0
- package/esm/src/interpreter/vanilla/compilers/durableworkflow.js +90 -0
- package/esm/src/interpreter/vanilla/compilers/fn.d.ts +4 -0
- package/esm/src/interpreter/vanilla/compilers/fn.d.ts.map +1 -0
- package/esm/src/interpreter/vanilla/compilers/fn.js +34 -0
- package/esm/src/interpreter/vanilla/compilers/http.d.ts +4 -0
- package/esm/src/interpreter/vanilla/compilers/http.d.ts.map +1 -0
- package/esm/src/interpreter/vanilla/compilers/http.js +54 -0
- package/esm/src/interpreter/vanilla/compilers/mod.d.ts +2 -0
- package/esm/src/interpreter/vanilla/compilers/mod.d.ts.map +1 -0
- package/esm/src/interpreter/vanilla/compilers/mod.js +13 -0
- package/esm/src/interpreter/vanilla/compilers/parallel.d.ts +4 -0
- package/esm/src/interpreter/vanilla/compilers/parallel.d.ts.map +1 -0
- package/esm/src/interpreter/vanilla/compilers/parallel.js +31 -0
- package/esm/src/interpreter/vanilla/compilers/schedule.d.ts +4 -0
- package/esm/src/interpreter/vanilla/compilers/schedule.d.ts.map +1 -0
- package/esm/src/interpreter/vanilla/compilers/schedule.js +76 -0
- package/esm/src/interpreter/vanilla/compilers/serial.d.ts +4 -0
- package/esm/src/interpreter/vanilla/compilers/serial.d.ts.map +1 -0
- package/esm/src/interpreter/vanilla/compilers/serial.js +28 -0
- package/esm/src/interpreter/vanilla/compilers/types.d.ts +15 -0
- package/esm/src/interpreter/vanilla/compilers/types.d.ts.map +1 -0
- package/esm/src/interpreter/vanilla/compilers/types.js +13 -0
- package/esm/src/interpreter/vanilla/compilers/unpack.d.ts +4 -0
- package/esm/src/interpreter/vanilla/compilers/unpack.d.ts.map +1 -0
- package/esm/src/interpreter/vanilla/compilers/unpack.js +34 -0
- package/esm/src/interpreter/vanilla/compilers/webhook.d.ts +4 -0
- package/esm/src/interpreter/vanilla/compilers/webhook.d.ts.map +1 -0
- package/esm/src/interpreter/vanilla/compilers/webhook.js +259 -0
- package/esm/src/interpreter/vanilla/mod.d.ts +3 -0
- package/esm/src/interpreter/vanilla/mod.d.ts.map +1 -0
- package/esm/src/interpreter/vanilla/mod.js +14 -0
- package/esm/src/issues/Issues.d.ts +1 -18
- package/esm/src/issues/Issues.d.ts.map +1 -1
- package/package.json +1 -1
- package/script/mod.d.ts +1 -1
- package/script/mod.d.ts.map +1 -1
- package/script/mod.js +2 -1
- package/script/src/connection/VanillaConnectionFactory.d.ts +16 -0
- package/script/src/connection/VanillaConnectionFactory.d.ts.map +1 -0
- package/script/src/connection/VanillaConnectionFactory.js +28 -0
- package/script/src/context/ActivationImpl.d.ts +2 -1
- package/script/src/context/ActivationImpl.d.ts.map +1 -1
- package/script/src/context/Context.d.ts +4 -2
- package/script/src/context/Context.d.ts.map +1 -1
- package/script/src/context/ContextProvider.d.ts +6 -6
- package/script/src/context/ContextProvider.d.ts.map +1 -1
- package/script/src/context/VanillaContext.d.ts +60 -0
- package/script/src/context/VanillaContext.d.ts.map +1 -0
- package/script/src/context/VanillaContext.js +302 -0
- package/script/src/dsl/http/mod.d.ts +1 -1
- package/script/src/dsl/http/mod.d.ts.map +1 -1
- package/script/src/dsl/http/types.d.ts +19 -134
- package/script/src/dsl/http/types.d.ts.map +1 -1
- package/script/src/dsl/http/versori/configloader.d.ts.map +1 -1
- package/script/src/dsl/http/versori/configloader.js +3 -0
- package/script/src/dsl/tasks/HttpTask.d.ts +5 -5
- package/script/src/dsl/tasks/HttpTask.d.ts.map +1 -1
- package/script/src/dsl/triggers/ScheduleTrigger.d.ts +2 -2
- package/script/src/dsl/triggers/ScheduleTrigger.d.ts.map +1 -1
- package/script/src/interpreter/memory/MemoryInterpreter.d.ts +2 -2
- package/script/src/interpreter/memory/MemoryInterpreter.d.ts.map +1 -1
- package/script/src/interpreter/memory/compilers/schedule.d.ts.map +1 -1
- 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 +2 -1
- package/script/src/interpreter/vanilla/ExecutionError.d.ts +27 -0
- package/script/src/interpreter/vanilla/ExecutionError.d.ts.map +1 -0
- package/script/src/interpreter/vanilla/ExecutionError.js +52 -0
- package/script/src/interpreter/vanilla/ObservableCompiler.d.ts +38 -0
- package/script/src/interpreter/vanilla/ObservableCompiler.d.ts.map +1 -0
- package/script/src/interpreter/vanilla/ObservableCompiler.js +99 -0
- package/script/src/interpreter/vanilla/Queue.d.ts +72 -0
- package/script/src/interpreter/vanilla/Queue.d.ts.map +1 -0
- package/script/src/interpreter/vanilla/Queue.js +181 -0
- package/script/src/interpreter/vanilla/VanillaInterpreter.d.ts +95 -0
- package/script/src/interpreter/vanilla/VanillaInterpreter.d.ts.map +1 -0
- package/script/src/interpreter/vanilla/VanillaInterpreter.js +435 -0
- package/script/src/interpreter/vanilla/compilers/background.d.ts +4 -0
- package/script/src/interpreter/vanilla/compilers/background.d.ts.map +1 -0
- package/script/src/interpreter/vanilla/compilers/background.js +37 -0
- package/script/src/interpreter/vanilla/compilers/catch.d.ts +4 -0
- package/script/src/interpreter/vanilla/compilers/catch.d.ts.map +1 -0
- package/script/src/interpreter/vanilla/compilers/catch.js +78 -0
- package/script/src/interpreter/vanilla/compilers/chain.d.ts +3 -0
- package/script/src/interpreter/vanilla/compilers/chain.d.ts.map +1 -0
- package/script/src/interpreter/vanilla/compilers/chain.js +24 -0
- package/script/src/interpreter/vanilla/compilers/durableworkflow.d.ts +8 -0
- package/script/src/interpreter/vanilla/compilers/durableworkflow.d.ts.map +1 -0
- package/script/src/interpreter/vanilla/compilers/durableworkflow.js +94 -0
- package/script/src/interpreter/vanilla/compilers/fn.d.ts +4 -0
- package/script/src/interpreter/vanilla/compilers/fn.d.ts.map +1 -0
- package/script/src/interpreter/vanilla/compilers/fn.js +37 -0
- package/script/src/interpreter/vanilla/compilers/http.d.ts +4 -0
- package/script/src/interpreter/vanilla/compilers/http.d.ts.map +1 -0
- package/script/src/interpreter/vanilla/compilers/http.js +57 -0
- package/script/src/interpreter/vanilla/compilers/mod.d.ts +2 -0
- package/script/src/interpreter/vanilla/compilers/mod.d.ts.map +1 -0
- package/script/src/interpreter/vanilla/compilers/mod.js +14 -0
- package/script/src/interpreter/vanilla/compilers/parallel.d.ts +4 -0
- package/script/src/interpreter/vanilla/compilers/parallel.d.ts.map +1 -0
- package/script/src/interpreter/vanilla/compilers/parallel.js +34 -0
- package/script/src/interpreter/vanilla/compilers/schedule.d.ts +4 -0
- package/script/src/interpreter/vanilla/compilers/schedule.d.ts.map +1 -0
- package/script/src/interpreter/vanilla/compilers/schedule.js +79 -0
- package/script/src/interpreter/vanilla/compilers/serial.d.ts +4 -0
- package/script/src/interpreter/vanilla/compilers/serial.d.ts.map +1 -0
- package/script/src/interpreter/vanilla/compilers/serial.js +31 -0
- package/script/src/interpreter/vanilla/compilers/types.d.ts +15 -0
- package/script/src/interpreter/vanilla/compilers/types.d.ts.map +1 -0
- package/script/src/interpreter/vanilla/compilers/types.js +14 -0
- package/script/src/interpreter/vanilla/compilers/unpack.d.ts +4 -0
- package/script/src/interpreter/vanilla/compilers/unpack.d.ts.map +1 -0
- package/script/src/interpreter/vanilla/compilers/unpack.js +37 -0
- package/script/src/interpreter/vanilla/compilers/webhook.d.ts +4 -0
- package/script/src/interpreter/vanilla/compilers/webhook.d.ts.map +1 -0
- package/script/src/interpreter/vanilla/compilers/webhook.js +265 -0
- package/script/src/interpreter/vanilla/mod.d.ts +3 -0
- package/script/src/interpreter/vanilla/mod.d.ts.map +1 -0
- package/script/src/interpreter/vanilla/mod.js +30 -0
- package/script/src/issues/Issues.d.ts +1 -18
- package/script/src/issues/Issues.d.ts.map +1 -1
|
@@ -0,0 +1,265 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/*
|
|
3
|
+
* Copyright (c) 2025 Versori Group Inc
|
|
4
|
+
*
|
|
5
|
+
* Use of this software is governed by the Business Source License 1.1
|
|
6
|
+
* included in the LICENSE file at the root of this repository.
|
|
7
|
+
*
|
|
8
|
+
* Change Date: 2029-01-01
|
|
9
|
+
* Change License: Apache License, Version 2.0
|
|
10
|
+
*
|
|
11
|
+
* As of the Change Date, in accordance with the Business Source License,
|
|
12
|
+
* use of this software will be governed by the Apache License, Version 2.0.
|
|
13
|
+
*/
|
|
14
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
15
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
16
|
+
};
|
|
17
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
18
|
+
exports.webhookCompiler = void 0;
|
|
19
|
+
const cors_1 = __importDefault(require("cors"));
|
|
20
|
+
const express_1 = __importDefault(require("express"));
|
|
21
|
+
const promises_1 = require("node:stream/promises");
|
|
22
|
+
const rxjs_1 = require("rxjs");
|
|
23
|
+
const WebhookTrigger_js_1 = require("../../../dsl/triggers/WebhookTrigger.js");
|
|
24
|
+
const ObservableCompiler_js_1 = require("../ObservableCompiler.js");
|
|
25
|
+
const express_xml_bodyparser_1 = __importDefault(require("express-xml-bodyparser"));
|
|
26
|
+
const xml2jsDefaults = {
|
|
27
|
+
explicitArray: false,
|
|
28
|
+
normalize: false,
|
|
29
|
+
normalizeTags: false,
|
|
30
|
+
trim: true,
|
|
31
|
+
};
|
|
32
|
+
const vanillaWebhookMiddleware = () => {
|
|
33
|
+
return async (_, res, next) => {
|
|
34
|
+
res.locals.activation = ObservableCompiler_js_1.VanillaActivation;
|
|
35
|
+
next();
|
|
36
|
+
};
|
|
37
|
+
};
|
|
38
|
+
const DEFAULT_SYNC_ON_SUCCESS = (ctx) => new Response(JSON.stringify(ctx.data), {
|
|
39
|
+
status: 200,
|
|
40
|
+
headers: {
|
|
41
|
+
'Content-Type': 'application/json',
|
|
42
|
+
'X-Execution-Id': ctx.executionId,
|
|
43
|
+
},
|
|
44
|
+
});
|
|
45
|
+
const DEFAULT_SYNC_ON_ERROR = (ctx) => new Response(JSON.stringify({ message: 'Internal server error', error: ctx.data }), {
|
|
46
|
+
status: 500,
|
|
47
|
+
headers: {
|
|
48
|
+
'Content-Type': 'application/json',
|
|
49
|
+
'X-Execution-Id': ctx.executionId,
|
|
50
|
+
},
|
|
51
|
+
});
|
|
52
|
+
const DEFAULT_ASYNC_ON_SUCCESS = (ctx) => new Response(JSON.stringify({
|
|
53
|
+
status: 'accepted',
|
|
54
|
+
executionId: ctx.executionId,
|
|
55
|
+
}), {
|
|
56
|
+
status: 202,
|
|
57
|
+
headers: {
|
|
58
|
+
'Content-Type': 'application/json',
|
|
59
|
+
'X-Execution-Id': ctx.executionId,
|
|
60
|
+
},
|
|
61
|
+
});
|
|
62
|
+
const DEFAULT_ASYNC_ON_ERROR = (ctx) => new Response(JSON.stringify({
|
|
63
|
+
message: 'Internal server error',
|
|
64
|
+
executionId: ctx.executionId,
|
|
65
|
+
}), {
|
|
66
|
+
status: 500,
|
|
67
|
+
headers: {
|
|
68
|
+
'Content-Type': 'application/json',
|
|
69
|
+
'X-Execution-Id': ctx.executionId,
|
|
70
|
+
},
|
|
71
|
+
});
|
|
72
|
+
exports.webhookCompiler = {
|
|
73
|
+
ctor: WebhookTrigger_js_1.WebhookTrigger,
|
|
74
|
+
compile: (ctx, trigger, signal) => {
|
|
75
|
+
const { response: { mode = 'async' } = {}, cors: corsOptions } = trigger.options;
|
|
76
|
+
const isSync = mode === 'sync';
|
|
77
|
+
const isAsync = mode === 'async';
|
|
78
|
+
if (!isSync && !isAsync) {
|
|
79
|
+
throw new Error('Invalid response mode, must be either "sync" or "async"');
|
|
80
|
+
}
|
|
81
|
+
const method = trigger.options.method || 'post';
|
|
82
|
+
const validMethods = ['get', 'post', 'put', 'delete', 'patch', 'options', 'head'];
|
|
83
|
+
if (method !== method.toLowerCase()) {
|
|
84
|
+
throw new Error(`HTTP method must be in lowercase: ${method} on webhook ${trigger.id}`);
|
|
85
|
+
}
|
|
86
|
+
if (!validMethods.includes(method)) {
|
|
87
|
+
throw new Error(`Unsupported HTTP method: ${method} on webhook ${trigger.id}. Must be one of: ${validMethods.join(', ')}`);
|
|
88
|
+
}
|
|
89
|
+
let onSuccess = isSync ? DEFAULT_SYNC_ON_SUCCESS : DEFAULT_ASYNC_ON_SUCCESS;
|
|
90
|
+
let onError = isSync ? DEFAULT_SYNC_ON_ERROR : DEFAULT_ASYNC_ON_ERROR;
|
|
91
|
+
if (trigger.options.response?.onSuccess) {
|
|
92
|
+
onSuccess = trigger.options.response.onSuccess;
|
|
93
|
+
}
|
|
94
|
+
if (trigger.options.response?.onError) {
|
|
95
|
+
onError = trigger.options.response.onError;
|
|
96
|
+
}
|
|
97
|
+
const ctxOptionsFn = (req, res) => ({
|
|
98
|
+
onSuccess: (ctx) => {
|
|
99
|
+
if (isSync) {
|
|
100
|
+
sendResponse(res, onSuccess(ctx));
|
|
101
|
+
}
|
|
102
|
+
},
|
|
103
|
+
onError: (ctx) => {
|
|
104
|
+
if (isSync) {
|
|
105
|
+
sendResponse(res, onError(ctx));
|
|
106
|
+
}
|
|
107
|
+
},
|
|
108
|
+
request: req,
|
|
109
|
+
});
|
|
110
|
+
if (!trigger.options.request?.rawBody) {
|
|
111
|
+
ctx.webhookRouter.use(express_1.default.json({ limit: '50mb' }));
|
|
112
|
+
ctx.webhookRouter.use((0, express_xml_bodyparser_1.default)(xml2jsDefaults));
|
|
113
|
+
}
|
|
114
|
+
else {
|
|
115
|
+
ctx.webhookRouter.use(express_1.default.raw({ type: '*/*', limit: '50mb' }));
|
|
116
|
+
}
|
|
117
|
+
return new rxjs_1.Observable((subscriber) => {
|
|
118
|
+
if (!ctx.webhookRouter) {
|
|
119
|
+
throw new Error('Router not available in compiler context');
|
|
120
|
+
}
|
|
121
|
+
// add the webhook endpoint to the router
|
|
122
|
+
ctx.log.info('webhook endpoint added:', { trigger });
|
|
123
|
+
if (corsOptions) {
|
|
124
|
+
if (typeof corsOptions === 'boolean') {
|
|
125
|
+
ctx.webhookRouter.use((0, cors_1.default)());
|
|
126
|
+
}
|
|
127
|
+
else {
|
|
128
|
+
ctx.webhookRouter.use((0, cors_1.default)(corsOptions));
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
// endpoint for sans user because I'm not quite sure how the dynamic routing works
|
|
132
|
+
ctx.webhookRouter[method](`/${trigger.id}`, vanillaWebhookMiddleware(), async (req, res) => {
|
|
133
|
+
await ctx.tracer.startActiveSpan(`webhook-${trigger.id}`, (span) => {
|
|
134
|
+
span.setAttribute('task.id', trigger.id);
|
|
135
|
+
span.setAttribute('task.type', 'webhook');
|
|
136
|
+
const staticActivation = res.locals.activation;
|
|
137
|
+
const executionCtx = ctx.contextProvider.create(staticActivation, req.body, ctxOptionsFn(req, res));
|
|
138
|
+
span.setAttribute('execution.id', executionCtx.executionId);
|
|
139
|
+
try {
|
|
140
|
+
subscriber.next(executionCtx);
|
|
141
|
+
if (isAsync) {
|
|
142
|
+
sendResponse(res, onSuccess(executionCtx));
|
|
143
|
+
}
|
|
144
|
+
}
|
|
145
|
+
catch (error) {
|
|
146
|
+
executionCtx.log.error('webhook execution error', {
|
|
147
|
+
error: JSON.stringify(error),
|
|
148
|
+
});
|
|
149
|
+
if (isAsync) {
|
|
150
|
+
sendResponse(res, onError(executionCtx.withData(error)));
|
|
151
|
+
}
|
|
152
|
+
}
|
|
153
|
+
finally {
|
|
154
|
+
span.end();
|
|
155
|
+
}
|
|
156
|
+
});
|
|
157
|
+
});
|
|
158
|
+
// this endpoint will trigger the workflow for each activation given by the external user ID
|
|
159
|
+
ctx.webhookRouter[method](`/${trigger.id}/users/:userId`, vanillaWebhookMiddleware(), async (req, res) => {
|
|
160
|
+
await ctx.tracer.startActiveSpan(`webhook-${trigger.id}`, (span) => {
|
|
161
|
+
span.setAttribute('task.id', trigger.id);
|
|
162
|
+
span.setAttribute('task.type', 'webhook');
|
|
163
|
+
span.setAttribute('user.id', req.params.userId);
|
|
164
|
+
const userId = req.params.userId;
|
|
165
|
+
const activation = res.locals.activation;
|
|
166
|
+
// Right now we only support a user having one activation
|
|
167
|
+
// so this will need changing when we support multiple activations per user
|
|
168
|
+
// as will the middleware
|
|
169
|
+
if (!activation) {
|
|
170
|
+
res.status(404).json({
|
|
171
|
+
status: 'error',
|
|
172
|
+
message: `No activations found for user: ${userId}`,
|
|
173
|
+
});
|
|
174
|
+
span.setAttribute('error.message', `No activations found for user: ${userId}`);
|
|
175
|
+
span.setAttribute('http.status_code', '404');
|
|
176
|
+
span.end();
|
|
177
|
+
return;
|
|
178
|
+
}
|
|
179
|
+
const executionCtx = ctx.contextProvider.create(activation, req.body, ctxOptionsFn(req, res));
|
|
180
|
+
span.setAttribute('execution.id', executionCtx.executionId);
|
|
181
|
+
const errors = [];
|
|
182
|
+
try {
|
|
183
|
+
subscriber.next(executionCtx);
|
|
184
|
+
}
|
|
185
|
+
catch (error) {
|
|
186
|
+
executionCtx.log.error('webhook execution error', {
|
|
187
|
+
error: JSON.stringify(error),
|
|
188
|
+
});
|
|
189
|
+
errors.push({
|
|
190
|
+
activationId: activation.id,
|
|
191
|
+
error,
|
|
192
|
+
});
|
|
193
|
+
}
|
|
194
|
+
if (isAsync) {
|
|
195
|
+
if (errors.length === 0) {
|
|
196
|
+
sendResponse(res, onSuccess(executionCtx));
|
|
197
|
+
}
|
|
198
|
+
else {
|
|
199
|
+
sendResponse(res, onError(executionCtx.withData(errors)));
|
|
200
|
+
}
|
|
201
|
+
}
|
|
202
|
+
span.end();
|
|
203
|
+
});
|
|
204
|
+
});
|
|
205
|
+
// this endpoint will trigger the workflow only for the activation given by its ID
|
|
206
|
+
ctx.webhookRouter[method](`/${trigger.id}/activations/:activationId`, vanillaWebhookMiddleware(), async (req, res) => {
|
|
207
|
+
await ctx.tracer.startActiveSpan(`webhook-${trigger.id}`, (span) => {
|
|
208
|
+
span.setAttribute('task.id', trigger.id);
|
|
209
|
+
span.setAttribute('task.type', 'webhook');
|
|
210
|
+
span.setAttribute('activation.id', req.params.activationId);
|
|
211
|
+
const activation = res.locals.activation;
|
|
212
|
+
const activationId = activation?.id ?? req.params.activationId;
|
|
213
|
+
if (!activation) {
|
|
214
|
+
// TODO report back actual errors
|
|
215
|
+
res.status(404).json({
|
|
216
|
+
status: 'error',
|
|
217
|
+
message: `No activation found for ID: ${activationId}`,
|
|
218
|
+
});
|
|
219
|
+
span.setAttribute('error.message', `No activation found for ID: ${activationId}`);
|
|
220
|
+
span.setAttribute('http.status_code', '404');
|
|
221
|
+
span.end();
|
|
222
|
+
return;
|
|
223
|
+
}
|
|
224
|
+
const activationCtx = ctx.contextProvider.create(activation, req.body, ctxOptionsFn(req, res));
|
|
225
|
+
span.setAttribute('execution.id', activationCtx.executionId);
|
|
226
|
+
try {
|
|
227
|
+
subscriber.next(activationCtx);
|
|
228
|
+
if (isAsync) {
|
|
229
|
+
sendResponse(res, onSuccess(activationCtx));
|
|
230
|
+
}
|
|
231
|
+
}
|
|
232
|
+
catch (error) {
|
|
233
|
+
activationCtx.log.error('webhook execution error', {
|
|
234
|
+
error: JSON.stringify(error),
|
|
235
|
+
});
|
|
236
|
+
if (isAsync) {
|
|
237
|
+
sendResponse(res, onError(activationCtx.withData(error)));
|
|
238
|
+
}
|
|
239
|
+
}
|
|
240
|
+
finally {
|
|
241
|
+
span.end();
|
|
242
|
+
}
|
|
243
|
+
});
|
|
244
|
+
});
|
|
245
|
+
function cleanup() {
|
|
246
|
+
ctx.log.debug('webhook trigger stopped');
|
|
247
|
+
subscriber.complete();
|
|
248
|
+
}
|
|
249
|
+
signal.addEventListener('abort', cleanup, { once: true });
|
|
250
|
+
return () => {
|
|
251
|
+
signal.removeEventListener('abort', cleanup);
|
|
252
|
+
ctx.log.debug('webhook execution unsubscribed');
|
|
253
|
+
};
|
|
254
|
+
});
|
|
255
|
+
},
|
|
256
|
+
};
|
|
257
|
+
function sendResponse(res, response) {
|
|
258
|
+
res.status(response.status);
|
|
259
|
+
response.headers.forEach((value, key) => {
|
|
260
|
+
res.setHeader(key, value);
|
|
261
|
+
});
|
|
262
|
+
if (response.body) {
|
|
263
|
+
(0, promises_1.pipeline)(response.body, res);
|
|
264
|
+
}
|
|
265
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"mod.d.ts","sourceRoot":"","sources":["../../../../src/src/interpreter/vanilla/mod.ts"],"names":[],"mappings":"AAaA,cAAc,yBAAyB,CAAC;AACxC,cAAc,qBAAqB,CAAC"}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/*
|
|
3
|
+
* Copyright (c) 2025 Versori Group Inc
|
|
4
|
+
*
|
|
5
|
+
* Use of this software is governed by the Business Source License 1.1
|
|
6
|
+
* included in the LICENSE file at the root of this repository.
|
|
7
|
+
*
|
|
8
|
+
* Change Date: 2029-01-01
|
|
9
|
+
* Change License: Apache License, Version 2.0
|
|
10
|
+
*
|
|
11
|
+
* As of the Change Date, in accordance with the Business Source License,
|
|
12
|
+
* use of this software will be governed by the Apache License, Version 2.0.
|
|
13
|
+
*/
|
|
14
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
15
|
+
if (k2 === undefined) k2 = k;
|
|
16
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
17
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
18
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
19
|
+
}
|
|
20
|
+
Object.defineProperty(o, k2, desc);
|
|
21
|
+
}) : (function(o, m, k, k2) {
|
|
22
|
+
if (k2 === undefined) k2 = k;
|
|
23
|
+
o[k2] = m[k];
|
|
24
|
+
}));
|
|
25
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
26
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
27
|
+
};
|
|
28
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
29
|
+
__exportStar(require("./VanillaInterpreter.js"), exports);
|
|
30
|
+
__exportStar(require("./ExecutionError.js"), exports);
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { Logger } from '../observability/mod.js';
|
|
2
|
+
import { Issue } from '@versori/run/services/platform';
|
|
2
3
|
export type CreateIssue = {
|
|
3
4
|
reason: 'manual' | 'error';
|
|
4
5
|
severity: 'low' | 'medium' | 'high';
|
|
@@ -7,24 +8,6 @@ export type CreateIssue = {
|
|
|
7
8
|
annotations?: Record<string, string>;
|
|
8
9
|
labels?: Record<string, string>;
|
|
9
10
|
};
|
|
10
|
-
export type Issue = {
|
|
11
|
-
id: string;
|
|
12
|
-
title: string;
|
|
13
|
-
message: string;
|
|
14
|
-
annotations: Record<string, string>;
|
|
15
|
-
labels: Record<string, string>;
|
|
16
|
-
createdAt: string;
|
|
17
|
-
lastSeenAt: string;
|
|
18
|
-
resolvedAt: string | null;
|
|
19
|
-
resolutionStatus: string | null;
|
|
20
|
-
environmentId: string;
|
|
21
|
-
organisationId: string;
|
|
22
|
-
projectId: string;
|
|
23
|
-
reason: string;
|
|
24
|
-
seenCount: number;
|
|
25
|
-
severity: string;
|
|
26
|
-
status: string;
|
|
27
|
-
};
|
|
28
11
|
export interface IssueAPI {
|
|
29
12
|
submitIssue(issue: CreateIssue): Promise<void>;
|
|
30
13
|
createIssue(issue: CreateIssue, options?: {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Issues.d.ts","sourceRoot":"","sources":["../../../src/src/issues/Issues.ts"],"names":[],"mappings":"AAuBA,OAAO,EAAE,MAAM,EAAE,MAAM,yBAAyB,CAAC;
|
|
1
|
+
{"version":3,"file":"Issues.d.ts","sourceRoot":"","sources":["../../../src/src/issues/Issues.ts"],"names":[],"mappings":"AAuBA,OAAO,EAAE,MAAM,EAAE,MAAM,yBAAyB,CAAC;AACjD,OAAO,EAAE,KAAK,EAAE,MAAM,gCAAgC,CAAC;AAEvD,MAAM,MAAM,WAAW,GAAG;IACtB,MAAM,EAAE,QAAQ,GAAG,OAAO,CAAC;IAC3B,QAAQ,EAAE,KAAK,GAAG,QAAQ,GAAG,MAAM,CAAC;IACpC,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,WAAW,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IACrC,MAAM,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;CACnC,CAAC;AAEF,MAAM,WAAW,QAAQ;IACrB,WAAW,CAAC,KAAK,EAAE,WAAW,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;IAE/C,WAAW,CAAC,KAAK,EAAE,WAAW,EAAE,OAAO,CAAC,EAAE;QACtC,WAAW,CAAC,EAAE,OAAO,CAAC;QACtB,cAAc,CAAC,EAAE,MAAM,CAAC;KAC3B,GAAG,OAAO,CAAC,KAAK,GAAG,IAAI,CAAC,CAAC;CAC7B;AAED,qBAAa,SAAU,YAAW,QAAQ;IACtC,OAAO,CAAC,QAAQ,CAAC,OAAO,CAAS;IACjC,OAAO,CAAC,QAAQ,CAAC,SAAS,CAAS;IACnC,OAAO,CAAC,QAAQ,CAAC,aAAa,CAAS;IACvC,OAAO,CAAC,QAAQ,CAAC,cAAc,CAAS;IAExC,OAAO,CAAC,QAAQ,CAAC,gBAAgB,CAAC,CAAS;IAC3C,OAAO,CAAC,QAAQ,CAAC,OAAO,CAAC,CAAS;IAClC,OAAO,CAAC,QAAQ,CAAC,OAAO,CAAC,CAAS;IAClC,OAAO,CAAC,GAAG,CAAS;gBAER,GAAG,EAAE,MAAM;IA2BjB,WAAW,CAAC,KAAK,EAAE,WAAW,GAAG,OAAO,CAAC,IAAI,CAAC;IAQpD,WAAW,CAAC,KAAK,EAAE,WAAW,EAAE,OAAO,CAAC,EAAE;QACtC,WAAW,CAAC,EAAE,OAAO,CAAC;QACtB,cAAc,CAAC,EAAE,MAAM,CAAC;KAC3B,GAAG,OAAO,CAAC,KAAK,GAAG,IAAI,CAAC;YAWX,MAAM;CA2DvB;AAED,qBAAa,UAAW,YAAW,QAAQ;IACvC,WAAW,CAAC,CAAC,EAAE,WAAW,GAAG,OAAO,CAAC,IAAI,CAAC;IAI1C,WAAW,CAAC,CAAC,EAAE,WAAW,EAAE,QAAQ,CAAC,EAAE;QACnC,WAAW,CAAC,EAAE,OAAO,CAAC;QACtB,cAAc,CAAC,EAAE,MAAM,CAAC;KAC3B,GAAG,OAAO,CAAC,KAAK,GAAG,IAAI,CAAC;CAG5B"}
|