@versori/run 0.2.8 → 0.2.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/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 +6 -7
- package/esm/src/dsl/http/versori/roundtripper.d.ts.map +1 -1
- package/esm/src/dsl/http/versori/roundtripper.js +32 -28
- 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 +6 -7
- package/script/src/dsl/http/versori/roundtripper.d.ts.map +1 -1
- package/script/src/dsl/http/versori/roundtripper.js +31 -27
- 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,202 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.createStaticWebhookMiddleware = createStaticWebhookMiddleware;
|
|
4
|
+
exports.createActIdDynamicWebhookMiddleware = createActIdDynamicWebhookMiddleware;
|
|
5
|
+
exports.createUserIdDynamicWebhookMiddleware = createUserIdDynamicWebhookMiddleware;
|
|
6
|
+
const node_crypto_1 = require("node:crypto");
|
|
7
|
+
const node_buffer_1 = require("node:buffer");
|
|
8
|
+
// TODO: Refactor this so we don't have like three different middlewares for static and dynamic webhooks
|
|
9
|
+
function createStaticWebhookMiddleware(opts) {
|
|
10
|
+
if (opts.connName === undefined) {
|
|
11
|
+
opts.log.warn(`No connection ID found for webhook, accepting any requests which is unsecure!`, { webhookId: opts.id });
|
|
12
|
+
return async (_req, res, next) => {
|
|
13
|
+
const activation = await opts.cnxProvider.getStaticActivation();
|
|
14
|
+
res.locals.activation = activation;
|
|
15
|
+
next();
|
|
16
|
+
};
|
|
17
|
+
}
|
|
18
|
+
return async (req, res, next) => {
|
|
19
|
+
if (!opts.connName) {
|
|
20
|
+
// This is mainly for type safety, but we should never reach this point
|
|
21
|
+
opts.log.error('Connection name is not defined for webhook middleware');
|
|
22
|
+
res.status(401).json({ error: 'Unauthorised' });
|
|
23
|
+
return;
|
|
24
|
+
}
|
|
25
|
+
const cnxId = opts.cfgReader.getConnectionID(opts.connName);
|
|
26
|
+
const conn = await opts.cnxProvider.getStaticConnection(cnxId);
|
|
27
|
+
const activation = await opts.cnxProvider.getStaticActivation();
|
|
28
|
+
if (conn === undefined || activation === undefined) {
|
|
29
|
+
opts.log.error(`Connection or activation not found for webhook: /${opts.id}`);
|
|
30
|
+
res.status(401).json({ error: 'Unauthorised' });
|
|
31
|
+
return;
|
|
32
|
+
}
|
|
33
|
+
const key = await opts.credentials.getRaw(opts.connName);
|
|
34
|
+
const asc = conn.credentials[0].authSchemeConfig;
|
|
35
|
+
if (!asc || !asc.hmac) {
|
|
36
|
+
opts.log.error('HMAC AuthSchemeConfig not found for webhook');
|
|
37
|
+
res.status(401).json({ error: 'Unauthorised' });
|
|
38
|
+
return;
|
|
39
|
+
}
|
|
40
|
+
const digest = createDigest(asc.hmac, req, key);
|
|
41
|
+
let requestDigest;
|
|
42
|
+
try {
|
|
43
|
+
requestDigest = extractDigest(asc.hmac, req);
|
|
44
|
+
}
|
|
45
|
+
catch (error) {
|
|
46
|
+
opts.log.error('Error extracting HMAC digest from request', { error });
|
|
47
|
+
res.status(401).json({ error: 'Unauthorised' });
|
|
48
|
+
return;
|
|
49
|
+
}
|
|
50
|
+
if (digest !== requestDigest) {
|
|
51
|
+
res.status(401).json({ error: 'Unauthorised' });
|
|
52
|
+
return;
|
|
53
|
+
}
|
|
54
|
+
res.locals.activation = activation;
|
|
55
|
+
next();
|
|
56
|
+
};
|
|
57
|
+
}
|
|
58
|
+
function createActIdDynamicWebhookMiddleware(opts) {
|
|
59
|
+
if (!opts.connName) {
|
|
60
|
+
opts.log.warn(`No template ID found for webhook, accepting any requests which is unsecure!`, { webhookId: opts.id });
|
|
61
|
+
return async (req, res, next) => {
|
|
62
|
+
const activationId = req.params.activationId;
|
|
63
|
+
const activation = await opts.cnxProvider.getActivation(activationId);
|
|
64
|
+
res.locals.activation = activation;
|
|
65
|
+
next();
|
|
66
|
+
};
|
|
67
|
+
}
|
|
68
|
+
return async (req, res, next) => {
|
|
69
|
+
if (!opts.connName) {
|
|
70
|
+
// This is mainly for type safety, but we should never reach this point
|
|
71
|
+
opts.log.error('Connection name is not defined for webhook middleware');
|
|
72
|
+
res.status(401).json({ error: 'Unauthorised' });
|
|
73
|
+
return;
|
|
74
|
+
}
|
|
75
|
+
const templateId = opts.cfgReader.getTemplateID(opts.connName);
|
|
76
|
+
const activationId = req.params.activationId;
|
|
77
|
+
const activation = await opts.cnxProvider.getActivation(activationId);
|
|
78
|
+
const conn = await opts.cnxProvider.getActivationConnection(templateId, activationId);
|
|
79
|
+
if (activation === undefined || conn === undefined) {
|
|
80
|
+
opts.log.error(`Activation or connection not found for webhook: /${opts.id}/activations/${activationId}`);
|
|
81
|
+
res.status(401).json({ error: 'Unauthorised' });
|
|
82
|
+
return;
|
|
83
|
+
}
|
|
84
|
+
const key = await opts.credentials.getRaw(opts.connName, activationId);
|
|
85
|
+
const asc = conn.credentials[0].authSchemeConfig;
|
|
86
|
+
if (!asc || !asc.hmac) {
|
|
87
|
+
opts.log.error('HMAC AuthSchemeConfig not found for webhook');
|
|
88
|
+
res.status(401).json({ error: 'Unauthorised' });
|
|
89
|
+
return;
|
|
90
|
+
}
|
|
91
|
+
const digest = createDigest(asc.hmac, req, key);
|
|
92
|
+
let requestDigest;
|
|
93
|
+
try {
|
|
94
|
+
requestDigest = extractDigest(asc.hmac, req);
|
|
95
|
+
}
|
|
96
|
+
catch (error) {
|
|
97
|
+
opts.log.error('Error extracting HMAC digest from request', { error });
|
|
98
|
+
res.status(401).json({ error: 'Unauthorised' });
|
|
99
|
+
return;
|
|
100
|
+
}
|
|
101
|
+
if (digest !== requestDigest) {
|
|
102
|
+
res.status(401).json({ error: 'Unauthorised' });
|
|
103
|
+
return;
|
|
104
|
+
}
|
|
105
|
+
res.locals.activation = activation;
|
|
106
|
+
next();
|
|
107
|
+
};
|
|
108
|
+
}
|
|
109
|
+
function createUserIdDynamicWebhookMiddleware(opts) {
|
|
110
|
+
if (!opts.connName) {
|
|
111
|
+
opts.log.warn(`No template ID found for webhook, accepting any requests which is unsecure!`, { webhookId: opts.id });
|
|
112
|
+
return async (req, res, next) => {
|
|
113
|
+
const userId = req.params.userId;
|
|
114
|
+
const activations = await opts.cnxProvider.getUserActivations(userId);
|
|
115
|
+
if (activations.length === 0) {
|
|
116
|
+
opts.log.error(`No activations found for user: ${userId}`);
|
|
117
|
+
res.status(401).json({ error: 'Unauthorised' });
|
|
118
|
+
return;
|
|
119
|
+
}
|
|
120
|
+
const activation = activations[0];
|
|
121
|
+
res.locals.activation = activation;
|
|
122
|
+
next();
|
|
123
|
+
};
|
|
124
|
+
}
|
|
125
|
+
return async (req, res, next) => {
|
|
126
|
+
if (!opts.connName) {
|
|
127
|
+
// This is mainly for type safety, but we should never reach this point
|
|
128
|
+
opts.log.error('Connection name is not defined for webhook middleware');
|
|
129
|
+
res.status(401).json({ error: 'Unauthorised' });
|
|
130
|
+
return;
|
|
131
|
+
}
|
|
132
|
+
const templateId = opts.cfgReader.getTemplateID(opts.connName);
|
|
133
|
+
const userId = req.params.userId;
|
|
134
|
+
const activations = await opts.cnxProvider.getUserActivations(userId);
|
|
135
|
+
if (activations.length === 0) {
|
|
136
|
+
res.status(401).json({ error: 'Unauthorised' });
|
|
137
|
+
return;
|
|
138
|
+
}
|
|
139
|
+
const activation = activations[0]; // Right now we only support a user having one activation
|
|
140
|
+
const conn = await opts.cnxProvider.getActivationConnection(templateId, activation.id);
|
|
141
|
+
if (conn === undefined) {
|
|
142
|
+
opts.log.error(`Connection not found for webhook: /${opts.id}/users/${userId}`);
|
|
143
|
+
res.status(401).json({ error: 'Unauthorised' });
|
|
144
|
+
return;
|
|
145
|
+
}
|
|
146
|
+
const key = await opts.credentials.getRaw(opts.connName, activation.id);
|
|
147
|
+
const asc = conn.credentials[0].authSchemeConfig;
|
|
148
|
+
if (!asc || !asc.hmac) {
|
|
149
|
+
opts.log.error('HMAC AuthSchemeConfig not found for webhook');
|
|
150
|
+
res.status(401).json({ error: 'Unauthorised' });
|
|
151
|
+
return;
|
|
152
|
+
}
|
|
153
|
+
const digest = createDigest(asc.hmac, req, key);
|
|
154
|
+
let requestDigest;
|
|
155
|
+
try {
|
|
156
|
+
requestDigest = extractDigest(asc.hmac, req);
|
|
157
|
+
}
|
|
158
|
+
catch (error) {
|
|
159
|
+
opts.log.error('Error extracting HMAC digest from request', { error });
|
|
160
|
+
res.status(401).json({ error: 'Unauthorised' });
|
|
161
|
+
return;
|
|
162
|
+
}
|
|
163
|
+
if (digest !== requestDigest) {
|
|
164
|
+
res.status(401).json({ error: 'Unauthorised' });
|
|
165
|
+
return;
|
|
166
|
+
}
|
|
167
|
+
res.locals.activation = activation;
|
|
168
|
+
next();
|
|
169
|
+
};
|
|
170
|
+
}
|
|
171
|
+
// createDigest creates a HMAC digest for the request using the provided key.
|
|
172
|
+
// Note that this assumes the request body is a JSON object, as one would normally
|
|
173
|
+
// expect for our use case.
|
|
174
|
+
// TODO: implement the case where we might want to digest the body + url or url + body
|
|
175
|
+
// or url...
|
|
176
|
+
function createDigest(asc, req, key) {
|
|
177
|
+
const hmac = (0, node_crypto_1.createHmac)(asc.algorithm, node_buffer_1.Buffer.from(key).toString('utf8'));
|
|
178
|
+
hmac.update(JSON.stringify(req.body));
|
|
179
|
+
return hmac.digest(asc.encoding);
|
|
180
|
+
}
|
|
181
|
+
function extractDigest(asc, req) {
|
|
182
|
+
switch (asc.in) {
|
|
183
|
+
case 'query':
|
|
184
|
+
if (req.query[asc.name]) {
|
|
185
|
+
return req.query[asc.name];
|
|
186
|
+
}
|
|
187
|
+
break;
|
|
188
|
+
case 'header':
|
|
189
|
+
if (req.headers[asc.name]) {
|
|
190
|
+
return req.headers[asc.name];
|
|
191
|
+
}
|
|
192
|
+
break;
|
|
193
|
+
case 'cookie':
|
|
194
|
+
if (req.cookies[asc.name]) {
|
|
195
|
+
return req.cookies[asc.name];
|
|
196
|
+
}
|
|
197
|
+
break;
|
|
198
|
+
default:
|
|
199
|
+
throw new Error(`Unsupported HMAC digest extraction method: ${asc.in}`);
|
|
200
|
+
}
|
|
201
|
+
throw new Error(`HMAC digest not found in request: ${asc.name}`);
|
|
202
|
+
}
|
|
@@ -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,mBAAm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AAI,CAEpB;IAED,IAAI,UAAU,IAAI,UAAU,GAAG,SAAS,CAEvC;IAED,IAAI,IAAI,IAAI,CAAC,CAEZ;IAED,MAAM,CAAC,KAAK,CAAC,EAAE,aAAa,GAAG,QAAQ;IAIvC,WAAW,IAAI,mBAAmB;IAIlC,IAAI,KAAK,IAAI,OAAO,UAAU,CAAC,KAAK,CAKnC;IAEK,QAAQ,CAAC,WAAW,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"}
|
|
@@ -129,7 +129,7 @@ class HttpContextImpl {
|
|
|
129
129
|
? (0, types_js_1.wrapDynamicFetcher)(__classPrivateFieldGet(this, _HttpContextImpl_dynamicFetcher, "f"), __classPrivateFieldGet(this, _HttpContextImpl_inner, "f").activation)
|
|
130
130
|
: __classPrivateFieldGet(this, _HttpContextImpl_staticFetcher, "f") ?? globalThis.fetch;
|
|
131
131
|
}
|
|
132
|
-
async nextPage(
|
|
132
|
+
async nextPage(_nextParams) {
|
|
133
133
|
throw new Error('Method not implemented.');
|
|
134
134
|
}
|
|
135
135
|
}
|
|
@@ -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,EAA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
|
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,CAAC;AAG7D,OAAO,EAA+B,UAAU,EAAM,YAAY,EAAO,MAAM,MAAM,CAAC;AACtF,OAAO,EAAE,eAAe,EAAuB,MAAM,kCAAkC,CAAC;AAExF,OAAO,EAAE,kBAAkB,EAAE,YAAY,EAAE,mBAAmB,EAAE,MAAM,yBAAyB,CAAC;
|
|
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,CAAC;AAG7D,OAAO,EAA+B,UAAU,EAAM,YAAY,EAAO,MAAM,MAAM,CAAC;AACtF,OAAO,EAAE,eAAe,EAAuB,MAAM,kCAAkC,CAAC;AAExF,OAAO,EAAE,YAAY,EAAE,kBAAkB,EAAE,YAAY,EAAE,mBAAmB,EAAE,MAAM,yBAAyB,CAAC;AAc9G,OAAO,EAAE,QAAQ,EAAgB,MAAM,uBAAuB,CAAC;AAG/D,OAAO,EAAE,WAAW,EAAE,uBAAuB,EAAoB,MAAM,cAAc,CAAC;AAEtF,OAAO,EAAE,MAAM,EAAE,MAAM,uCAAuC,CAAC;AAC/D,OAAO,EAAmB,kBAAkB,EAAE,MAAM,yBAAyB,CAAC;AAI9E,MAAM,MAAM,wBAAwB,GAAG;IACnC,MAAM,CAAC,EAAE,MAAM,CAA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Aa,EAAE,MAAM,EACrB,UAAU,EAAE,MAAM,EAC3B,YAAY,EAAE,GAAG,CAAC,MAAM,EAAE,MAAM,CAAC,EACxB,kBAAkB,EAAE,kBAAkB,EACtC,YAAY,EAAE,YAAY,EAC1B,MAAM,EAAE,MAAM,EACd,SAAS,EAAE,YAAY,EACvB,OAAO,CAAC,EAAE,OAAO,YAAA;WAWzB,WAAW,CAAC,OAAO,GAAE,wBAA6B,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"}
|
|
@@ -23,6 +23,7 @@ const NatsKeyValueProvider_js_1 = require("../../kv/nats/NatsKeyValueProvider.js
|
|
|
23
23
|
const ConsoleLogger_js_1 = require("../../observability/logging/ConsoleLogger.js");
|
|
24
24
|
const ObservableCompiler_js_1 = require("./ObservableCompiler.js");
|
|
25
25
|
const proxyroundtripper_js_1 = require("../../dsl/http/versori/proxyroundtripper.js");
|
|
26
|
+
const configloader_js_1 = require("../../dsl/http/versori/configloader.js");
|
|
26
27
|
function getKVProvider(runLocal) {
|
|
27
28
|
if (runLocal) {
|
|
28
29
|
return Promise.resolve(new MemoryKeyValueProvider_js_1.MemoryKeyValueProvider());
|
|
@@ -41,7 +42,7 @@ function getRoundTripperFactory(log, tracer, opts) {
|
|
|
41
42
|
return new default_js_1.DefaultRoundTripperFactory();
|
|
42
43
|
}
|
|
43
44
|
class MemoryInterpreter {
|
|
44
|
-
constructor(log, compiler, contextProvider, roundTripperFactory,
|
|
45
|
+
constructor(log, compiler, contextProvider, roundTripperFactory, webhookRouter, cronRouter, cronRegistry, connectionProvider, cronProvider, tracer, cfgReader, otelSDK) {
|
|
45
46
|
Object.defineProperty(this, "log", {
|
|
46
47
|
enumerable: true,
|
|
47
48
|
configurable: true,
|
|
@@ -66,11 +67,17 @@ class MemoryInterpreter {
|
|
|
66
67
|
writable: true,
|
|
67
68
|
value: roundTripperFactory
|
|
68
69
|
});
|
|
69
|
-
Object.defineProperty(this, "
|
|
70
|
+
Object.defineProperty(this, "webhookRouter", {
|
|
70
71
|
enumerable: true,
|
|
71
72
|
configurable: true,
|
|
72
73
|
writable: true,
|
|
73
|
-
value:
|
|
74
|
+
value: webhookRouter
|
|
75
|
+
});
|
|
76
|
+
Object.defineProperty(this, "cronRouter", {
|
|
77
|
+
enumerable: true,
|
|
78
|
+
configurable: true,
|
|
79
|
+
writable: true,
|
|
80
|
+
value: cronRouter
|
|
74
81
|
});
|
|
75
82
|
Object.defineProperty(this, "cronRegistry", {
|
|
76
83
|
enumerable: true,
|
|
@@ -96,6 +103,12 @@ class MemoryInterpreter {
|
|
|
96
103
|
writable: true,
|
|
97
104
|
value: tracer
|
|
98
105
|
});
|
|
106
|
+
Object.defineProperty(this, "cfgReader", {
|
|
107
|
+
enumerable: true,
|
|
108
|
+
configurable: true,
|
|
109
|
+
writable: true,
|
|
110
|
+
value: cfgReader
|
|
111
|
+
});
|
|
99
112
|
Object.defineProperty(this, "otelSDK", {
|
|
100
113
|
enumerable: true,
|
|
101
114
|
configurable: true,
|
|
@@ -108,7 +121,13 @@ class MemoryInterpreter {
|
|
|
108
121
|
writable: true,
|
|
109
122
|
value: []
|
|
110
123
|
});
|
|
111
|
-
Object.defineProperty(this, "
|
|
124
|
+
Object.defineProperty(this, "webhookServer", {
|
|
125
|
+
enumerable: true,
|
|
126
|
+
configurable: true,
|
|
127
|
+
writable: true,
|
|
128
|
+
value: void 0
|
|
129
|
+
});
|
|
130
|
+
Object.defineProperty(this, "cronServer", {
|
|
112
131
|
enumerable: true,
|
|
113
132
|
configurable: true,
|
|
114
133
|
writable: true,
|
|
@@ -143,6 +162,7 @@ class MemoryInterpreter {
|
|
|
143
162
|
const orgSlug = Deno.env.get(constants_js_1.envVarOrgSlug) || 'development';
|
|
144
163
|
const otelTracesURL = Deno.env.get(constants_js_1.envVarOtelTracesURL);
|
|
145
164
|
let otelSDK;
|
|
165
|
+
const configReader = configloader_js_1.VersoriConfigReader.fromEnv(log);
|
|
146
166
|
const runLocal = Deno.env.get(constants_js_1.envVarLocalRun) === 'true';
|
|
147
167
|
await waitForReady(log);
|
|
148
168
|
// Do NOT change those attributes, they are used by the API to filter on
|
|
@@ -173,10 +193,10 @@ class MemoryInterpreter {
|
|
|
173
193
|
if (options.contextProvider) {
|
|
174
194
|
// no need to set up a key-value provider if options.contextProvider is already
|
|
175
195
|
// initialised.
|
|
176
|
-
return new MemoryInterpreter(log, compiler, options.contextProvider, roundTripperFactory, express_1.default.Router(), new Map(), platformapi_js_1.PlatformAPIClient.fromEnv(), cronapi_js_1.CronAPIClient.fromEnv(), tracer, otelSDK);
|
|
196
|
+
return new MemoryInterpreter(log, compiler, options.contextProvider, roundTripperFactory, express_1.default.Router(), express_1.default.Router(), new Map(), platformapi_js_1.PlatformAPIClient.fromEnv(), cronapi_js_1.CronAPIClient.fromEnv(), tracer, configReader, otelSDK);
|
|
177
197
|
}
|
|
178
198
|
const kvp = await getKVProvider(runLocal);
|
|
179
|
-
return new MemoryInterpreter(log, compiler, new ContextProvider_js_1.ContextProviderImpl(log, kvp, roundTripperFactory.credentials()), roundTripperFactory, express_1.default.Router(), new Map(), platformapi_js_1.PlatformAPIClient.fromEnv(), cronapi_js_1.CronAPIClient.fromEnv(), tracer, otelSDK);
|
|
199
|
+
return new MemoryInterpreter(log, compiler, new ContextProvider_js_1.ContextProviderImpl(log, kvp, roundTripperFactory.credentials()), roundTripperFactory, express_1.default.Router(), express_1.default.Router(), new Map(), platformapi_js_1.PlatformAPIClient.fromEnv(), cronapi_js_1.CronAPIClient.fromEnv(), tracer, configReader, otelSDK);
|
|
180
200
|
}
|
|
181
201
|
register(workflow, options) {
|
|
182
202
|
const localAbortController = new AbortController();
|
|
@@ -193,9 +213,11 @@ class MemoryInterpreter {
|
|
|
193
213
|
tracer: this.tracer,
|
|
194
214
|
contextProvider: this.contextProvider,
|
|
195
215
|
roundTripperFactory: this.roundTripperFactory,
|
|
196
|
-
|
|
216
|
+
webhookRouter: this.webhookRouter,
|
|
217
|
+
cronRouter: this.cronRouter,
|
|
197
218
|
cronRegistry: this.cronRegistry,
|
|
198
219
|
connectionProvider: this.connectionProvider,
|
|
220
|
+
configReader: this.cfgReader,
|
|
199
221
|
};
|
|
200
222
|
const trigger$ = this.compiler.compileTrigger(compilerContext, workflow.trigger, combinedSignal);
|
|
201
223
|
const task$ = this.compiler.compileTask(compilerContext, workflow.task);
|
|
@@ -213,21 +235,28 @@ class MemoryInterpreter {
|
|
|
213
235
|
}
|
|
214
236
|
async start() {
|
|
215
237
|
const port = Deno.env.get('PORT') || 3000;
|
|
216
|
-
const
|
|
217
|
-
|
|
238
|
+
const cronPort = Deno.env.get('CRON_PORT') || 3001;
|
|
239
|
+
const webhookApp = (0, express_1.default)();
|
|
240
|
+
webhookApp.use(express_1.default.json()); // Add JSON body parser middleware
|
|
241
|
+
const cronApp = (0, express_1.default)();
|
|
242
|
+
cronApp.use(express_1.default.json());
|
|
218
243
|
const xml2jsDefaults = {
|
|
219
244
|
explicitArray: false,
|
|
220
245
|
normalize: false,
|
|
221
246
|
normalizeTags: false,
|
|
222
247
|
trim: true,
|
|
223
248
|
};
|
|
224
|
-
|
|
249
|
+
webhookApp.use((0, express_xml_bodyparser_1.default)(xml2jsDefaults));
|
|
225
250
|
// Add health check route
|
|
226
|
-
this.
|
|
251
|
+
this.webhookRouter.get('/health', (_req, res) => {
|
|
252
|
+
res.json({ status: 'healthy' });
|
|
253
|
+
});
|
|
254
|
+
this.cronRouter.get('/health', (_req, res) => {
|
|
227
255
|
res.json({ status: 'healthy' });
|
|
228
256
|
});
|
|
229
|
-
// Add router to the
|
|
230
|
-
|
|
257
|
+
// Add router to the webhookApplication
|
|
258
|
+
webhookApp.use(this.webhookRouter);
|
|
259
|
+
cronApp.use(this.cronRouter);
|
|
231
260
|
// Start all registered workflows
|
|
232
261
|
for (const registration of this.registeredWorkflows) {
|
|
233
262
|
Deno.addSignalListener('SIGINT', registration.sigintListener);
|
|
@@ -293,9 +322,12 @@ class MemoryInterpreter {
|
|
|
293
322
|
});
|
|
294
323
|
throw new Error('Unable to register scheduler tasks with central cron provider');
|
|
295
324
|
}
|
|
296
|
-
this.
|
|
325
|
+
this.webhookServer = webhookApp.listen(port, () => {
|
|
297
326
|
this.log.info(`Express server listening on http://localhost:${port}`);
|
|
298
327
|
});
|
|
328
|
+
this.cronServer = cronApp.listen(cronPort, () => {
|
|
329
|
+
this.log.info(`Cron server listening on http://localhost:${cronPort}`);
|
|
330
|
+
});
|
|
299
331
|
this.shutdownServer = () => {
|
|
300
332
|
if (this.isShuttingDown) {
|
|
301
333
|
return;
|
|
@@ -303,8 +335,11 @@ class MemoryInterpreter {
|
|
|
303
335
|
this.isShuttingDown = true;
|
|
304
336
|
this.log.info('Shutting down server');
|
|
305
337
|
// Close the server
|
|
306
|
-
if (this.
|
|
307
|
-
this.
|
|
338
|
+
if (this.webhookServer) {
|
|
339
|
+
this.webhookServer.close();
|
|
340
|
+
}
|
|
341
|
+
if (this.cronServer) {
|
|
342
|
+
this.cronServer.close();
|
|
308
343
|
}
|
|
309
344
|
// Remove all signal listeners
|
|
310
345
|
for (const registration of this.registeredWorkflows) {
|
|
@@ -323,13 +358,28 @@ class MemoryInterpreter {
|
|
|
323
358
|
};
|
|
324
359
|
Deno.addSignalListener('SIGINT', this.shutdownServer);
|
|
325
360
|
return new Promise((resolve) => {
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
361
|
+
let serversClosed = 0;
|
|
362
|
+
const totalServers = [this.webhookServer, this.cronServer].filter(Boolean).length;
|
|
363
|
+
const checkResolve = () => {
|
|
364
|
+
serversClosed++;
|
|
365
|
+
if (serversClosed === totalServers) {
|
|
366
|
+
this.log.info('All servers closed');
|
|
329
367
|
resolve();
|
|
368
|
+
}
|
|
369
|
+
};
|
|
370
|
+
if (this.webhookServer) {
|
|
371
|
+
this.webhookServer.on('close', () => {
|
|
372
|
+
this.log.info('Webhook server closed');
|
|
373
|
+
checkResolve();
|
|
374
|
+
});
|
|
375
|
+
}
|
|
376
|
+
if (this.cronServer) {
|
|
377
|
+
this.cronServer.on('close', () => {
|
|
378
|
+
this.log.info('Cron server closed');
|
|
379
|
+
checkResolve();
|
|
330
380
|
});
|
|
331
381
|
}
|
|
332
|
-
|
|
382
|
+
if (!this.webhookServer && !this.cronServer) {
|
|
333
383
|
resolve();
|
|
334
384
|
}
|
|
335
385
|
});
|
|
@@ -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,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,YAAY,EAAE,kBAAkB,EAAE,mBAAmB,EAAE,MAAM,yBAAyB,CAAC;AAChG,OAAO,EAAE,MAAM,EAAE,MAAM,SAAS,CAAC;AACjC,OAAO,EAAE,MAAM,EAAE,MAAM,oBAAoB,CAAC;AAE5C,MAAM,MAAM,eAAe,GAA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C,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"}
|
|
@@ -7,7 +7,7 @@ const ScheduleTrigger_js_1 = require("../../../dsl/triggers/ScheduleTrigger.js")
|
|
|
7
7
|
function compileSchedule(ctx, trigger, signal) {
|
|
8
8
|
return new rxjs_1.Observable((subscriber) => {
|
|
9
9
|
// Add HTTP endpoint for manual triggering
|
|
10
|
-
if (!ctx.
|
|
10
|
+
if (!ctx.cronRouter) {
|
|
11
11
|
throw new Error('Router not available in compiler context');
|
|
12
12
|
}
|
|
13
13
|
const projectId = Deno.env.get(constants_js_1.envVarProjectId) || 'example-service';
|
|
@@ -68,7 +68,7 @@ function compileSchedule(ctx, trigger, signal) {
|
|
|
68
68
|
res.status(500).json({ error: 'Failed to trigger schedule' });
|
|
69
69
|
}
|
|
70
70
|
}
|
|
71
|
-
ctx.
|
|
71
|
+
ctx.cronRouter.post(`/cron/${trigger.id}`, async (req, res) => {
|
|
72
72
|
await ctx.tracer.startActiveSpan(`schedule-${trigger.id}`, async (span) => {
|
|
73
73
|
span.setAttribute('task.id', trigger.id);
|
|
74
74
|
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"}
|