@versori/run 0.4.0-alpha.3 → 0.4.0-alpha.4

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.
@@ -1 +1 @@
1
- {"version":3,"file":"http.d.ts","sourceRoot":"","sources":["../../../../../src/src/interpreter/durable/compilers/http.ts"],"names":[],"mappings":"AAOA,OAAO,EAAmB,YAAY,EAAE,MAAM,gCAAgC,CAAC;AAG/E,OAAO,EAA2B,YAAY,EAAE,MAAM,YAAY,CAAC;AAwFnE,eAAO,MAAM,YAAY,EAAE,YAAY,CAAC,GAAG,EAAE,GAAG,EAAE,YAAY,CAAC,GAAG,EAAE,GAAG,EAAE,GAAG,CAAC,CAG5E,CAAC"}
1
+ {"version":3,"file":"http.d.ts","sourceRoot":"","sources":["../../../../../src/src/interpreter/durable/compilers/http.ts"],"names":[],"mappings":"AAQA,OAAO,EAAmB,YAAY,EAAE,MAAM,gCAAgC,CAAC;AAG/E,OAAO,EAA2B,YAAY,EAAE,MAAM,YAAY,CAAC;AAmHnE,eAAO,MAAM,YAAY,EAAE,YAAY,CAAC,GAAG,EAAE,GAAG,EAAE,YAAY,CAAC,GAAG,EAAE,GAAG,EAAE,GAAG,CAAC,CAG5E,CAAC"}
@@ -1,6 +1,7 @@
1
1
  import { mergeMap } from 'rxjs';
2
2
  import { tap } from 'rxjs/operators';
3
3
  import { DynamicFetchFactory } from '../../../connection/DynamicFetchFactory.js';
4
+ import { FetchBuilder } from '../../../connection/internal/FetchBuilder.js';
4
5
  import { StaticFetchFactory } from '../../../connection/StaticFetchFactory.js';
5
6
  import { HttpContextImpl, HttpTaskImpl } from '../../../dsl/tasks/HttpTask.js';
6
7
  import { enabled as supervisorEnabled } from '../../../internal/supervisor.js';
@@ -8,11 +9,23 @@ function compileHttp(compilerCtx, task) {
8
9
  const cnxMap = compilerCtx.configReader.getCnxMapping(task.opts.connection);
9
10
  let fetchFactory;
10
11
  if (!cnxMap) {
11
- compilerCtx.log.error(`Connection ${task.opts.connection} not found, using default fetch with no credentials`);
12
- fetchFactory = Promise.resolve(new StaticFetchFactory(globalThis.fetch));
12
+ compilerCtx.log.warn(`Connection ${task.opts.connection} not found, using default fetch with no credentials`);
13
+ if (supervisorEnabled) {
14
+ // missing connection map and we are in supervised mode, so we use the fake fetcher
15
+ fetchFactory = Promise.resolve(new StaticFetchFactory(new FetchBuilder(globalThis.fetch).buildSupervisedFetch()));
16
+ }
17
+ else {
18
+ // missing connection map and not in supervised mode, so we use global fetch
19
+ fetchFactory = Promise.resolve(new StaticFetchFactory(globalThis.fetch));
20
+ }
13
21
  }
14
22
  else if (cnxMap.dynamic) {
15
- fetchFactory = Promise.resolve(new DynamicFetchFactory(compilerCtx.cnxFactory, compilerCtx.platformApi, compilerCtx.organisationId, cnxMap.templateId));
23
+ if (cnxMap.mockWithAI) {
24
+ fetchFactory = Promise.resolve(new StaticFetchFactory(new FetchBuilder(globalThis.fetch).buildSupervisedFetch()));
25
+ }
26
+ else {
27
+ fetchFactory = Promise.resolve(new DynamicFetchFactory(compilerCtx.cnxFactory, compilerCtx.platformApi, compilerCtx.organisationId, cnxMap.templateId));
28
+ }
16
29
  }
17
30
  else {
18
31
  fetchFactory = compilerCtx.platformApi.getConnection({
@@ -22,8 +35,21 @@ function compileHttp(compilerCtx, task) {
22
35
  },
23
36
  throwOnError: true,
24
37
  })
25
- .then(({ data }) => Promise.all([compilerCtx.cnxFactory.fetcher(data), data.baseUrl ?? '']))
26
- .then(([fetcher, baseUrl]) => new StaticFetchFactory(fetcher, baseUrl));
38
+ .then(({ data }) => {
39
+ if (cnxMap.mockWithAI) {
40
+ // use the fake fetcher that calls the supervisor to generate a mock reponse
41
+ return new StaticFetchFactory(new FetchBuilder(globalThis.fetch, data).buildSupervisedFetch());
42
+ }
43
+ return Promise.all([compilerCtx.cnxFactory.fetcher(data), data.baseUrl ?? ''])
44
+ .then(([fetcher, baseUrl]) => new StaticFetchFactory(fetcher, baseUrl));
45
+ })
46
+ .catch((err) => {
47
+ compilerCtx.log.error(`Failed to get connection ${task.opts.connection}`, err);
48
+ if (supervisorEnabled) {
49
+ return new StaticFetchFactory(new FetchBuilder(globalThis.fetch).build());
50
+ }
51
+ throw err;
52
+ });
27
53
  }
28
54
  async function http(ctx) {
29
55
  const [fetch, baseUrl] = await fetchFactory.then(ff => Promise.all([ff.fetcher(ctx), ff.baseUrl(ctx)]));
@@ -41,9 +67,9 @@ function compileHttp(compilerCtx, task) {
41
67
  span.setAttribute('execution.id', ctx.executionId);
42
68
  span.setAttribute('connection.name', task.opts.connection);
43
69
  try {
44
- let result = await http(ctx);
70
+ const result = await http(ctx);
45
71
  if (supervisorEnabled) {
46
- span.setAttribute('http.response.body', JSON.stringify(result.data));
72
+ span.setAttribute('response.body', JSON.stringify(result.data));
47
73
  }
48
74
  return result;
49
75
  }
@@ -1 +1 @@
1
- {"version":3,"file":"webhook.d.ts","sourceRoot":"","sources":["../../../../../src/src/interpreter/durable/compilers/webhook.ts"],"names":[],"mappings":"AAcA,OAAO,EAAE,WAAW,EAAE,cAAc,EAAE,MAAM,yCAAyC,CAAC;AAGtF,OAAO,EAAE,eAAe,EAAE,MAAM,YAAY,CAAC;AAuD7C,eAAO,MAAM,eAAe,EAAE,eAAe,CAAC,WAAW,EAAE,cAAc,CA0SxE,CAAC"}
1
+ {"version":3,"file":"webhook.d.ts","sourceRoot":"","sources":["../../../../../src/src/interpreter/durable/compilers/webhook.ts"],"names":[],"mappings":"AAcA,OAAO,EAAE,WAAW,EAAE,cAAc,EAAE,MAAM,yCAAyC,CAAC;AAGtF,OAAO,EAAE,eAAe,EAAE,MAAM,YAAY,CAAC;AAuD7C,eAAO,MAAM,eAAe,EAAE,eAAe,CAAC,WAAW,EAAE,cAAc,CA4SxE,CAAC"}
@@ -91,6 +91,7 @@ export const webhookCompiler = {
91
91
  else {
92
92
  ctx.webhookRouter.use(express.raw({ type: '*/*', limit: '50mb' }));
93
93
  }
94
+ ctx.webhookRegistry.set(trigger.id, { method, path: `/${trigger.id}`, options: trigger.options });
94
95
  return new Observable((subscriber) => {
95
96
  if (!ctx.webhookRouter) {
96
97
  throw new Error('Router not available in compiler context');
@@ -119,7 +120,7 @@ export const webhookCompiler = {
119
120
  await ctx.tracer.startActiveSpan(`webhook-${trigger.id}`, async (span) => {
120
121
  span.setAttribute('task.id', trigger.id);
121
122
  span.setAttribute('task.type', 'webhook');
122
- span.setAttribute('task.type', 'fn');
123
+ span.setAttribute('type', 'task');
123
124
  const staticActivation = res.locals.activation;
124
125
  const executionCtx = ctx.contextProvider.create(staticActivation, req.body, ctxOptionsFn(req, res));
125
126
  span.setAttribute('execution.id', executionCtx.executionId);
@@ -9,7 +9,7 @@ function compileHttp(compilerCtx, task) {
9
9
  const cnxMap = compilerCtx.configReader.getCnxMapping(task.opts.connection);
10
10
  let fetchFactory;
11
11
  if (!cnxMap) {
12
- compilerCtx.log.error(`Connection ${task.opts.connection} not found, using default fetch with no credentials`);
12
+ compilerCtx.log.warn(`Connection ${task.opts.connection} not found, using default fetch with no credentials`);
13
13
  if (supervisorEnabled) {
14
14
  // missing connection map and we are in supervised mode, so we use the fake fetcher
15
15
  fetchFactory = Promise.resolve(new StaticFetchFactory(new FetchBuilder(globalThis.fetch).buildSupervisedFetch()));
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@versori/run",
3
- "version": "0.4.0-alpha.3",
3
+ "version": "0.4.0-alpha.4",
4
4
  "description": "Versori Run",
5
5
  "homepage": "https://github.com/versori/versori-run#readme",
6
6
  "repository": {
@@ -1 +1 @@
1
- {"version":3,"file":"http.d.ts","sourceRoot":"","sources":["../../../../../src/src/interpreter/durable/compilers/http.ts"],"names":[],"mappings":"AAOA,OAAO,EAAmB,YAAY,EAAE,MAAM,gCAAgC,CAAC;AAG/E,OAAO,EAA2B,YAAY,EAAE,MAAM,YAAY,CAAC;AAwFnE,eAAO,MAAM,YAAY,EAAE,YAAY,CAAC,GAAG,EAAE,GAAG,EAAE,YAAY,CAAC,GAAG,EAAE,GAAG,EAAE,GAAG,CAAC,CAG5E,CAAC"}
1
+ {"version":3,"file":"http.d.ts","sourceRoot":"","sources":["../../../../../src/src/interpreter/durable/compilers/http.ts"],"names":[],"mappings":"AAQA,OAAO,EAAmB,YAAY,EAAE,MAAM,gCAAgC,CAAC;AAG/E,OAAO,EAA2B,YAAY,EAAE,MAAM,YAAY,CAAC;AAmHnE,eAAO,MAAM,YAAY,EAAE,YAAY,CAAC,GAAG,EAAE,GAAG,EAAE,YAAY,CAAC,GAAG,EAAE,GAAG,EAAE,GAAG,CAAC,CAG5E,CAAC"}
@@ -4,6 +4,7 @@ exports.httpCompiler = void 0;
4
4
  const rxjs_1 = require("rxjs");
5
5
  const operators_1 = require("rxjs/operators");
6
6
  const DynamicFetchFactory_js_1 = require("../../../connection/DynamicFetchFactory.js");
7
+ const FetchBuilder_js_1 = require("../../../connection/internal/FetchBuilder.js");
7
8
  const StaticFetchFactory_js_1 = require("../../../connection/StaticFetchFactory.js");
8
9
  const HttpTask_js_1 = require("../../../dsl/tasks/HttpTask.js");
9
10
  const supervisor_js_1 = require("../../../internal/supervisor.js");
@@ -11,11 +12,23 @@ function compileHttp(compilerCtx, task) {
11
12
  const cnxMap = compilerCtx.configReader.getCnxMapping(task.opts.connection);
12
13
  let fetchFactory;
13
14
  if (!cnxMap) {
14
- compilerCtx.log.error(`Connection ${task.opts.connection} not found, using default fetch with no credentials`);
15
- fetchFactory = Promise.resolve(new StaticFetchFactory_js_1.StaticFetchFactory(globalThis.fetch));
15
+ compilerCtx.log.warn(`Connection ${task.opts.connection} not found, using default fetch with no credentials`);
16
+ if (supervisor_js_1.enabled) {
17
+ // missing connection map and we are in supervised mode, so we use the fake fetcher
18
+ fetchFactory = Promise.resolve(new StaticFetchFactory_js_1.StaticFetchFactory(new FetchBuilder_js_1.FetchBuilder(globalThis.fetch).buildSupervisedFetch()));
19
+ }
20
+ else {
21
+ // missing connection map and not in supervised mode, so we use global fetch
22
+ fetchFactory = Promise.resolve(new StaticFetchFactory_js_1.StaticFetchFactory(globalThis.fetch));
23
+ }
16
24
  }
17
25
  else if (cnxMap.dynamic) {
18
- fetchFactory = Promise.resolve(new DynamicFetchFactory_js_1.DynamicFetchFactory(compilerCtx.cnxFactory, compilerCtx.platformApi, compilerCtx.organisationId, cnxMap.templateId));
26
+ if (cnxMap.mockWithAI) {
27
+ fetchFactory = Promise.resolve(new StaticFetchFactory_js_1.StaticFetchFactory(new FetchBuilder_js_1.FetchBuilder(globalThis.fetch).buildSupervisedFetch()));
28
+ }
29
+ else {
30
+ fetchFactory = Promise.resolve(new DynamicFetchFactory_js_1.DynamicFetchFactory(compilerCtx.cnxFactory, compilerCtx.platformApi, compilerCtx.organisationId, cnxMap.templateId));
31
+ }
19
32
  }
20
33
  else {
21
34
  fetchFactory = compilerCtx.platformApi.getConnection({
@@ -25,8 +38,21 @@ function compileHttp(compilerCtx, task) {
25
38
  },
26
39
  throwOnError: true,
27
40
  })
28
- .then(({ data }) => Promise.all([compilerCtx.cnxFactory.fetcher(data), data.baseUrl ?? '']))
29
- .then(([fetcher, baseUrl]) => new StaticFetchFactory_js_1.StaticFetchFactory(fetcher, baseUrl));
41
+ .then(({ data }) => {
42
+ if (cnxMap.mockWithAI) {
43
+ // use the fake fetcher that calls the supervisor to generate a mock reponse
44
+ return new StaticFetchFactory_js_1.StaticFetchFactory(new FetchBuilder_js_1.FetchBuilder(globalThis.fetch, data).buildSupervisedFetch());
45
+ }
46
+ return Promise.all([compilerCtx.cnxFactory.fetcher(data), data.baseUrl ?? ''])
47
+ .then(([fetcher, baseUrl]) => new StaticFetchFactory_js_1.StaticFetchFactory(fetcher, baseUrl));
48
+ })
49
+ .catch((err) => {
50
+ compilerCtx.log.error(`Failed to get connection ${task.opts.connection}`, err);
51
+ if (supervisor_js_1.enabled) {
52
+ return new StaticFetchFactory_js_1.StaticFetchFactory(new FetchBuilder_js_1.FetchBuilder(globalThis.fetch).build());
53
+ }
54
+ throw err;
55
+ });
30
56
  }
31
57
  async function http(ctx) {
32
58
  const [fetch, baseUrl] = await fetchFactory.then(ff => Promise.all([ff.fetcher(ctx), ff.baseUrl(ctx)]));
@@ -44,9 +70,9 @@ function compileHttp(compilerCtx, task) {
44
70
  span.setAttribute('execution.id', ctx.executionId);
45
71
  span.setAttribute('connection.name', task.opts.connection);
46
72
  try {
47
- let result = await http(ctx);
73
+ const result = await http(ctx);
48
74
  if (supervisor_js_1.enabled) {
49
- span.setAttribute('http.response.body', JSON.stringify(result.data));
75
+ span.setAttribute('response.body', JSON.stringify(result.data));
50
76
  }
51
77
  return result;
52
78
  }
@@ -1 +1 @@
1
- {"version":3,"file":"webhook.d.ts","sourceRoot":"","sources":["../../../../../src/src/interpreter/durable/compilers/webhook.ts"],"names":[],"mappings":"AAcA,OAAO,EAAE,WAAW,EAAE,cAAc,EAAE,MAAM,yCAAyC,CAAC;AAGtF,OAAO,EAAE,eAAe,EAAE,MAAM,YAAY,CAAC;AAuD7C,eAAO,MAAM,eAAe,EAAE,eAAe,CAAC,WAAW,EAAE,cAAc,CA0SxE,CAAC"}
1
+ {"version":3,"file":"webhook.d.ts","sourceRoot":"","sources":["../../../../../src/src/interpreter/durable/compilers/webhook.ts"],"names":[],"mappings":"AAcA,OAAO,EAAE,WAAW,EAAE,cAAc,EAAE,MAAM,yCAAyC,CAAC;AAGtF,OAAO,EAAE,eAAe,EAAE,MAAM,YAAY,CAAC;AAuD7C,eAAO,MAAM,eAAe,EAAE,eAAe,CAAC,WAAW,EAAE,cAAc,CA4SxE,CAAC"}
@@ -97,6 +97,7 @@ exports.webhookCompiler = {
97
97
  else {
98
98
  ctx.webhookRouter.use(express_1.default.raw({ type: '*/*', limit: '50mb' }));
99
99
  }
100
+ ctx.webhookRegistry.set(trigger.id, { method, path: `/${trigger.id}`, options: trigger.options });
100
101
  return new rxjs_1.Observable((subscriber) => {
101
102
  if (!ctx.webhookRouter) {
102
103
  throw new Error('Router not available in compiler context');
@@ -125,7 +126,7 @@ exports.webhookCompiler = {
125
126
  await ctx.tracer.startActiveSpan(`webhook-${trigger.id}`, async (span) => {
126
127
  span.setAttribute('task.id', trigger.id);
127
128
  span.setAttribute('task.type', 'webhook');
128
- span.setAttribute('task.type', 'fn');
129
+ span.setAttribute('type', 'task');
129
130
  const staticActivation = res.locals.activation;
130
131
  const executionCtx = ctx.contextProvider.create(staticActivation, req.body, ctxOptionsFn(req, res));
131
132
  span.setAttribute('execution.id', executionCtx.executionId);
@@ -12,7 +12,7 @@ function compileHttp(compilerCtx, task) {
12
12
  const cnxMap = compilerCtx.configReader.getCnxMapping(task.opts.connection);
13
13
  let fetchFactory;
14
14
  if (!cnxMap) {
15
- compilerCtx.log.error(`Connection ${task.opts.connection} not found, using default fetch with no credentials`);
15
+ compilerCtx.log.warn(`Connection ${task.opts.connection} not found, using default fetch with no credentials`);
16
16
  if (supervisor_js_1.enabled) {
17
17
  // missing connection map and we are in supervised mode, so we use the fake fetcher
18
18
  fetchFactory = Promise.resolve(new StaticFetchFactory_js_1.StaticFetchFactory(new FetchBuilder_js_1.FetchBuilder(globalThis.fetch).buildSupervisedFetch()));