@versori/run 0.2.8 → 0.2.9
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/Context.d.ts +4 -4
- package/esm/src/context/Context.d.ts.map +1 -1
- package/esm/src/context/ContextProvider.d.ts +3 -3
- package/esm/src/context/ContextProvider.d.ts.map +1 -1
- package/esm/src/dsl/http/default.d.ts +4 -4
- package/esm/src/dsl/http/default.d.ts.map +1 -1
- package/esm/src/dsl/http/default.js +3 -3
- package/esm/src/dsl/http/types.d.ts +8 -2
- package/esm/src/dsl/http/types.d.ts.map +1 -1
- package/esm/src/dsl/http/versori/configloader.d.ts +10 -1
- package/esm/src/dsl/http/versori/configloader.d.ts.map +1 -1
- package/esm/src/dsl/http/versori/configloader.js +37 -0
- 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 +2 -0
- package/esm/src/dsl/http/versori/contextcredentials.d.ts +0 -4
- package/esm/src/dsl/http/versori/contextcredentials.d.ts.map +1 -1
- package/esm/src/dsl/http/versori/cronapi.d.ts.map +1 -1
- package/esm/src/dsl/http/versori/cronapi.js +2 -2
- package/esm/src/dsl/http/versori/proxyroundtripper.d.ts +5 -7
- package/esm/src/dsl/http/versori/proxyroundtripper.d.ts.map +1 -1
- package/esm/src/dsl/http/versori/proxyroundtripper.js +10 -24
- package/esm/src/dsl/http/versori/roundtripper.d.ts +5 -7
- package/esm/src/dsl/http/versori/roundtripper.d.ts.map +1 -1
- package/esm/src/dsl/http/versori/roundtripper.js +11 -24
- package/esm/src/dsl/http/versori/webhookmiddleware.d.ts +16 -0
- package/esm/src/dsl/http/versori/webhookmiddleware.d.ts.map +1 -0
- package/esm/src/dsl/http/versori/webhookmiddleware.js +197 -0
- package/esm/src/dsl/tasks/HttpTask.d.ts +3 -3
- 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 +1 -0
- package/esm/src/dsl/triggers/WebhookTrigger.d.ts.map +1 -1
- package/esm/src/interpreter/memory/MemoryInterpreter.d.ts +7 -4
- package/esm/src/interpreter/memory/MemoryInterpreter.d.ts.map +1 -1
- package/esm/src/interpreter/memory/MemoryInterpreter.js +70 -20
- package/esm/src/interpreter/memory/ObservableCompiler.d.ts +4 -2
- package/esm/src/interpreter/memory/ObservableCompiler.d.ts.map +1 -1
- package/esm/src/interpreter/memory/compilers/schedule.js +2 -2
- package/esm/src/interpreter/memory/compilers/webhook.d.ts.map +1 -1
- package/esm/src/interpreter/memory/compilers/webhook.js +38 -12
- package/esm/src/observability/logging/ConsoleLogger.d.ts +1 -0
- package/esm/src/observability/logging/ConsoleLogger.d.ts.map +1 -1
- package/esm/src/observability/logging/ConsoleLogger.js +7 -0
- package/esm/src/observability/logging/Logger.d.ts +2 -1
- package/esm/src/observability/logging/Logger.d.ts.map +1 -1
- package/package.json +1 -1
- package/script/src/context/Context.d.ts +4 -4
- package/script/src/context/Context.d.ts.map +1 -1
- package/script/src/context/ContextProvider.d.ts +3 -3
- package/script/src/context/ContextProvider.d.ts.map +1 -1
- package/script/src/dsl/http/default.d.ts +4 -4
- package/script/src/dsl/http/default.d.ts.map +1 -1
- package/script/src/dsl/http/default.js +3 -3
- package/script/src/dsl/http/types.d.ts +8 -2
- package/script/src/dsl/http/types.d.ts.map +1 -1
- package/script/src/dsl/http/versori/configloader.d.ts +10 -1
- package/script/src/dsl/http/versori/configloader.d.ts.map +1 -1
- package/script/src/dsl/http/versori/configloader.js +39 -0
- 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 +3 -1
- package/script/src/dsl/http/versori/contextcredentials.d.ts +0 -4
- package/script/src/dsl/http/versori/contextcredentials.d.ts.map +1 -1
- package/script/src/dsl/http/versori/cronapi.d.ts.map +1 -1
- package/script/src/dsl/http/versori/cronapi.js +1 -1
- package/script/src/dsl/http/versori/proxyroundtripper.d.ts +5 -7
- package/script/src/dsl/http/versori/proxyroundtripper.d.ts.map +1 -1
- package/script/src/dsl/http/versori/proxyroundtripper.js +9 -23
- package/script/src/dsl/http/versori/roundtripper.d.ts +5 -7
- package/script/src/dsl/http/versori/roundtripper.d.ts.map +1 -1
- package/script/src/dsl/http/versori/roundtripper.js +10 -23
- package/script/src/dsl/http/versori/webhookmiddleware.d.ts +16 -0
- package/script/src/dsl/http/versori/webhookmiddleware.d.ts.map +1 -0
- package/script/src/dsl/http/versori/webhookmiddleware.js +202 -0
- package/script/src/dsl/tasks/HttpTask.d.ts +3 -3
- 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 +1 -0
- package/script/src/dsl/triggers/WebhookTrigger.d.ts.map +1 -1
- package/script/src/interpreter/memory/MemoryInterpreter.d.ts +7 -4
- package/script/src/interpreter/memory/MemoryInterpreter.d.ts.map +1 -1
- package/script/src/interpreter/memory/MemoryInterpreter.js +70 -20
- package/script/src/interpreter/memory/ObservableCompiler.d.ts +4 -2
- package/script/src/interpreter/memory/ObservableCompiler.d.ts.map +1 -1
- package/script/src/interpreter/memory/compilers/schedule.js +2 -2
- package/script/src/interpreter/memory/compilers/webhook.d.ts.map +1 -1
- package/script/src/interpreter/memory/compilers/webhook.js +38 -12
- package/script/src/observability/logging/ConsoleLogger.d.ts +1 -0
- package/script/src/observability/logging/ConsoleLogger.d.ts.map +1 -1
- package/script/src/observability/logging/ConsoleLogger.js +7 -0
- package/script/src/observability/logging/Logger.d.ts +2 -1
- package/script/src/observability/logging/Logger.d.ts.map +1 -1
|
@@ -0,0 +1,197 @@
|
|
|
1
|
+
import { createHmac } from 'node:crypto';
|
|
2
|
+
import { Buffer } from 'node:buffer';
|
|
3
|
+
// TODO: Refactor this so we don't have like three different middlewares for static and dynamic webhooks
|
|
4
|
+
export function createStaticWebhookMiddleware(opts) {
|
|
5
|
+
if (opts.connName === undefined) {
|
|
6
|
+
opts.log.warn(`No connection ID found for webhook, accepting any requests which is unsecure!`, { webhookId: opts.id });
|
|
7
|
+
return async (_req, res, next) => {
|
|
8
|
+
const activation = await opts.cnxProvider.getStaticActivation();
|
|
9
|
+
res.locals.activation = activation;
|
|
10
|
+
next();
|
|
11
|
+
};
|
|
12
|
+
}
|
|
13
|
+
return async (req, res, next) => {
|
|
14
|
+
if (!opts.connName) {
|
|
15
|
+
// This is mainly for type safety, but we should never reach this point
|
|
16
|
+
opts.log.error('Connection name is not defined for webhook middleware');
|
|
17
|
+
res.status(401).json({ error: 'Unauthorised' });
|
|
18
|
+
return;
|
|
19
|
+
}
|
|
20
|
+
const cnxId = opts.cfgReader.getConnectionID(opts.connName);
|
|
21
|
+
const conn = await opts.cnxProvider.getStaticConnection(cnxId);
|
|
22
|
+
const activation = await opts.cnxProvider.getStaticActivation();
|
|
23
|
+
if (conn === undefined || activation === undefined) {
|
|
24
|
+
opts.log.error(`Connection or activation not found for webhook: /${opts.id}`);
|
|
25
|
+
res.status(401).json({ error: 'Unauthorised' });
|
|
26
|
+
return;
|
|
27
|
+
}
|
|
28
|
+
const key = await opts.credentials.getRaw(opts.connName);
|
|
29
|
+
const asc = conn.credentials[0].authSchemeConfig;
|
|
30
|
+
if (!asc || !asc.hmac) {
|
|
31
|
+
opts.log.error('HMAC AuthSchemeConfig not found for webhook');
|
|
32
|
+
res.status(401).json({ error: 'Unauthorised' });
|
|
33
|
+
return;
|
|
34
|
+
}
|
|
35
|
+
const digest = createDigest(asc.hmac, req, key);
|
|
36
|
+
let requestDigest;
|
|
37
|
+
try {
|
|
38
|
+
requestDigest = extractDigest(asc.hmac, req);
|
|
39
|
+
}
|
|
40
|
+
catch (error) {
|
|
41
|
+
opts.log.error('Error extracting HMAC digest from request', { error });
|
|
42
|
+
res.status(401).json({ error: 'Unauthorised' });
|
|
43
|
+
return;
|
|
44
|
+
}
|
|
45
|
+
if (digest !== requestDigest) {
|
|
46
|
+
res.status(401).json({ error: 'Unauthorised' });
|
|
47
|
+
return;
|
|
48
|
+
}
|
|
49
|
+
res.locals.activation = activation;
|
|
50
|
+
next();
|
|
51
|
+
};
|
|
52
|
+
}
|
|
53
|
+
export function createActIdDynamicWebhookMiddleware(opts) {
|
|
54
|
+
if (!opts.connName) {
|
|
55
|
+
opts.log.warn(`No template ID found for webhook, accepting any requests which is unsecure!`, { webhookId: opts.id });
|
|
56
|
+
return async (req, res, next) => {
|
|
57
|
+
const activationId = req.params.activationId;
|
|
58
|
+
const activation = await opts.cnxProvider.getActivation(activationId);
|
|
59
|
+
res.locals.activation = activation;
|
|
60
|
+
next();
|
|
61
|
+
};
|
|
62
|
+
}
|
|
63
|
+
return async (req, res, next) => {
|
|
64
|
+
if (!opts.connName) {
|
|
65
|
+
// This is mainly for type safety, but we should never reach this point
|
|
66
|
+
opts.log.error('Connection name is not defined for webhook middleware');
|
|
67
|
+
res.status(401).json({ error: 'Unauthorised' });
|
|
68
|
+
return;
|
|
69
|
+
}
|
|
70
|
+
const templateId = opts.cfgReader.getTemplateID(opts.connName);
|
|
71
|
+
const activationId = req.params.activationId;
|
|
72
|
+
const activation = await opts.cnxProvider.getActivation(activationId);
|
|
73
|
+
const conn = await opts.cnxProvider.getActivationConnection(templateId, activationId);
|
|
74
|
+
if (activation === undefined || conn === undefined) {
|
|
75
|
+
opts.log.error(`Activation or connection not found for webhook: /${opts.id}/activations/${activationId}`);
|
|
76
|
+
res.status(401).json({ error: 'Unauthorised' });
|
|
77
|
+
return;
|
|
78
|
+
}
|
|
79
|
+
const key = await opts.credentials.getRaw(opts.connName, activationId);
|
|
80
|
+
const asc = conn.credentials[0].authSchemeConfig;
|
|
81
|
+
if (!asc || !asc.hmac) {
|
|
82
|
+
opts.log.error('HMAC AuthSchemeConfig not found for webhook');
|
|
83
|
+
res.status(401).json({ error: 'Unauthorised' });
|
|
84
|
+
return;
|
|
85
|
+
}
|
|
86
|
+
const digest = createDigest(asc.hmac, req, key);
|
|
87
|
+
let requestDigest;
|
|
88
|
+
try {
|
|
89
|
+
requestDigest = extractDigest(asc.hmac, req);
|
|
90
|
+
}
|
|
91
|
+
catch (error) {
|
|
92
|
+
opts.log.error('Error extracting HMAC digest from request', { error });
|
|
93
|
+
res.status(401).json({ error: 'Unauthorised' });
|
|
94
|
+
return;
|
|
95
|
+
}
|
|
96
|
+
if (digest !== requestDigest) {
|
|
97
|
+
res.status(401).json({ error: 'Unauthorised' });
|
|
98
|
+
return;
|
|
99
|
+
}
|
|
100
|
+
res.locals.activation = activation;
|
|
101
|
+
next();
|
|
102
|
+
};
|
|
103
|
+
}
|
|
104
|
+
export function createUserIdDynamicWebhookMiddleware(opts) {
|
|
105
|
+
if (!opts.connName) {
|
|
106
|
+
opts.log.warn(`No template ID found for webhook, accepting any requests which is unsecure!`, { webhookId: opts.id });
|
|
107
|
+
return async (req, res, next) => {
|
|
108
|
+
const userId = req.params.userId;
|
|
109
|
+
const activations = await opts.cnxProvider.getUserActivations(userId);
|
|
110
|
+
if (activations.length === 0) {
|
|
111
|
+
opts.log.error(`No activations found for user: ${userId}`);
|
|
112
|
+
res.status(401).json({ error: 'Unauthorised' });
|
|
113
|
+
return;
|
|
114
|
+
}
|
|
115
|
+
const activation = activations[0];
|
|
116
|
+
res.locals.activation = activation;
|
|
117
|
+
next();
|
|
118
|
+
};
|
|
119
|
+
}
|
|
120
|
+
return async (req, res, next) => {
|
|
121
|
+
if (!opts.connName) {
|
|
122
|
+
// This is mainly for type safety, but we should never reach this point
|
|
123
|
+
opts.log.error('Connection name is not defined for webhook middleware');
|
|
124
|
+
res.status(401).json({ error: 'Unauthorised' });
|
|
125
|
+
return;
|
|
126
|
+
}
|
|
127
|
+
const templateId = opts.cfgReader.getTemplateID(opts.connName);
|
|
128
|
+
const userId = req.params.userId;
|
|
129
|
+
const activations = await opts.cnxProvider.getUserActivations(userId);
|
|
130
|
+
if (activations.length === 0) {
|
|
131
|
+
res.status(401).json({ error: 'Unauthorised' });
|
|
132
|
+
return;
|
|
133
|
+
}
|
|
134
|
+
const activation = activations[0]; // Right now we only support a user having one activation
|
|
135
|
+
const conn = await opts.cnxProvider.getActivationConnection(templateId, activation.id);
|
|
136
|
+
if (conn === undefined) {
|
|
137
|
+
opts.log.error(`Connection not found for webhook: /${opts.id}/users/${userId}`);
|
|
138
|
+
res.status(401).json({ error: 'Unauthorised' });
|
|
139
|
+
return;
|
|
140
|
+
}
|
|
141
|
+
const key = await opts.credentials.getRaw(opts.connName, activation.id);
|
|
142
|
+
const asc = conn.credentials[0].authSchemeConfig;
|
|
143
|
+
if (!asc || !asc.hmac) {
|
|
144
|
+
opts.log.error('HMAC AuthSchemeConfig not found for webhook');
|
|
145
|
+
res.status(401).json({ error: 'Unauthorised' });
|
|
146
|
+
return;
|
|
147
|
+
}
|
|
148
|
+
const digest = createDigest(asc.hmac, req, key);
|
|
149
|
+
let requestDigest;
|
|
150
|
+
try {
|
|
151
|
+
requestDigest = extractDigest(asc.hmac, req);
|
|
152
|
+
}
|
|
153
|
+
catch (error) {
|
|
154
|
+
opts.log.error('Error extracting HMAC digest from request', { error });
|
|
155
|
+
res.status(401).json({ error: 'Unauthorised' });
|
|
156
|
+
return;
|
|
157
|
+
}
|
|
158
|
+
if (digest !== requestDigest) {
|
|
159
|
+
res.status(401).json({ error: 'Unauthorised' });
|
|
160
|
+
return;
|
|
161
|
+
}
|
|
162
|
+
res.locals.activation = activation;
|
|
163
|
+
next();
|
|
164
|
+
};
|
|
165
|
+
}
|
|
166
|
+
// createDigest creates a HMAC digest for the request using the provided key.
|
|
167
|
+
// Note that this assumes the request body is a JSON object, as one would normally
|
|
168
|
+
// expect for our use case.
|
|
169
|
+
// TODO: implement the case where we might want to digest the body + url or url + body
|
|
170
|
+
// or url...
|
|
171
|
+
function createDigest(asc, req, key) {
|
|
172
|
+
const hmac = createHmac(asc.algorithm, Buffer.from(key).toString('utf8'));
|
|
173
|
+
hmac.update(JSON.stringify(req.body));
|
|
174
|
+
return hmac.digest(asc.encoding);
|
|
175
|
+
}
|
|
176
|
+
function extractDigest(asc, req) {
|
|
177
|
+
switch (asc.in) {
|
|
178
|
+
case 'query':
|
|
179
|
+
if (req.query[asc.name]) {
|
|
180
|
+
return req.query[asc.name];
|
|
181
|
+
}
|
|
182
|
+
break;
|
|
183
|
+
case 'header':
|
|
184
|
+
if (req.headers[asc.name]) {
|
|
185
|
+
return req.headers[asc.name];
|
|
186
|
+
}
|
|
187
|
+
break;
|
|
188
|
+
case 'cookie':
|
|
189
|
+
if (req.cookies[asc.name]) {
|
|
190
|
+
return req.cookies[asc.name];
|
|
191
|
+
}
|
|
192
|
+
break;
|
|
193
|
+
default:
|
|
194
|
+
throw new Error(`Unsupported HMAC digest extraction method: ${asc.in}`);
|
|
195
|
+
}
|
|
196
|
+
throw new Error(`HMAC digest not found in request: ${asc.name}`);
|
|
197
|
+
}
|
|
@@ -2,7 +2,7 @@ import { Context, ContextImpl } from '../../context/Context.js';
|
|
|
2
2
|
import { KeyValue, KeyValueScope } from '../../kv/KeyValue.js';
|
|
3
3
|
import { Logger } from '../../observability/logging/Logger.js';
|
|
4
4
|
import { Activation, DynamicFetcher } from '../http/types.js';
|
|
5
|
-
import {
|
|
5
|
+
import { CredentialsProvider } from '../http/versori/contextcredentials.js';
|
|
6
6
|
import { ArrayTask, Task, Taskable, TaskType } from '../Task.js';
|
|
7
7
|
export interface HttpContext<Data, PageParams = undefined> extends Context<Data> {
|
|
8
8
|
fetch: typeof fetch;
|
|
@@ -42,9 +42,9 @@ export declare class HttpContextImpl<D, PageParams> implements HttpContext<D, Pa
|
|
|
42
42
|
get activation(): Activation | undefined;
|
|
43
43
|
get data(): D;
|
|
44
44
|
openKv(scope?: KeyValueScope): KeyValue;
|
|
45
|
-
credentials():
|
|
45
|
+
credentials(): CredentialsProvider;
|
|
46
46
|
get fetch(): typeof globalThis.fetch;
|
|
47
|
-
nextPage(
|
|
47
|
+
nextPage(_nextParams: PageParams): Promise<void>;
|
|
48
48
|
}
|
|
49
49
|
export declare function http<In = any, Out = any, PageParams = unknown>(taskId: string, opts: HttpOptions<In, Out, PageParams>, fn: HttpContextFunc<In, Out, PageParams>): Task<In, Out>;
|
|
50
50
|
//# sourceMappingURL=HttpTask.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"HttpTask.d.ts","sourceRoot":"","sources":["../../../../src/src/dsl/tasks/HttpTask.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,WAAW,EAAE,MAAM,0BAA0B,CAAC;AAChE,OAAO,EAAE,QAAQ,EAAE,aAAa,EAAE,MAAM,sBAAsB,CAAC;AAC/D,OAAO,EAAE,MAAM,EAAE,MAAM,uCAAuC,CAAC;AAE/D,OAAO,EAAE,UAAU,EAAE,cAAc,EAAsB,MAAM,kBAAkB,CAAC;AAClF,OAAO,EAAE,
|
|
1
|
+
{"version":3,"file":"HttpTask.d.ts","sourceRoot":"","sources":["../../../../src/src/dsl/tasks/HttpTask.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,WAAW,EAAE,MAAM,0BAA0B,CAAC;AAChE,OAAO,EAAE,QAAQ,EAAE,aAAa,EAAE,MAAM,sBAAsB,CAAC;AAC/D,OAAO,EAAE,MAAM,EAAE,MAAM,uCAAuC,CAAC;AAE/D,OAAO,EAAE,UAAU,EAAE,cAAc,EAAsB,MAAM,kBAAkB,CAAC;AAClF,OAAO,EAAE,mBAAmB,EAAE,MAAM,uCAAuC,CAAC;AAC5E,OAAO,EAAE,SAAS,EAAE,IAAI,EAAE,QAAQ,EAAE,QAAQ,EAAE,MAAM,YAAY,CAAC;AAMjE,MAAM,WAAW,WAAW,CAAC,IAAI,EAAE,UAAU,GAAG,SAAS,CAAE,SAAQ,OAAO,CAAC,IAAI,CAAC;IAC5E,KAAK,EAAE,OAAO,KAAK,CAAC;IACpB,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,EAAE,UAAU,GAAG,OAAO,CAAC,IAAI,CAAC;CAGzD;AAED,wBAAgB,IAAI,CAAC,EAAE,GAAG,GAAG,EAAE,GAAG,GAAG,GAAG,EAAE,UAAU,GAAG,OAAO,EAC1D,MAAM,EAAE,MAAM,EACd,IAAI,EAAE,WAAW,CAAC,EAAE,EAAE,GAAG,EAAE,UAAU,CAAC,EACtC,EAAE,EAAE,eAAe,CAAC,EAAE,EAAE,GAAG,EAAE,UAAU,CAAC,GACzC,IAAI,CAAC,EAAE,EAAE,GAAG,CAAC,CAEf"}
|
|
@@ -124,7 +124,7 @@ export class HttpContextImpl {
|
|
|
124
124
|
? wrapDynamicFetcher(__classPrivateFieldGet(this, _HttpContextImpl_dynamicFetcher, "f"), __classPrivateFieldGet(this, _HttpContextImpl_inner, "f").activation)
|
|
125
125
|
: __classPrivateFieldGet(this, _HttpContextImpl_staticFetcher, "f") ?? globalThis.fetch;
|
|
126
126
|
}
|
|
127
|
-
async nextPage(
|
|
127
|
+
async nextPage(_nextParams) {
|
|
128
128
|
throw new Error('Method not implemented.');
|
|
129
129
|
}
|
|
130
130
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"WebhookTrigger.d.ts","sourceRoot":"","sources":["../../../../src/src/dsl/triggers/WebhookTrigger.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,0BAA0B,CAAC;AAEnD,OAAO,EAAE,QAAQ,EAAE,MAAM,YAAY,CAAC;AACtC,OAAO,EAAE,OAAO,EAAE,WAAW,EAAE,MAAM,eAAe,CAAC;AACrD,OAAO,EAAE,QAAQ,EAAgB,MAAM,gBAAgB,CAAC;AAExD,MAAM,MAAM,WAAW,GAAG,MAAM,CAAC,MAAM,EAAE,KAAK,CAAC,CAAC;AAEhD,MAAM,MAAM,kBAAkB,GAAG,OAAO,GAAG;IACvC,MAAM,EAAE,MAAM,CAAC;IACf,OAAO,EAAE,MAAM,EAAE,CAAC;IAClB,cAAc,E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,CAAC,EAAE,MAAM,GAAG,OAAO,CAAC;IAExB;;;;;;;OAOG;IACH,SAAS,CAAC,EAAE,CAAC,CAAC,EAAE,GAAG,EAAE,OAAO,CAAC,CAAC,CAAC,KAAK,QAAQ,CAAC;IAE7C;;;;;;;OAOG;IACH,OAAO,CAAC,EAAE,CAAC,CAAC,EAAE,GAAG,EAAE,OAAO,CAAC,CAAC,CAAC,KAAK,QAAQ,CAAC;CAC9C,CAAA;AAED,MAAM,MAAM,cAAc,GAAG;IACzB,IAAI,CAAC,EAAE,kBAAkB,CAAC;IAC1B,QAAQ,CAAC,EAAE,sBAAsB,CAAC;IAClC,UAAU,CAAC,EAAE,MAAM,CAAC;CACvB,CAAA;AAED,qBAAa,cAAe,YAAW,OAAO,CAAC,WAAW,CAAC;IACvD,EAAE,EAAE,MAAM,CAAC;IACX,OAAO,EAAE,cAAc,CAAC;IAExB,CAAC,WAAW,CAAC,EAAE,MAAM,CAAa;gBAEtB,EAAE,EAAE,MAAM,EAAE,OAAO,GAAE,cAAmB;IAKpD,IAAI,CAAC,EAAE,EAAE,IAAI,EAAE,QAAQ,CAAC,WAAW,EAAE,EAAE,CAAC,GAAG,QAAQ,CAAC,EAAE,CAAC;CAG1D;AAED,wBAAgB,OAAO,CAAC,EAAE,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,cAAc,GAAG,OAAO,CAAC,WAAW,CAAC,CAElF"}
|
|
@@ -3,7 +3,7 @@ import { NodeSDK } from '@opentelemetry/sdk-node';
|
|
|
3
3
|
import { Router } from 'express';
|
|
4
4
|
import { Observable, Subscription } from 'rxjs';
|
|
5
5
|
import { ContextProvider } from '../../context/ContextProvider.js';
|
|
6
|
-
import { ConnectionProvider, CronProvider, RoundTripperFactory } from '../../dsl/http/types.js';
|
|
6
|
+
import { ConfigReader, ConnectionProvider, CronProvider, RoundTripperFactory } from '../../dsl/http/types.js';
|
|
7
7
|
import { Workflow } from '../../dsl/Workflow.js';
|
|
8
8
|
import { ContextImpl, ContextOperatorFunction } from '../../mod.js';
|
|
9
9
|
import { Logger } from '../../observability/logging/Logger.js';
|
|
@@ -27,17 +27,20 @@ export declare class MemoryInterpreter {
|
|
|
27
27
|
private readonly compiler;
|
|
28
28
|
private readonly contextProvider;
|
|
29
29
|
private readonly roundTripperFactory;
|
|
30
|
-
private readonly
|
|
30
|
+
private readonly webhookRouter;
|
|
31
|
+
private readonly cronRouter;
|
|
31
32
|
private cronRegistry;
|
|
32
33
|
private readonly connectionProvider;
|
|
33
34
|
private readonly cronProvider;
|
|
34
35
|
private readonly tracer;
|
|
36
|
+
private readonly cfgReader;
|
|
35
37
|
private readonly otelSDK?;
|
|
36
38
|
private registeredWorkflows;
|
|
37
|
-
private
|
|
39
|
+
private webhookServer?;
|
|
40
|
+
private cronServer?;
|
|
38
41
|
private shutdownServer?;
|
|
39
42
|
private isShuttingDown;
|
|
40
|
-
constructor(log: Logger, compiler: ObservableCompiler, contextProvider: ContextProvider, roundTripperFactory: RoundTripperFactory,
|
|
43
|
+
constructor(log: Logger, compiler: ObservableCompiler, contextProvider: ContextProvider, roundTripperFactory: RoundTripperFactory, webhookRouter: Router, cronRouter: Router, cronRegistry: Map<string, string>, connectionProvider: ConnectionProvider, cronProvider: CronProvider, tracer: Tracer, cfgReader: ConfigReader, otelSDK?: NodeSDK | undefined);
|
|
41
44
|
static newInstance(options?: MemoryInterpreterOptions): Promise<MemoryInterpreter>;
|
|
42
45
|
register<O>(workflow: Workflow<O>, options?: MemoryInterpreterOptions): Registration;
|
|
43
46
|
start(): Promise<void>;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"MemoryInterpreter.d.ts","sourceRoot":"","sources":["../../../../src/src/interpreter/memory/MemoryInterpreter.ts"],"names":[],"mappings":"AAAA,OAAsB,EAAE,MAAM,EAAE,MAAM,oBAAoB,CAAC;AAG3D,OAAO,EAAE,OAAO,EAAE,MAAM,yBAAyB,CAAC;AAClD,OAAgB,EAAqB,MAAM,EAAE,MAAM,SAAS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B,GAAG,OAAO,CAAC,iBAAiB,CAAC;IAqF5F,QAAQ,CAAC,CAAC,EAAE,QAAQ,EAAE,QAAQ,CAAC,CAAC,CAAC,EAAE,OAAO,CAAC,EAAE,wBAAwB;IAiD/D,KAAK,IAAI,OAAO,CAAC,IAAI,CAAC;IAyMtB,IAAI,IAAI,OAAO,CAAC,IAAI,CAAC;CAO9B"}
|
|
@@ -17,6 +17,7 @@ import { NatsKeyValueProvider } from '../../kv/nats/NatsKeyValueProvider.js';
|
|
|
17
17
|
import { ConsoleLogger } from '../../observability/logging/ConsoleLogger.js';
|
|
18
18
|
import { ObservableCompiler } from './ObservableCompiler.js';
|
|
19
19
|
import { ProxyRoundTripper } from '../../dsl/http/versori/proxyroundtripper.js';
|
|
20
|
+
import { VersoriConfigReader } from '../../dsl/http/versori/configloader.js';
|
|
20
21
|
function getKVProvider(runLocal) {
|
|
21
22
|
if (runLocal) {
|
|
22
23
|
return Promise.resolve(new MemoryKeyValueProvider());
|
|
@@ -35,7 +36,7 @@ function getRoundTripperFactory(log, tracer, opts) {
|
|
|
35
36
|
return new DefaultRoundTripperFactory();
|
|
36
37
|
}
|
|
37
38
|
export class MemoryInterpreter {
|
|
38
|
-
constructor(log, compiler, contextProvider, roundTripperFactory,
|
|
39
|
+
constructor(log, compiler, contextProvider, roundTripperFactory, webhookRouter, cronRouter, cronRegistry, connectionProvider, cronProvider, tracer, cfgReader, otelSDK) {
|
|
39
40
|
Object.defineProperty(this, "log", {
|
|
40
41
|
enumerable: true,
|
|
41
42
|
configurable: true,
|
|
@@ -60,11 +61,17 @@ export class MemoryInterpreter {
|
|
|
60
61
|
writable: true,
|
|
61
62
|
value: roundTripperFactory
|
|
62
63
|
});
|
|
63
|
-
Object.defineProperty(this, "
|
|
64
|
+
Object.defineProperty(this, "webhookRouter", {
|
|
64
65
|
enumerable: true,
|
|
65
66
|
configurable: true,
|
|
66
67
|
writable: true,
|
|
67
|
-
value:
|
|
68
|
+
value: webhookRouter
|
|
69
|
+
});
|
|
70
|
+
Object.defineProperty(this, "cronRouter", {
|
|
71
|
+
enumerable: true,
|
|
72
|
+
configurable: true,
|
|
73
|
+
writable: true,
|
|
74
|
+
value: cronRouter
|
|
68
75
|
});
|
|
69
76
|
Object.defineProperty(this, "cronRegistry", {
|
|
70
77
|
enumerable: true,
|
|
@@ -90,6 +97,12 @@ export class MemoryInterpreter {
|
|
|
90
97
|
writable: true,
|
|
91
98
|
value: tracer
|
|
92
99
|
});
|
|
100
|
+
Object.defineProperty(this, "cfgReader", {
|
|
101
|
+
enumerable: true,
|
|
102
|
+
configurable: true,
|
|
103
|
+
writable: true,
|
|
104
|
+
value: cfgReader
|
|
105
|
+
});
|
|
93
106
|
Object.defineProperty(this, "otelSDK", {
|
|
94
107
|
enumerable: true,
|
|
95
108
|
configurable: true,
|
|
@@ -102,7 +115,13 @@ export class MemoryInterpreter {
|
|
|
102
115
|
writable: true,
|
|
103
116
|
value: []
|
|
104
117
|
});
|
|
105
|
-
Object.defineProperty(this, "
|
|
118
|
+
Object.defineProperty(this, "webhookServer", {
|
|
119
|
+
enumerable: true,
|
|
120
|
+
configurable: true,
|
|
121
|
+
writable: true,
|
|
122
|
+
value: void 0
|
|
123
|
+
});
|
|
124
|
+
Object.defineProperty(this, "cronServer", {
|
|
106
125
|
enumerable: true,
|
|
107
126
|
configurable: true,
|
|
108
127
|
writable: true,
|
|
@@ -137,6 +156,7 @@ export class MemoryInterpreter {
|
|
|
137
156
|
const orgSlug = Deno.env.get(envVarOrgSlug) || 'development';
|
|
138
157
|
const otelTracesURL = Deno.env.get(envVarOtelTracesURL);
|
|
139
158
|
let otelSDK;
|
|
159
|
+
const configReader = VersoriConfigReader.fromEnv(log);
|
|
140
160
|
const runLocal = Deno.env.get(envVarLocalRun) === 'true';
|
|
141
161
|
await waitForReady(log);
|
|
142
162
|
// Do NOT change those attributes, they are used by the API to filter on
|
|
@@ -167,10 +187,10 @@ export class MemoryInterpreter {
|
|
|
167
187
|
if (options.contextProvider) {
|
|
168
188
|
// no need to set up a key-value provider if options.contextProvider is already
|
|
169
189
|
// initialised.
|
|
170
|
-
return new MemoryInterpreter(log, compiler, options.contextProvider, roundTripperFactory, express.Router(), new Map(), PlatformAPIClient.fromEnv(), CronAPIClient.fromEnv(), tracer, otelSDK);
|
|
190
|
+
return new MemoryInterpreter(log, compiler, options.contextProvider, roundTripperFactory, express.Router(), express.Router(), new Map(), PlatformAPIClient.fromEnv(), CronAPIClient.fromEnv(), tracer, configReader, otelSDK);
|
|
171
191
|
}
|
|
172
192
|
const kvp = await getKVProvider(runLocal);
|
|
173
|
-
return new MemoryInterpreter(log, compiler, new ContextProviderImpl(log, kvp, roundTripperFactory.credentials()), roundTripperFactory, express.Router(), new Map(), PlatformAPIClient.fromEnv(), CronAPIClient.fromEnv(), tracer, otelSDK);
|
|
193
|
+
return new MemoryInterpreter(log, compiler, new ContextProviderImpl(log, kvp, roundTripperFactory.credentials()), roundTripperFactory, express.Router(), express.Router(), new Map(), PlatformAPIClient.fromEnv(), CronAPIClient.fromEnv(), tracer, configReader, otelSDK);
|
|
174
194
|
}
|
|
175
195
|
register(workflow, options) {
|
|
176
196
|
const localAbortController = new AbortController();
|
|
@@ -187,9 +207,11 @@ export class MemoryInterpreter {
|
|
|
187
207
|
tracer: this.tracer,
|
|
188
208
|
contextProvider: this.contextProvider,
|
|
189
209
|
roundTripperFactory: this.roundTripperFactory,
|
|
190
|
-
|
|
210
|
+
webhookRouter: this.webhookRouter,
|
|
211
|
+
cronRouter: this.cronRouter,
|
|
191
212
|
cronRegistry: this.cronRegistry,
|
|
192
213
|
connectionProvider: this.connectionProvider,
|
|
214
|
+
configReader: this.cfgReader,
|
|
193
215
|
};
|
|
194
216
|
const trigger$ = this.compiler.compileTrigger(compilerContext, workflow.trigger, combinedSignal);
|
|
195
217
|
const task$ = this.compiler.compileTask(compilerContext, workflow.task);
|
|
@@ -207,21 +229,28 @@ export class MemoryInterpreter {
|
|
|
207
229
|
}
|
|
208
230
|
async start() {
|
|
209
231
|
const port = Deno.env.get('PORT') || 3000;
|
|
210
|
-
const
|
|
211
|
-
|
|
232
|
+
const cronPort = Deno.env.get('CRON_PORT') || 3001;
|
|
233
|
+
const webhookApp = express();
|
|
234
|
+
webhookApp.use(express.json()); // Add JSON body parser middleware
|
|
235
|
+
const cronApp = express();
|
|
236
|
+
cronApp.use(express.json());
|
|
212
237
|
const xml2jsDefaults = {
|
|
213
238
|
explicitArray: false,
|
|
214
239
|
normalize: false,
|
|
215
240
|
normalizeTags: false,
|
|
216
241
|
trim: true,
|
|
217
242
|
};
|
|
218
|
-
|
|
243
|
+
webhookApp.use(xmlparser(xml2jsDefaults));
|
|
219
244
|
// Add health check route
|
|
220
|
-
this.
|
|
245
|
+
this.webhookRouter.get('/health', (_req, res) => {
|
|
246
|
+
res.json({ status: 'healthy' });
|
|
247
|
+
});
|
|
248
|
+
this.cronRouter.get('/health', (_req, res) => {
|
|
221
249
|
res.json({ status: 'healthy' });
|
|
222
250
|
});
|
|
223
|
-
// Add router to the
|
|
224
|
-
|
|
251
|
+
// Add router to the webhookApplication
|
|
252
|
+
webhookApp.use(this.webhookRouter);
|
|
253
|
+
cronApp.use(this.cronRouter);
|
|
225
254
|
// Start all registered workflows
|
|
226
255
|
for (const registration of this.registeredWorkflows) {
|
|
227
256
|
Deno.addSignalListener('SIGINT', registration.sigintListener);
|
|
@@ -287,9 +316,12 @@ export class MemoryInterpreter {
|
|
|
287
316
|
});
|
|
288
317
|
throw new Error('Unable to register scheduler tasks with central cron provider');
|
|
289
318
|
}
|
|
290
|
-
this.
|
|
319
|
+
this.webhookServer = webhookApp.listen(port, () => {
|
|
291
320
|
this.log.info(`Express server listening on http://localhost:${port}`);
|
|
292
321
|
});
|
|
322
|
+
this.cronServer = cronApp.listen(cronPort, () => {
|
|
323
|
+
this.log.info(`Cron server listening on http://localhost:${cronPort}`);
|
|
324
|
+
});
|
|
293
325
|
this.shutdownServer = () => {
|
|
294
326
|
if (this.isShuttingDown) {
|
|
295
327
|
return;
|
|
@@ -297,8 +329,11 @@ export class MemoryInterpreter {
|
|
|
297
329
|
this.isShuttingDown = true;
|
|
298
330
|
this.log.info('Shutting down server');
|
|
299
331
|
// Close the server
|
|
300
|
-
if (this.
|
|
301
|
-
this.
|
|
332
|
+
if (this.webhookServer) {
|
|
333
|
+
this.webhookServer.close();
|
|
334
|
+
}
|
|
335
|
+
if (this.cronServer) {
|
|
336
|
+
this.cronServer.close();
|
|
302
337
|
}
|
|
303
338
|
// Remove all signal listeners
|
|
304
339
|
for (const registration of this.registeredWorkflows) {
|
|
@@ -317,13 +352,28 @@ export class MemoryInterpreter {
|
|
|
317
352
|
};
|
|
318
353
|
Deno.addSignalListener('SIGINT', this.shutdownServer);
|
|
319
354
|
return new Promise((resolve) => {
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
355
|
+
let serversClosed = 0;
|
|
356
|
+
const totalServers = [this.webhookServer, this.cronServer].filter(Boolean).length;
|
|
357
|
+
const checkResolve = () => {
|
|
358
|
+
serversClosed++;
|
|
359
|
+
if (serversClosed === totalServers) {
|
|
360
|
+
this.log.info('All servers closed');
|
|
323
361
|
resolve();
|
|
362
|
+
}
|
|
363
|
+
};
|
|
364
|
+
if (this.webhookServer) {
|
|
365
|
+
this.webhookServer.on('close', () => {
|
|
366
|
+
this.log.info('Webhook server closed');
|
|
367
|
+
checkResolve();
|
|
368
|
+
});
|
|
369
|
+
}
|
|
370
|
+
if (this.cronServer) {
|
|
371
|
+
this.cronServer.on('close', () => {
|
|
372
|
+
this.log.info('Cron server closed');
|
|
373
|
+
checkResolve();
|
|
324
374
|
});
|
|
325
375
|
}
|
|
326
|
-
|
|
376
|
+
if (!this.webhookServer && !this.cronServer) {
|
|
327
377
|
resolve();
|
|
328
378
|
}
|
|
329
379
|
});
|
|
@@ -5,7 +5,7 @@ import { ContextOperatorFunction, TaskCompiler, TriggerCompiler } from './compil
|
|
|
5
5
|
import { Trigger } from '../../dsl/Trigger.js';
|
|
6
6
|
import { ContextProvider } from '../../context/ContextProvider.js';
|
|
7
7
|
import { ContextImpl } from '../../context/Context.js';
|
|
8
|
-
import { ConnectionProvider, RoundTripperFactory } from '../../dsl/http/types.js';
|
|
8
|
+
import { ConfigReader, ConnectionProvider, RoundTripperFactory } from '../../dsl/http/types.js';
|
|
9
9
|
import { Router } from 'express';
|
|
10
10
|
import { Tracer } from '@opentelemetry/api';
|
|
11
11
|
export type CompilerContext = {
|
|
@@ -15,7 +15,9 @@ export type CompilerContext = {
|
|
|
15
15
|
contextProvider: ContextProvider;
|
|
16
16
|
roundTripperFactory: RoundTripperFactory;
|
|
17
17
|
connectionProvider: ConnectionProvider;
|
|
18
|
-
|
|
18
|
+
webhookRouter: Router;
|
|
19
|
+
cronRouter: Router;
|
|
20
|
+
configReader: ConfigReader;
|
|
19
21
|
cronRegistry: Map<string, string>;
|
|
20
22
|
};
|
|
21
23
|
export type CompilerFunc<In = any, Out = any, T extends Task<In, Out> = Task<In, Out>> = (ctx: CompilerContext, task: T) => OperatorFunction<In, Out>;
|
|
@@ -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,CA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AAG,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"}
|
|
@@ -4,7 +4,7 @@ import { ScheduleTrigger } from '../../../dsl/triggers/ScheduleTrigger.js';
|
|
|
4
4
|
function compileSchedule(ctx, trigger, signal) {
|
|
5
5
|
return new Observable((subscriber) => {
|
|
6
6
|
// Add HTTP endpoint for manual triggering
|
|
7
|
-
if (!ctx.
|
|
7
|
+
if (!ctx.cronRouter) {
|
|
8
8
|
throw new Error('Router not available in compiler context');
|
|
9
9
|
}
|
|
10
10
|
const projectId = Deno.env.get(envVarProjectId) || 'example-service';
|
|
@@ -65,7 +65,7 @@ function compileSchedule(ctx, trigger, signal) {
|
|
|
65
65
|
res.status(500).json({ error: 'Failed to trigger schedule' });
|
|
66
66
|
}
|
|
67
67
|
}
|
|
68
|
-
ctx.
|
|
68
|
+
ctx.cronRouter.post(`/cron/${trigger.id}`, async (req, res) => {
|
|
69
69
|
await ctx.tracer.startActiveSpan(`schedule-${trigger.id}`, async (span) => {
|
|
70
70
|
span.setAttribute('task.id', trigger.id);
|
|
71
71
|
span.setAttribute('task.type', 'schedule');
|
|
@@ -1 +1 @@
|
|
|
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;
|
|
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;AAkD7C,eAAO,MAAM,eAAe,EAAE,eAAe,CAAC,WAAW,EAAE,cAAc,CAuRxE,CAAC"}
|