@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.
Files changed (93) hide show
  1. package/esm/src/context/Context.d.ts +4 -4
  2. package/esm/src/context/Context.d.ts.map +1 -1
  3. package/esm/src/context/ContextProvider.d.ts +3 -3
  4. package/esm/src/context/ContextProvider.d.ts.map +1 -1
  5. package/esm/src/dsl/http/default.d.ts +4 -4
  6. package/esm/src/dsl/http/default.d.ts.map +1 -1
  7. package/esm/src/dsl/http/default.js +3 -3
  8. package/esm/src/dsl/http/types.d.ts +8 -2
  9. package/esm/src/dsl/http/types.d.ts.map +1 -1
  10. package/esm/src/dsl/http/versori/configloader.d.ts +10 -1
  11. package/esm/src/dsl/http/versori/configloader.d.ts.map +1 -1
  12. package/esm/src/dsl/http/versori/configloader.js +37 -0
  13. package/esm/src/dsl/http/versori/constants.d.ts +1 -0
  14. package/esm/src/dsl/http/versori/constants.d.ts.map +1 -1
  15. package/esm/src/dsl/http/versori/constants.js +2 -0
  16. package/esm/src/dsl/http/versori/contextcredentials.d.ts +0 -4
  17. package/esm/src/dsl/http/versori/contextcredentials.d.ts.map +1 -1
  18. package/esm/src/dsl/http/versori/cronapi.d.ts.map +1 -1
  19. package/esm/src/dsl/http/versori/cronapi.js +2 -2
  20. package/esm/src/dsl/http/versori/proxyroundtripper.d.ts +5 -7
  21. package/esm/src/dsl/http/versori/proxyroundtripper.d.ts.map +1 -1
  22. package/esm/src/dsl/http/versori/proxyroundtripper.js +10 -24
  23. package/esm/src/dsl/http/versori/roundtripper.d.ts +5 -7
  24. package/esm/src/dsl/http/versori/roundtripper.d.ts.map +1 -1
  25. package/esm/src/dsl/http/versori/roundtripper.js +11 -24
  26. package/esm/src/dsl/http/versori/webhookmiddleware.d.ts +16 -0
  27. package/esm/src/dsl/http/versori/webhookmiddleware.d.ts.map +1 -0
  28. package/esm/src/dsl/http/versori/webhookmiddleware.js +197 -0
  29. package/esm/src/dsl/tasks/HttpTask.d.ts +3 -3
  30. package/esm/src/dsl/tasks/HttpTask.d.ts.map +1 -1
  31. package/esm/src/dsl/tasks/HttpTask.js +1 -1
  32. package/esm/src/dsl/triggers/WebhookTrigger.d.ts +1 -0
  33. package/esm/src/dsl/triggers/WebhookTrigger.d.ts.map +1 -1
  34. package/esm/src/interpreter/memory/MemoryInterpreter.d.ts +7 -4
  35. package/esm/src/interpreter/memory/MemoryInterpreter.d.ts.map +1 -1
  36. package/esm/src/interpreter/memory/MemoryInterpreter.js +70 -20
  37. package/esm/src/interpreter/memory/ObservableCompiler.d.ts +4 -2
  38. package/esm/src/interpreter/memory/ObservableCompiler.d.ts.map +1 -1
  39. package/esm/src/interpreter/memory/compilers/schedule.js +2 -2
  40. package/esm/src/interpreter/memory/compilers/webhook.d.ts.map +1 -1
  41. package/esm/src/interpreter/memory/compilers/webhook.js +38 -12
  42. package/esm/src/observability/logging/ConsoleLogger.d.ts +1 -0
  43. package/esm/src/observability/logging/ConsoleLogger.d.ts.map +1 -1
  44. package/esm/src/observability/logging/ConsoleLogger.js +7 -0
  45. package/esm/src/observability/logging/Logger.d.ts +2 -1
  46. package/esm/src/observability/logging/Logger.d.ts.map +1 -1
  47. package/package.json +1 -1
  48. package/script/src/context/Context.d.ts +4 -4
  49. package/script/src/context/Context.d.ts.map +1 -1
  50. package/script/src/context/ContextProvider.d.ts +3 -3
  51. package/script/src/context/ContextProvider.d.ts.map +1 -1
  52. package/script/src/dsl/http/default.d.ts +4 -4
  53. package/script/src/dsl/http/default.d.ts.map +1 -1
  54. package/script/src/dsl/http/default.js +3 -3
  55. package/script/src/dsl/http/types.d.ts +8 -2
  56. package/script/src/dsl/http/types.d.ts.map +1 -1
  57. package/script/src/dsl/http/versori/configloader.d.ts +10 -1
  58. package/script/src/dsl/http/versori/configloader.d.ts.map +1 -1
  59. package/script/src/dsl/http/versori/configloader.js +39 -0
  60. package/script/src/dsl/http/versori/constants.d.ts +1 -0
  61. package/script/src/dsl/http/versori/constants.d.ts.map +1 -1
  62. package/script/src/dsl/http/versori/constants.js +3 -1
  63. package/script/src/dsl/http/versori/contextcredentials.d.ts +0 -4
  64. package/script/src/dsl/http/versori/contextcredentials.d.ts.map +1 -1
  65. package/script/src/dsl/http/versori/cronapi.d.ts.map +1 -1
  66. package/script/src/dsl/http/versori/cronapi.js +1 -1
  67. package/script/src/dsl/http/versori/proxyroundtripper.d.ts +5 -7
  68. package/script/src/dsl/http/versori/proxyroundtripper.d.ts.map +1 -1
  69. package/script/src/dsl/http/versori/proxyroundtripper.js +9 -23
  70. package/script/src/dsl/http/versori/roundtripper.d.ts +5 -7
  71. package/script/src/dsl/http/versori/roundtripper.d.ts.map +1 -1
  72. package/script/src/dsl/http/versori/roundtripper.js +10 -23
  73. package/script/src/dsl/http/versori/webhookmiddleware.d.ts +16 -0
  74. package/script/src/dsl/http/versori/webhookmiddleware.d.ts.map +1 -0
  75. package/script/src/dsl/http/versori/webhookmiddleware.js +202 -0
  76. package/script/src/dsl/tasks/HttpTask.d.ts +3 -3
  77. package/script/src/dsl/tasks/HttpTask.d.ts.map +1 -1
  78. package/script/src/dsl/tasks/HttpTask.js +1 -1
  79. package/script/src/dsl/triggers/WebhookTrigger.d.ts +1 -0
  80. package/script/src/dsl/triggers/WebhookTrigger.d.ts.map +1 -1
  81. package/script/src/interpreter/memory/MemoryInterpreter.d.ts +7 -4
  82. package/script/src/interpreter/memory/MemoryInterpreter.d.ts.map +1 -1
  83. package/script/src/interpreter/memory/MemoryInterpreter.js +70 -20
  84. package/script/src/interpreter/memory/ObservableCompiler.d.ts +4 -2
  85. package/script/src/interpreter/memory/ObservableCompiler.d.ts.map +1 -1
  86. package/script/src/interpreter/memory/compilers/schedule.js +2 -2
  87. package/script/src/interpreter/memory/compilers/webhook.d.ts.map +1 -1
  88. package/script/src/interpreter/memory/compilers/webhook.js +38 -12
  89. package/script/src/observability/logging/ConsoleLogger.d.ts +1 -0
  90. package/script/src/observability/logging/ConsoleLogger.d.ts.map +1 -1
  91. package/script/src/observability/logging/ConsoleLogger.js +7 -0
  92. package/script/src/observability/logging/Logger.d.ts +2 -1
  93. package/script/src/observability/logging/Logger.d.ts.map +1 -1
@@ -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, router, cronRegistry, connectionProvider, cronProvider, tracer, otelSDK) {
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, "router", {
70
+ Object.defineProperty(this, "webhookRouter", {
70
71
  enumerable: true,
71
72
  configurable: true,
72
73
  writable: true,
73
- value: router
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, "server", {
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
- router: this.router,
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 app = (0, express_1.default)();
217
- app.use(express_1.default.json()); // Add JSON body parser middleware
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
- app.use((0, express_xml_bodyparser_1.default)(xml2jsDefaults));
249
+ webhookApp.use((0, express_xml_bodyparser_1.default)(xml2jsDefaults));
225
250
  // Add health check route
226
- this.router.get('/health', (_req, res) => {
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 application
230
- app.use(this.router);
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.server = app.listen(port, () => {
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.server) {
307
- this.server.close();
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
- if (this.server) {
327
- this.server.on('close', () => {
328
- this.log.info('Server closed');
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
- else {
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
- router: Router;
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,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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.router) {
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.router.post(`/cron/${trigger.id}`, async (req, res) => {
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;AAgD7C,eAAO,MAAM,eAAe,EAAE,eAAe,CAAC,WAAW,EAAE,cAAc,CA+PxE,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"}
@@ -8,6 +8,7 @@ const cors_1 = __importDefault(require("cors"));
8
8
  const promises_1 = require("node:stream/promises");
9
9
  const rxjs_1 = require("rxjs");
10
10
  const WebhookTrigger_js_1 = require("../../../dsl/triggers/WebhookTrigger.js");
11
+ const webhookmiddleware_js_1 = require("../../../dsl/http/versori/webhookmiddleware.js");
11
12
  const DEFAULT_SYNC_ON_SUCCESS = (ctx) => new Response(JSON.stringify(ctx.data), {
12
13
  status: 200,
13
14
  headers: {
@@ -72,28 +73,35 @@ exports.webhookCompiler = {
72
73
  },
73
74
  });
74
75
  return new rxjs_1.Observable((subscriber) => {
75
- if (!ctx.router) {
76
+ if (!ctx.webhookRouter) {
76
77
  throw new Error('Router not available in compiler context');
77
78
  }
78
79
  // add the webhook endpoint to the router
79
80
  ctx.log.info('webhook endpoint added:', { trigger });
80
81
  if (corsOptions) {
81
82
  if (typeof corsOptions === 'boolean') {
82
- ctx.router.use((0, cors_1.default)());
83
+ ctx.webhookRouter.use((0, cors_1.default)());
83
84
  }
84
85
  else {
85
- ctx.router.use((0, cors_1.default)(corsOptions));
86
+ ctx.webhookRouter.use((0, cors_1.default)(corsOptions));
86
87
  }
87
88
  }
88
89
  // endpoint for sans user because I'm not quite sure how the dynamic routing works
89
- ctx.router.post(`/${trigger.id}`, async (req, res) => {
90
+ ctx.webhookRouter.post(`/${trigger.id}`, (0, webhookmiddleware_js_1.createStaticWebhookMiddleware)({
91
+ id: trigger.id,
92
+ connName: trigger.options.connection,
93
+ credentials: ctx.roundTripperFactory.credentials(),
94
+ cnxProvider: ctx.connectionProvider,
95
+ cfgReader: ctx.configReader,
96
+ log: ctx.log,
97
+ }), async (req, res) => {
90
98
  await ctx.tracer.startActiveSpan(`webhook-${trigger.id}`, async (span) => {
91
99
  span.setAttribute('task.id', trigger.id);
92
100
  span.setAttribute('task.type', 'webhook');
93
101
  let executionCtx = ctx.contextProvider.create(req.body, ctxOptionsFn(res));
94
- const activation = await ctx.connectionProvider.getStaticActivation();
95
- if (activation) {
96
- executionCtx = executionCtx.withActivation(activation);
102
+ const staticActivation = res.locals.activation;
103
+ if (staticActivation) {
104
+ executionCtx = executionCtx.withActivation(staticActivation);
97
105
  }
98
106
  span.setAttribute('execution.id', executionCtx.executionId);
99
107
  try {
@@ -116,13 +124,24 @@ exports.webhookCompiler = {
116
124
  });
117
125
  });
118
126
  // this endpoint will trigger the workflow for each activation given by the external user ID
119
- ctx.router.post(`/${trigger.id}/users/:userId`, async (req, res) => {
127
+ ctx.webhookRouter.post(`/${trigger.id}/users/:userId`, (0, webhookmiddleware_js_1.createUserIdDynamicWebhookMiddleware)({
128
+ id: trigger.id,
129
+ connName: trigger.options.connection,
130
+ credentials: ctx.roundTripperFactory.credentials(),
131
+ cnxProvider: ctx.connectionProvider,
132
+ cfgReader: ctx.configReader,
133
+ log: ctx.log,
134
+ }), async (req, res) => {
120
135
  await ctx.tracer.startActiveSpan(`webhook-${trigger.id}`, async (span) => {
121
136
  span.setAttribute('task.id', trigger.id);
122
137
  span.setAttribute('task.type', 'webhook');
123
138
  span.setAttribute('user.id', req.params.userId);
124
139
  const userId = req.params.userId;
125
- const activations = await ctx.connectionProvider.getUserActivations(userId);
140
+ const activation = res.locals.activation;
141
+ const activations = [activation];
142
+ // Right now we only support a user having one activation
143
+ // so this will need changing when we support multiple activations per user
144
+ // as will the middleware
126
145
  if (!activations || activations.length === 0) {
127
146
  res.status(404).json({
128
147
  status: 'error',
@@ -163,13 +182,20 @@ exports.webhookCompiler = {
163
182
  });
164
183
  });
165
184
  // this endpoint will trigger the workflow only for the activation given by its ID
166
- ctx.router.post(`/${trigger.id}/activations/:activationId`, async (req, res) => {
185
+ ctx.webhookRouter.post(`/${trigger.id}/activations/:activationId`, (0, webhookmiddleware_js_1.createActIdDynamicWebhookMiddleware)({
186
+ id: trigger.id,
187
+ connName: trigger.options.connection,
188
+ credentials: ctx.roundTripperFactory.credentials(),
189
+ cnxProvider: ctx.connectionProvider,
190
+ cfgReader: ctx.configReader,
191
+ log: ctx.log,
192
+ }), async (req, res) => {
167
193
  await ctx.tracer.startActiveSpan(`webhook-${trigger.id}`, async (span) => {
168
194
  span.setAttribute('task.id', trigger.id);
169
195
  span.setAttribute('task.type', 'webhook');
170
196
  span.setAttribute('activation.id', req.params.activationId);
171
- const activationId = req.params.activationId;
172
- const activation = await ctx.connectionProvider.getActivation(activationId);
197
+ const activation = res.locals.activation;
198
+ const activationId = activation.id || req.params.activationId;
173
199
  if (!activation) {
174
200
  // TODO report back actual errors
175
201
  res.status(404).json({
@@ -9,6 +9,7 @@ export declare class ConsoleLogger implements Logger {
9
9
  fields: Record<string, unknown>;
10
10
  constructor(level: LogLevel, fields?: Record<string, unknown>);
11
11
  debug(message: string, fields?: Record<string, unknown>): void;
12
+ warn(message: string, fields?: Record<string, unknown>): void;
12
13
  info(message: string, fields?: Record<string, unknown>): void;
13
14
  error(message: string, err?: Error, fields?: Record<string, unknown>): void;
14
15
  error(message: string, fields?: Record<string, unknown>): void;
@@ -1 +1 @@
1
- {"version":3,"file":"ConsoleLogger.d.ts","sourceRoot":"","sources":["../../../../src/src/observability/logging/ConsoleLogger.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,GAAG,MAAM,+CAA+C,CAAC;AACrE,OAAO,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,aAAa,CAAC;AAoM/C;;GAEG;AACH,qBAAa,aAAc,YAAW,MAAM;IACxC,GAAG,EAAE,GAAG,CAAC,MAAM,CAAC;IAEhB,KAAK,EAAE,QAAQ,CAAC;IAEhB,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;gBAEpB,KAAK,EAAE,QAAQ,EAAE,MAAM,GAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAM;IAOjE,KAAK,CAAC,OAAO,EAAE,MAAM,EAAE,MAAM,CAAC,E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AAO,CAAC,GAAG,IAAI;IAO7D,IAAI,CAAC,OAAO,EAAE,MAAM,EAAE,MAAM,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,IAAI;IAO7D,KAAK,CAAC,OAAO,EAAE,MAAM,EAAE,GAAG,CAAC,EAAE,KAAK,EAAE,MAAM,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,IAAI;IAC3E,KAAK,CAAC,OAAO,EAAE,MAAM,EAAE,MAAM,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,IAAI;IAsB9D,KAAK,CAAC,MAAM,EAAE;QAAE,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,CAAA;KAAE,GAAG,aAAa;IAOvD,QAAQ,CAAC,KAAK,EAAE,QAAQ,GAAG,IAAI;CAGlC"}
@@ -181,6 +181,7 @@ log.setup({
181
181
  });
182
182
  const levelMap = {
183
183
  debug: log.getLevelByName('DEBUG'),
184
+ warn: log.getLevelByName('WARN'),
184
185
  info: log.getLevelByName('INFO'),
185
186
  error: log.getLevelByName('ERROR'),
186
187
  };
@@ -218,6 +219,12 @@ class ConsoleLogger {
218
219
  ...fields,
219
220
  });
220
221
  }
222
+ warn(message, fields) {
223
+ this.log.warn(message, {
224
+ ...this.fields,
225
+ ...fields,
226
+ });
227
+ }
221
228
  info(message, fields) {
222
229
  this.log.info(message, {
223
230
  ...this.fields,
@@ -1,7 +1,8 @@
1
- export type LogLevel = 'debug' | 'info' | 'error';
1
+ export type LogLevel = 'debug' | 'warn' | 'info' | 'error';
2
2
  export interface Logger {
3
3
  level: LogLevel;
4
4
  debug(message: string, fields?: Record<string, unknown>): void;
5
+ warn(message: string, fields?: Record<string, unknown>): void;
5
6
  info(message: string, fields?: Record<string, unknown>): void;
6
7
  error(message: string, fields?: Record<string, unknown>): void;
7
8
  child(fields: {
@@ -1 +1 @@
1
- {"version":3,"file":"Logger.d.ts","sourceRoot":"","sources":["../../../../src/src/observability/logging/Logger.ts"],"names":[],"mappings":"AAAA,MAAM,MAAM,QAAQ,GAAG,OAAO,GAAG,MAAM,GAAG,OAAO,CAAC;AAElD,MAAM,WAAW,MAAM;IACnB,KAAK,EAAE,QAAQ,CAAC;IAEhB,KAAK,CAAC,OAAO,EAAE,MAAM,EAAE,MAAM,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,IAAI,CAAC;IAE/D,IAAI,CAAC,OAAO,EAAE,MAAM,EAAE,MAAM,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,IAAI,CAAC;IAE9D,KAAK,CAAC,OAAO,EAAE,MAAM,EAAE,MAAM,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,IAAI,CAAC;IAE/D,KAAK,CAAC,MAAM,EAAE;QAAE,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,CAAA;KAAE,GAAG,MAAM,CAAC;IAEjD,QAAQ,CAAC,KAAK,EAAE,QAAQ,GAAG,IAAI,CAAC;CACnC"}
1
+ {"version":3,"file":"Logger.d.ts","sourceRoot":"","sources":["../../../../src/src/observability/logging/Logger.ts"],"names":[],"mappings":"AAAA,MAAM,MAAM,QAAQ,GAAG,OAAO,GAAG,MAAM,GAAG,MAAM,GAAG,OAAO,CAAC;AAE3D,MAAM,WAAW,MAAM;IACnB,KAAK,EAAE,QAAQ,CAAC;IAEhB,KAAK,CAAC,OAAO,EAAE,MAAM,EAAE,MAAM,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,IAAI,CAAC;IAE/D,IAAI,CAAC,OAAO,EAAE,MAAM,EAAE,MAAM,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,IAAI,CAAC;IAE9D,IAAI,CAAC,OAAO,EAAE,MAAM,EAAE,MAAM,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,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