@versori/run 0.2.2-alpha.0 → 0.2.2-alpha.1

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":"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+LxE,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;AAgD7C,eAAO,MAAM,eAAe,EAAE,eAAe,CAAC,WAAW,EAAE,cAAc,CAyPxE,CAAC"}
@@ -1,4 +1,3 @@
1
- // In src/interpreter/memory/compilers/webhook.ts
2
1
  import cors from 'cors';
3
2
  import { pipeline } from 'node:stream/promises';
4
3
  import { Observable } from 'rxjs';
@@ -82,89 +81,119 @@ export const webhookCompiler = {
82
81
  }
83
82
  // endpoint for sans user because I'm not quite sure how the dynamic routing works
84
83
  ctx.router.post(`/${trigger.id}`, (req, res) => {
85
- const executionCtx = ctx.contextProvider.create(req.body, ctxOptionsFn(res));
86
- try {
87
- subscriber.next(executionCtx);
88
- if (isAsync) {
89
- sendResponse(res, onSuccess(executionCtx));
84
+ ctx.tracer.startActiveSpan(`webhook-${trigger.id}`, (span) => {
85
+ span.setAttribute('task.id', trigger.id);
86
+ span.setAttribute('task.type', 'webhook');
87
+ const executionCtx = ctx.contextProvider.create(req.body, ctxOptionsFn(res));
88
+ span.setAttribute('execution.id', executionCtx.executionId);
89
+ try {
90
+ subscriber.next(executionCtx);
91
+ if (isAsync) {
92
+ sendResponse(res, onSuccess(executionCtx));
93
+ }
90
94
  }
91
- }
92
- catch (error) {
93
- executionCtx.log.error('webhook execution error', {
94
- error: JSON.stringify(error),
95
- });
96
- if (isAsync) {
97
- sendResponse(res, onError(executionCtx.withData(error)));
95
+ catch (error) {
96
+ executionCtx.log.error('webhook execution error', {
97
+ error: JSON.stringify(error),
98
+ });
99
+ if (isAsync) {
100
+ sendResponse(res, onError(executionCtx.withData(error)));
101
+ }
98
102
  }
99
- }
103
+ finally {
104
+ span.end();
105
+ }
106
+ });
100
107
  });
101
108
  // this endpoint will trigger the workflow for each activation given by the external user ID
102
109
  ctx.router.post(`/${trigger.id}/users/:userId`, async (req, res) => {
103
- const userId = req.params.userId;
104
- const activations = await ctx.connectionProvider.getUserActivations(userId);
105
- if (!activations || activations.length === 0) {
106
- res.status(404).json({
107
- status: 'error',
108
- message: `No activations found for user: ${userId}`,
110
+ await ctx.tracer.startActiveSpan(`webhook-${trigger.id}`, async (span) => {
111
+ span.setAttribute('task.id', trigger.id);
112
+ span.setAttribute('task.type', 'webhook');
113
+ span.setAttribute('user.id', req.params.userId);
114
+ const userId = req.params.userId;
115
+ const activations = await ctx.connectionProvider.getUserActivations(userId);
116
+ if (!activations || activations.length === 0) {
117
+ res.status(404).json({
118
+ status: 'error',
119
+ message: `No activations found for user: ${userId}`,
120
+ });
121
+ span.setAttribute('error.message', `No activations found for user: ${userId}`);
122
+ span.setAttribute('http.status_code', '404');
123
+ span.end();
124
+ return;
125
+ }
126
+ const executionCtx = ctx.contextProvider.create(req.body, ctxOptionsFn(res));
127
+ span.setAttribute('execution.id', executionCtx.executionId);
128
+ const errors = [];
129
+ activations.forEach((activation) => {
130
+ const activationCtx = executionCtx.withActivation(activation);
131
+ try {
132
+ subscriber.next(activationCtx);
133
+ }
134
+ catch (error) {
135
+ activationCtx.log.error('webhook execution error', {
136
+ error: JSON.stringify(error),
137
+ });
138
+ errors.push({
139
+ activationId: activation.id,
140
+ error,
141
+ });
142
+ }
109
143
  });
110
- return;
111
- }
112
- const executionCtx = ctx.contextProvider.create(req.body, ctxOptionsFn(res));
113
- const errors = [];
114
- activations.forEach((activation) => {
115
- const activationCtx = executionCtx.withActivation(activation);
144
+ if (isAsync) {
145
+ if (errors.length === 0) {
146
+ sendResponse(res, onSuccess(executionCtx));
147
+ }
148
+ else {
149
+ sendResponse(res, onError(executionCtx.withData(errors)));
150
+ }
151
+ }
152
+ span.end();
153
+ });
154
+ });
155
+ // this endpoint will trigger the workflow only for the activation given by its ID
156
+ ctx.router.post(`/${trigger.id}/activations/:activationId`, async (req, res) => {
157
+ await ctx.tracer.startActiveSpan(`webhook-${trigger.id}`, async (span) => {
158
+ span.setAttribute('task.id', trigger.id);
159
+ span.setAttribute('task.type', 'webhook');
160
+ span.setAttribute('activation.id', req.params.activationId);
161
+ const activationId = req.params.activationId;
162
+ const activation = await ctx.connectionProvider.getActivation(activationId);
163
+ if (!activation) {
164
+ // TODO report back actual errors
165
+ res.status(404).json({
166
+ status: 'error',
167
+ message: `No activation found for ID: ${activationId}`,
168
+ });
169
+ span.setAttribute('error.message', `No activation found for ID: ${activationId}`);
170
+ span.setAttribute('http.status_code', '404');
171
+ span.end();
172
+ return;
173
+ }
174
+ const activationCtx = ctx.contextProvider.create(req.body, {
175
+ ...ctxOptionsFn(res),
176
+ activation,
177
+ });
178
+ span.setAttribute('execution.id', activationCtx.executionId);
116
179
  try {
117
180
  subscriber.next(activationCtx);
181
+ if (isAsync) {
182
+ sendResponse(res, onSuccess(activationCtx));
183
+ }
118
184
  }
119
185
  catch (error) {
120
186
  activationCtx.log.error('webhook execution error', {
121
187
  error: JSON.stringify(error),
122
188
  });
123
- errors.push({
124
- activationId: activation.id,
125
- error,
126
- });
127
- }
128
- });
129
- if (isAsync) {
130
- if (errors.length === 0) {
131
- sendResponse(res, onSuccess(executionCtx));
189
+ if (isAsync) {
190
+ sendResponse(res, onError(activationCtx.withData(error)));
191
+ }
132
192
  }
133
- else {
134
- sendResponse(res, onError(executionCtx.withData(errors)));
193
+ finally {
194
+ span.end();
135
195
  }
136
- }
137
- });
138
- // this endpoint will trigger the workflow only for the activation given by its ID
139
- ctx.router.post(`/${trigger.id}/activations/:activationId`, async (req, res) => {
140
- const activationId = req.params.activationId;
141
- const activation = await ctx.connectionProvider.getActivation(activationId);
142
- if (!activation) {
143
- // TODO report back actual errors
144
- res.status(404).json({
145
- status: 'error',
146
- message: `No activation found for ID: ${activationId}`,
147
- });
148
- return;
149
- }
150
- const activationCtx = ctx.contextProvider.create(req.body, {
151
- ...ctxOptionsFn(res),
152
- activation,
153
196
  });
154
- try {
155
- subscriber.next(activationCtx);
156
- if (isAsync) {
157
- sendResponse(res, onSuccess(activationCtx));
158
- }
159
- }
160
- catch (error) {
161
- activationCtx.log.error('webhook execution error', {
162
- error: JSON.stringify(error),
163
- });
164
- if (isAsync) {
165
- sendResponse(res, onError(activationCtx.withData(error)));
166
- }
167
- }
168
197
  });
169
198
  function cleanup() {
170
199
  ctx.log.debug('webhook trigger stopped');
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@versori/run",
3
- "version": "v0.2.2-alpha.0",
3
+ "version": "v0.2.2-alpha.1",
4
4
  "description": "Versori Run",
5
5
  "homepage": "https://github.com/versori/versori-run#readme",
6
6
  "repository": {
@@ -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+LxE,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;AAgD7C,eAAO,MAAM,eAAe,EAAE,eAAe,CAAC,WAAW,EAAE,cAAc,CAyPxE,CAAC"}
@@ -4,7 +4,6 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
4
4
  };
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
6
  exports.webhookCompiler = void 0;
7
- // In src/interpreter/memory/compilers/webhook.ts
8
7
  const cors_1 = __importDefault(require("cors"));
9
8
  const promises_1 = require("node:stream/promises");
10
9
  const rxjs_1 = require("rxjs");
@@ -88,89 +87,119 @@ exports.webhookCompiler = {
88
87
  }
89
88
  // endpoint for sans user because I'm not quite sure how the dynamic routing works
90
89
  ctx.router.post(`/${trigger.id}`, (req, res) => {
91
- const executionCtx = ctx.contextProvider.create(req.body, ctxOptionsFn(res));
92
- try {
93
- subscriber.next(executionCtx);
94
- if (isAsync) {
95
- sendResponse(res, onSuccess(executionCtx));
90
+ ctx.tracer.startActiveSpan(`webhook-${trigger.id}`, (span) => {
91
+ span.setAttribute('task.id', trigger.id);
92
+ span.setAttribute('task.type', 'webhook');
93
+ const executionCtx = ctx.contextProvider.create(req.body, ctxOptionsFn(res));
94
+ span.setAttribute('execution.id', executionCtx.executionId);
95
+ try {
96
+ subscriber.next(executionCtx);
97
+ if (isAsync) {
98
+ sendResponse(res, onSuccess(executionCtx));
99
+ }
96
100
  }
97
- }
98
- catch (error) {
99
- executionCtx.log.error('webhook execution error', {
100
- error: JSON.stringify(error),
101
- });
102
- if (isAsync) {
103
- sendResponse(res, onError(executionCtx.withData(error)));
101
+ catch (error) {
102
+ executionCtx.log.error('webhook execution error', {
103
+ error: JSON.stringify(error),
104
+ });
105
+ if (isAsync) {
106
+ sendResponse(res, onError(executionCtx.withData(error)));
107
+ }
104
108
  }
105
- }
109
+ finally {
110
+ span.end();
111
+ }
112
+ });
106
113
  });
107
114
  // this endpoint will trigger the workflow for each activation given by the external user ID
108
115
  ctx.router.post(`/${trigger.id}/users/:userId`, async (req, res) => {
109
- const userId = req.params.userId;
110
- const activations = await ctx.connectionProvider.getUserActivations(userId);
111
- if (!activations || activations.length === 0) {
112
- res.status(404).json({
113
- status: 'error',
114
- message: `No activations found for user: ${userId}`,
116
+ await ctx.tracer.startActiveSpan(`webhook-${trigger.id}`, async (span) => {
117
+ span.setAttribute('task.id', trigger.id);
118
+ span.setAttribute('task.type', 'webhook');
119
+ span.setAttribute('user.id', req.params.userId);
120
+ const userId = req.params.userId;
121
+ const activations = await ctx.connectionProvider.getUserActivations(userId);
122
+ if (!activations || activations.length === 0) {
123
+ res.status(404).json({
124
+ status: 'error',
125
+ message: `No activations found for user: ${userId}`,
126
+ });
127
+ span.setAttribute('error.message', `No activations found for user: ${userId}`);
128
+ span.setAttribute('http.status_code', '404');
129
+ span.end();
130
+ return;
131
+ }
132
+ const executionCtx = ctx.contextProvider.create(req.body, ctxOptionsFn(res));
133
+ span.setAttribute('execution.id', executionCtx.executionId);
134
+ const errors = [];
135
+ activations.forEach((activation) => {
136
+ const activationCtx = executionCtx.withActivation(activation);
137
+ try {
138
+ subscriber.next(activationCtx);
139
+ }
140
+ catch (error) {
141
+ activationCtx.log.error('webhook execution error', {
142
+ error: JSON.stringify(error),
143
+ });
144
+ errors.push({
145
+ activationId: activation.id,
146
+ error,
147
+ });
148
+ }
115
149
  });
116
- return;
117
- }
118
- const executionCtx = ctx.contextProvider.create(req.body, ctxOptionsFn(res));
119
- const errors = [];
120
- activations.forEach((activation) => {
121
- const activationCtx = executionCtx.withActivation(activation);
150
+ if (isAsync) {
151
+ if (errors.length === 0) {
152
+ sendResponse(res, onSuccess(executionCtx));
153
+ }
154
+ else {
155
+ sendResponse(res, onError(executionCtx.withData(errors)));
156
+ }
157
+ }
158
+ span.end();
159
+ });
160
+ });
161
+ // this endpoint will trigger the workflow only for the activation given by its ID
162
+ ctx.router.post(`/${trigger.id}/activations/:activationId`, async (req, res) => {
163
+ await ctx.tracer.startActiveSpan(`webhook-${trigger.id}`, async (span) => {
164
+ span.setAttribute('task.id', trigger.id);
165
+ span.setAttribute('task.type', 'webhook');
166
+ span.setAttribute('activation.id', req.params.activationId);
167
+ const activationId = req.params.activationId;
168
+ const activation = await ctx.connectionProvider.getActivation(activationId);
169
+ if (!activation) {
170
+ // TODO report back actual errors
171
+ res.status(404).json({
172
+ status: 'error',
173
+ message: `No activation found for ID: ${activationId}`,
174
+ });
175
+ span.setAttribute('error.message', `No activation found for ID: ${activationId}`);
176
+ span.setAttribute('http.status_code', '404');
177
+ span.end();
178
+ return;
179
+ }
180
+ const activationCtx = ctx.contextProvider.create(req.body, {
181
+ ...ctxOptionsFn(res),
182
+ activation,
183
+ });
184
+ span.setAttribute('execution.id', activationCtx.executionId);
122
185
  try {
123
186
  subscriber.next(activationCtx);
187
+ if (isAsync) {
188
+ sendResponse(res, onSuccess(activationCtx));
189
+ }
124
190
  }
125
191
  catch (error) {
126
192
  activationCtx.log.error('webhook execution error', {
127
193
  error: JSON.stringify(error),
128
194
  });
129
- errors.push({
130
- activationId: activation.id,
131
- error,
132
- });
133
- }
134
- });
135
- if (isAsync) {
136
- if (errors.length === 0) {
137
- sendResponse(res, onSuccess(executionCtx));
195
+ if (isAsync) {
196
+ sendResponse(res, onError(activationCtx.withData(error)));
197
+ }
138
198
  }
139
- else {
140
- sendResponse(res, onError(executionCtx.withData(errors)));
199
+ finally {
200
+ span.end();
141
201
  }
142
- }
143
- });
144
- // this endpoint will trigger the workflow only for the activation given by its ID
145
- ctx.router.post(`/${trigger.id}/activations/:activationId`, async (req, res) => {
146
- const activationId = req.params.activationId;
147
- const activation = await ctx.connectionProvider.getActivation(activationId);
148
- if (!activation) {
149
- // TODO report back actual errors
150
- res.status(404).json({
151
- status: 'error',
152
- message: `No activation found for ID: ${activationId}`,
153
- });
154
- return;
155
- }
156
- const activationCtx = ctx.contextProvider.create(req.body, {
157
- ...ctxOptionsFn(res),
158
- activation,
159
202
  });
160
- try {
161
- subscriber.next(activationCtx);
162
- if (isAsync) {
163
- sendResponse(res, onSuccess(activationCtx));
164
- }
165
- }
166
- catch (error) {
167
- activationCtx.log.error('webhook execution error', {
168
- error: JSON.stringify(error),
169
- });
170
- if (isAsync) {
171
- sendResponse(res, onError(activationCtx.withData(error)));
172
- }
173
- }
174
203
  });
175
204
  function cleanup() {
176
205
  ctx.log.debug('webhook trigger stopped');