@versori/run 0.1.0-alpha.13 → 0.1.0-alpha.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 (89) hide show
  1. package/esm/_dnt.shims.d.ts +5 -1
  2. package/esm/_dnt.shims.d.ts.map +1 -1
  3. package/esm/_dnt.shims.js +5 -1
  4. package/esm/deps/jsr.io/@nats-io/transport-deno/3.0.2/src/deno_transport.d.ts +2 -1
  5. package/esm/deps/jsr.io/@nats-io/transport-deno/3.0.2/src/deno_transport.d.ts.map +1 -1
  6. package/esm/deps/jsr.io/@nats-io/transport-deno/3.0.2/src/deno_transport.js +7 -6
  7. package/{script/deps/jsr.io/@std/fmt/1.0.5 → esm/deps/jsr.io/@std/fmt/1.0.6}/colors.d.ts.map +1 -1
  8. package/{script/deps/jsr.io/@std/fs/1.0.11 → esm/deps/jsr.io/@std/fs/1.0.16}/exists.d.ts +0 -1
  9. package/esm/deps/jsr.io/@std/fs/1.0.16/exists.d.ts.map +1 -0
  10. package/esm/deps/jsr.io/@std/fs/{1.0.11 → 1.0.16}/exists.js +12 -10
  11. package/esm/deps/jsr.io/@std/log/0.224.14/console_handler.js +1 -1
  12. package/esm/deps/jsr.io/@std/log/0.224.14/file_handler.d.ts +3 -2
  13. package/esm/deps/jsr.io/@std/log/0.224.14/file_handler.d.ts.map +1 -1
  14. package/esm/deps/jsr.io/@std/log/0.224.14/file_handler.js +2 -1
  15. package/esm/deps/jsr.io/@std/log/0.224.14/rotating_file_handler.d.ts.map +1 -1
  16. package/esm/deps/jsr.io/@std/log/0.224.14/rotating_file_handler.js +9 -7
  17. package/esm/src/context/Context.d.ts +4 -14
  18. package/esm/src/context/Context.d.ts.map +1 -1
  19. package/esm/src/context/Context.js +10 -16
  20. package/esm/src/context/ContextProvider.d.ts +4 -3
  21. package/esm/src/context/ContextProvider.d.ts.map +1 -1
  22. package/esm/src/context/ContextProvider.js +5 -5
  23. package/esm/src/dsl/http/versori/configloader.d.ts.map +1 -1
  24. package/esm/src/dsl/http/versori/configloader.js +3 -2
  25. package/esm/src/dsl/http/versori/internalauth.d.ts.map +1 -1
  26. package/esm/src/dsl/http/versori/internalauth.js +6 -5
  27. package/esm/src/dsl/http/versori/platformapi.d.ts +1 -2
  28. package/esm/src/dsl/http/versori/platformapi.d.ts.map +1 -1
  29. package/esm/src/dsl/http/versori/platformapi.js +5 -15
  30. package/esm/src/dsl/http/versori/roundtripper.d.ts.map +1 -1
  31. package/esm/src/dsl/http/versori/roundtripper.js +40 -36
  32. package/esm/src/dsl/triggers/WebhookTrigger.d.ts +3 -45
  33. package/esm/src/dsl/triggers/WebhookTrigger.d.ts.map +1 -1
  34. package/esm/src/dsl/triggers/WebhookTrigger.js +6 -10
  35. package/esm/src/interpreter/memory/MemoryInterpreter.d.ts +1 -6
  36. package/esm/src/interpreter/memory/MemoryInterpreter.d.ts.map +1 -1
  37. package/esm/src/interpreter/memory/MemoryInterpreter.js +7 -71
  38. package/esm/src/interpreter/memory/compilers/webhook.d.ts.map +1 -1
  39. package/esm/src/interpreter/memory/compilers/webhook.js +32 -106
  40. package/esm/src/kv/nats/NatsKeyValueProvider.d.ts.map +1 -1
  41. package/esm/src/kv/nats/NatsKeyValueProvider.js +8 -7
  42. package/package.json +6 -3
  43. package/script/_dnt.shims.d.ts +5 -1
  44. package/script/_dnt.shims.d.ts.map +1 -1
  45. package/script/_dnt.shims.js +7 -2
  46. package/script/deps/jsr.io/@nats-io/transport-deno/3.0.2/src/deno_transport.d.ts +2 -1
  47. package/script/deps/jsr.io/@nats-io/transport-deno/3.0.2/src/deno_transport.d.ts.map +1 -1
  48. package/script/deps/jsr.io/@nats-io/transport-deno/3.0.2/src/deno_transport.js +33 -9
  49. package/{esm/deps/jsr.io/@std/fmt/1.0.5 → script/deps/jsr.io/@std/fmt/1.0.6}/colors.d.ts.map +1 -1
  50. package/{esm/deps/jsr.io/@std/fs/1.0.11 → script/deps/jsr.io/@std/fs/1.0.16}/exists.d.ts +0 -1
  51. package/script/deps/jsr.io/@std/fs/1.0.16/exists.d.ts.map +1 -0
  52. package/script/deps/jsr.io/@std/fs/{1.0.11 → 1.0.16}/exists.js +35 -10
  53. package/script/deps/jsr.io/@std/log/0.224.14/console_handler.js +1 -1
  54. package/script/deps/jsr.io/@std/log/0.224.14/file_handler.d.ts +3 -2
  55. package/script/deps/jsr.io/@std/log/0.224.14/file_handler.d.ts.map +1 -1
  56. package/script/deps/jsr.io/@std/log/0.224.14/file_handler.js +25 -1
  57. package/script/deps/jsr.io/@std/log/0.224.14/rotating_file_handler.d.ts.map +1 -1
  58. package/script/deps/jsr.io/@std/log/0.224.14/rotating_file_handler.js +32 -7
  59. package/script/src/context/Context.d.ts +4 -14
  60. package/script/src/context/Context.d.ts.map +1 -1
  61. package/script/src/context/Context.js +10 -16
  62. package/script/src/context/ContextProvider.d.ts +4 -3
  63. package/script/src/context/ContextProvider.d.ts.map +1 -1
  64. package/script/src/context/ContextProvider.js +5 -5
  65. package/script/src/dsl/http/versori/configloader.d.ts.map +1 -1
  66. package/script/src/dsl/http/versori/configloader.js +26 -2
  67. package/script/src/dsl/http/versori/internalauth.d.ts.map +1 -1
  68. package/script/src/dsl/http/versori/internalauth.js +29 -5
  69. package/script/src/dsl/http/versori/platformapi.d.ts +1 -2
  70. package/script/src/dsl/http/versori/platformapi.d.ts.map +1 -1
  71. package/script/src/dsl/http/versori/platformapi.js +28 -15
  72. package/script/src/dsl/http/versori/roundtripper.d.ts.map +1 -1
  73. package/script/src/dsl/http/versori/roundtripper.js +63 -36
  74. package/script/src/dsl/triggers/WebhookTrigger.d.ts +3 -45
  75. package/script/src/dsl/triggers/WebhookTrigger.d.ts.map +1 -1
  76. package/script/src/dsl/triggers/WebhookTrigger.js +6 -10
  77. package/script/src/interpreter/memory/MemoryInterpreter.d.ts +1 -6
  78. package/script/src/interpreter/memory/MemoryInterpreter.d.ts.map +1 -1
  79. package/script/src/interpreter/memory/MemoryInterpreter.js +30 -71
  80. package/script/src/interpreter/memory/compilers/webhook.d.ts.map +1 -1
  81. package/script/src/interpreter/memory/compilers/webhook.js +32 -109
  82. package/script/src/kv/nats/NatsKeyValueProvider.d.ts.map +1 -1
  83. package/script/src/kv/nats/NatsKeyValueProvider.js +31 -7
  84. package/esm/deps/jsr.io/@std/fs/1.0.11/exists.d.ts.map +0 -1
  85. package/script/deps/jsr.io/@std/fs/1.0.11/exists.d.ts.map +0 -1
  86. /package/esm/deps/jsr.io/@std/fmt/{1.0.5 → 1.0.6}/colors.d.ts +0 -0
  87. /package/esm/deps/jsr.io/@std/fmt/{1.0.5 → 1.0.6}/colors.js +0 -0
  88. /package/script/deps/jsr.io/@std/fmt/{1.0.5 → 1.0.6}/colors.d.ts +0 -0
  89. /package/script/deps/jsr.io/@std/fmt/{1.0.5 → 1.0.6}/colors.js +0 -0
@@ -1,7 +1,8 @@
1
+ import * as dntShim from "../../../../_dnt.shims.js";
1
2
  import { envVarEnvId, envVarOrgId, envVarPlatformApiBaseURL } from './constants.js';
2
3
  import { InternalAuth } from './internalauth.js';
3
4
  export class PlatformAPIClient {
4
- constructor(baseUrl, orgId, envId, cache = {}) {
5
+ constructor(baseUrl, orgId, envId) {
5
6
  Object.defineProperty(this, "baseUrl", {
6
7
  enumerable: true,
7
8
  configurable: true,
@@ -26,31 +27,21 @@ export class PlatformAPIClient {
26
27
  writable: true,
27
28
  value: void 0
28
29
  });
29
- Object.defineProperty(this, "cache", {
30
- enumerable: true,
31
- configurable: true,
32
- writable: true,
33
- value: void 0
34
- });
35
30
  this.baseUrl = baseUrl;
36
31
  this.orgId = orgId;
37
- this.cache = cache;
38
32
  this.envId = envId;
39
33
  this.internalAuth = new InternalAuth();
40
34
  }
41
35
  static fromEnv() {
42
- const baseUrl = Deno.env.get(envVarPlatformApiBaseURL);
43
- const orgId = Deno.env.get(envVarOrgId);
44
- const envId = Deno.env.get(envVarEnvId);
36
+ const baseUrl = dntShim.Deno.env.get(envVarPlatformApiBaseURL);
37
+ const orgId = dntShim.Deno.env.get(envVarOrgId);
38
+ const envId = dntShim.Deno.env.get(envVarEnvId);
45
39
  if (!baseUrl || !orgId || !envId) {
46
40
  throw new Error('Missing required environment variables');
47
41
  }
48
42
  return new PlatformAPIClient(baseUrl, orgId, envId);
49
43
  }
50
44
  async getStaticConnection(cnxId) {
51
- if (this.cache[cnxId]) {
52
- return this.cache[cnxId];
53
- }
54
45
  const resp = await fetch(`${this.baseUrl}/o/${this.orgId}/connections/${cnxId}`, {
55
46
  headers: {
56
47
  'x-versori-internal-token': await this.internalAuth.getToken(),
@@ -60,7 +51,6 @@ export class PlatformAPIClient {
60
51
  return undefined;
61
52
  }
62
53
  const result = (await resp.json());
63
- this.cache[cnxId] = result;
64
54
  return result;
65
55
  }
66
56
  async getUserActivations(userId) {
@@ -1 +1 @@
1
- {"version":3,"file":"roundtripper.d.ts","sourceRoot":"","sources":["../../../../../src/src/dsl/http/versori/roundtripper.ts"],"names":[],"mappings":"AAAA,OAAO,EAGH,cAAc,EACd,mBAAmB,EAEtB,MAAM,aAAa,CAAC;AAErB,OAAO,EAAE,uBAAuB,EAAE,MAAM,sBAAsB,CAAC;AAE/D,OAAO,EAAE,iBAAiB,EAAE,MAAM,kBAAkB,CAAC;AACrD,OAAO,EAAE,MAAM,EAAE,MAAM,0CAA0C,CAAC;AASlE,MAAM,MAAM,kBAAkB,GAAG,OAAO,GAAG,SAAS,GAAG,SAAS,CAAC;AAEjE;;;;;;;;;;;GAWG;AACH,qBAAa,0BAA2B,YAAW,mBAAmB;IAClE,OAAO,CAAC,WAAW,CAA0B;IAE7C,OAAO,CAAC,iBAAiB,CAAoB;IAE7C,OAAO,CAAC,UAAU,CAAmB;IAErC,OAAO,CAAC,GAAG,CAAS;IAEpB,OAAO,CAAC,QAAQ,CAAC,cAAc,CAK7B;gBAGE,WAAW,EAAE,uBAAuB,EACpC,iBAAiB,EAAE,iBAAiB,EACpC,MAAM,EAAE,MAAM;IAQlB,MAAM,CAAC,OAAO,CAAC,MAAM,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,OAAO,CAAC,aAAa;IAsBf,MAAM,CACR,QAAQ,EAAE,MAAM,EAChB,EAAE,GAAE,OAAO,KAAwB,GACpC,OAAO,CAAC,OAAO,KAAK,GAAG,SAAS,CAAC;IA4B9B,aAAa,CACf,YAAY,EAAE,MAAM,EACpB,EAAE,GAAE,OAAO,KAAwB,GACpC,OAAO,CAAC,cAAc,GAAG,SAAS,CAAC;IA4CtC,OAAO,CAAC,eAAe;IAYvB,OAAO,CAAC,aAAa;YAUP,aAAa;YAoDb,gBAAgB;YAmChB,kBAAkB;YAiClB,aAAa;CAkD9B"}
@@ -1,6 +1,6 @@
1
+ import * as dntShim from "../../../../_dnt.shims.js";
1
2
  import { LoadConfigFromFile } from './configloader.js';
2
3
  import { VersoriCredentialClient } from './credentials/mod.js';
3
- import { LRUCache } from 'lru-cache';
4
4
  import { PlatformAPIClient } from './platformapi.js';
5
5
  import { ConsoleLogger } from '../../../observability/mod.js';
6
6
  import { envVarCredsBaseURL, envVarEnvId, envVarOrgId, envVarPlatformApiBaseURL, } from './constants.js';
@@ -59,10 +59,10 @@ export class VersoriRoundTripperFactory {
59
59
  this.log = logger;
60
60
  }
61
61
  static fromEnv(logger) {
62
- const credsBaseURL = Deno.env.get(envVarCredsBaseURL);
63
- const platformApiBaseURL = Deno.env.get(envVarPlatformApiBaseURL);
64
- const orgId = Deno.env.get(envVarOrgId);
65
- const envId = Deno.env.get(envVarEnvId);
62
+ const credsBaseURL = dntShim.Deno.env.get(envVarCredsBaseURL);
63
+ const platformApiBaseURL = dntShim.Deno.env.get(envVarPlatformApiBaseURL);
64
+ const orgId = dntShim.Deno.env.get(envVarOrgId);
65
+ const envId = dntShim.Deno.env.get(envVarEnvId);
66
66
  if (!orgId || !envId || !platformApiBaseURL || !credsBaseURL) {
67
67
  const missingVars = [];
68
68
  if (!orgId)
@@ -83,10 +83,12 @@ export class VersoriRoundTripperFactory {
83
83
  // takes the info and modifies the url using changeBaseUrl if necessary
84
84
  changeRequestInit(info, conn) {
85
85
  if (typeof info === 'string') {
86
+ // should be this most of the time assuming we're using pathnames
86
87
  return this.changeBaseUrl(info, conn);
87
88
  }
88
89
  else if (info instanceof URL) {
89
- return this.changeBaseUrl(info.toString(), conn);
90
+ const newUrl = new URL(this.changeBaseUrl(info.toString(), conn));
91
+ return newUrl;
90
92
  }
91
93
  else if (info instanceof Request) {
92
94
  const url = this.changeBaseUrl(info.url, conn);
@@ -94,44 +96,46 @@ export class VersoriRoundTripperFactory {
94
96
  }
95
97
  return info;
96
98
  }
97
- changeBaseUrl(url, conn) {
98
- const baseUrl = conn.baseUrl;
99
- if (!baseUrl) {
100
- return url;
99
+ changeBaseUrl(pathname, conn) {
100
+ const connBaseURL = conn.baseUrl;
101
+ // if the connection has no baseUrl set, but the pathname is a valid URL, return it as is
102
+ if (!connBaseURL && isValidURL(pathname)) {
103
+ return pathname;
101
104
  }
102
- const urlObj = new URL(url);
103
- const baseUrlObj = new URL(baseUrl);
104
- urlObj.hostname = baseUrlObj.hostname;
105
- this.log.debug('Changing base URL', {
106
- originalUrl: url,
107
- newUrl: urlObj.toString(),
108
- });
109
- return url.toString();
105
+ const connBaseURLObj = new URL(connBaseURL);
106
+ let _pathname = pathname;
107
+ if (isValidURL(pathname)) {
108
+ const pathnameObj = new URL(pathname);
109
+ _pathname = pathnameObj.pathname;
110
+ }
111
+ const newURL = new URL(_pathname, connBaseURLObj.origin);
112
+ return newURL.toString();
110
113
  }
114
+ // TODO: Currently if the connection is edited, then the fetcher will not be updated.
111
115
  async create(connName, fn = globalThis.fetch) {
112
116
  const cnxId = this.getConnectionID(connName);
113
117
  const conn = await this.platformAPIClient.getStaticConnection(cnxId);
114
118
  if (!conn) {
115
119
  return undefined;
116
120
  }
121
+ const _fn = (input, init) => {
122
+ const _input = this.changeRequestInit(input, conn);
123
+ return fn(_input, init);
124
+ };
117
125
  switch (conn.credentials[0].authSchemeConfig.type) {
118
126
  case 'api-key':
119
- return this.apiKeyFetcher(conn, fn);
127
+ return this.apiKeyFetcher(conn, _fn);
120
128
  case 'basic-auth':
121
- return this.basicAuthFetcher(conn, fn);
129
+ return this.basicAuthFetcher(conn, _fn);
122
130
  case 'jwt-bearer':
123
- return this.bearerTokenFetcher(conn, fn);
131
+ return this.bearerTokenFetcher(conn, _fn);
124
132
  case 'oauth2':
125
- return this.oauth2Fetcher(conn, fn);
133
+ return this.oauth2Fetcher(conn, _fn);
126
134
  default:
127
135
  return fn;
128
136
  }
129
137
  }
130
138
  async createDynamic(templateName, fn = globalThis.fetch) {
131
- const lruCacheOptions = {
132
- max: 100,
133
- };
134
- const cache = new LRUCache(lruCacheOptions);
135
139
  const template = this.getTemplateID(templateName);
136
140
  if (!template) {
137
141
  this.log.info('Template not found in config, could be a static connection', {
@@ -140,16 +144,7 @@ export class VersoriRoundTripperFactory {
140
144
  return undefined;
141
145
  }
142
146
  const _fn = async (activation, input, init) => {
143
- let conn = undefined;
144
- if (cache.has(activation.id)) {
145
- conn = cache.get(activation.id);
146
- }
147
- else {
148
- conn = await this.platformAPIClient.getActivationConnection(template, activation.id);
149
- if (conn) {
150
- cache.set(activation.id, conn);
151
- }
152
- }
147
+ const conn = await this.platformAPIClient.getActivationConnection(template, activation.id);
153
148
  if (!conn) {
154
149
  return this.defaultDynamic('Connection not found for user, using default fetch', {
155
150
  templateName: templateName,
@@ -338,3 +333,12 @@ export class VersoriRoundTripperFactory {
338
333
  return _fn;
339
334
  }
340
335
  }
336
+ function isValidURL(url) {
337
+ try {
338
+ new URL(url);
339
+ return true;
340
+ }
341
+ catch (_) {
342
+ return false;
343
+ }
344
+ }
@@ -1,55 +1,13 @@
1
- import { Context } from '../../context/Context.js';
2
1
  import { Taskable } from '../Task.js';
3
2
  import { Trigger, TriggerType } from '../Trigger.js';
4
3
  import { Workflow } from '../Workflow.js';
5
4
  export type WebhookData = Record<string, never>;
6
- export type WebhookCorsOptions = boolean | {
7
- origin: string;
8
- methods: string[];
9
- allowedHeaders: string[];
10
- exposedHeaders: string[];
11
- credentials: boolean;
12
- };
13
- export type WebhookResponseOptions = {
14
- /**
15
- * Mode determines how the response is sent to the client. The response can be customized by
16
- * the `onSuccess` and `onError` functions, which have sensible defaults for each mode.
17
- *
18
- * - `sync`: The response is sent at the end of the workflow.
19
- * - `async`: The response is sent immediately after the trigger is activated.
20
- *
21
- * @default 'sync'
22
- */
23
- mode?: 'sync' | 'async';
24
- /**
25
- * Function that returns a response for a successful trigger activation.
26
- *
27
- * Defaults to a 202 Accepted response for 'async' mode, and a 200 OK response for 'sync' mode.
28
- *
29
- * @param ctx The current context of the workflow, containing data from the final step.
30
- * @returns A response to send to the client.
31
- */
32
- onSuccess?: <T>(ctx: Context<T>) => Response;
33
- /**
34
- * Function that returns a response for a failed trigger activation.
35
- *
36
- * Defaults to a 500 Internal Server Error response for both modes.
37
- *
38
- * @param ctx The current context of the workflow, containing data from the final step.
39
- * @returns A response to send to the client.
40
- */
41
- onError?: <T>(ctx: Context<T>) => Response;
42
- };
43
- export type WebhookOptions = {
44
- cors?: WebhookCorsOptions;
45
- response?: WebhookResponseOptions;
46
- };
47
5
  export declare class WebhookTrigger implements Trigger<WebhookData> {
48
6
  id: string;
49
- options: WebhookOptions;
50
7
  [TriggerType]: string;
51
- constructor(id: string, options?: WebhookOptions);
8
+ constructor(id: string);
52
9
  then<OO>(task: Taskable<WebhookData, OO>): Workflow<OO>;
10
+ catch<OO>(error: any): Workflow<OO>;
53
11
  }
54
- export declare function webhook(id: string, options?: WebhookOptions): Trigger<WebhookData>;
12
+ export declare function webhook(id: string): Workflow<WebhookData>;
55
13
  //# sourceMappingURL=WebhookTrigger.d.ts.map
@@ -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,E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AAE,cAAc,GAAG,OAAO,CAAC,WAAW,CAAC,CAElF"}
1
+ {"version":3,"file":"WebhookTrigger.d.ts","sourceRoot":"","sources":["../../../../src/src/dsl/triggers/WebhookTrigger.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,QAAQ,EAAE,MAAM,YAAY,CAAC;AACtC,OAAO,EAAE,OAAO,EAAE,WAAW,EAAE,MAAM,eAAe,CAAC;AACrD,OAAO,EAAE,QAAQ,EAAgB,MAAM,gBAAgB,CAAC;AAExD,MAAM,MAAM,WAAW,GAAG,MAAM,CAAC,MAAM,EAAE,KAAK,CAAC,CAAC;AAEhD,qBAAa,cAAe,YAAW,OAAO,CAAC,WAAW,CAAC;IACvD,EAAE,EAAE,MAAM,CAAC;IAEX,CAAC,WAAW,CAAC,EAAE,MAAM,CAAa;gBAGtB,EAAE,EAAE,MAAM;IAItB,IAAI,CAAC,EAAE,EAAE,IAAI,EAAE,QAAQ,CAAC,WAAW,EAAE,EAAE,CAAC,GAAG,QAAQ,CAAC,EAAE,CAAC;IAIvD,KAAK,CAAC,EAAE,EAAE,KAAK,EAAE,GAAG,GAAG,QAAQ,CAAC,EAAE,CAAC;CAGtC;AAED,wBAAgB,OAAO,CAAC,EAAE,EAAE,MAAM,GAAG,QAAQ,CAAC,WAAW,CAAC,CAEzD"}
@@ -3,19 +3,13 @@ import { ensureTask } from "../ensureTask.js";
3
3
  import { TriggerType } from '../Trigger.js';
4
4
  import { WorkflowImpl } from '../Workflow.js';
5
5
  export class WebhookTrigger {
6
- constructor(id, options = {}) {
6
+ constructor(id) {
7
7
  Object.defineProperty(this, "id", {
8
8
  enumerable: true,
9
9
  configurable: true,
10
10
  writable: true,
11
11
  value: void 0
12
12
  });
13
- Object.defineProperty(this, "options", {
14
- enumerable: true,
15
- configurable: true,
16
- writable: true,
17
- value: void 0
18
- });
19
13
  Object.defineProperty(this, _a, {
20
14
  enumerable: true,
21
15
  configurable: true,
@@ -23,13 +17,15 @@ export class WebhookTrigger {
23
17
  value: 'webhook'
24
18
  });
25
19
  this.id = id;
26
- this.options = options;
27
20
  }
28
21
  then(task) {
29
22
  return new WorkflowImpl(this, ensureTask(task));
30
23
  }
24
+ catch(error) {
25
+ return this;
26
+ }
31
27
  }
32
28
  _a = TriggerType;
33
- export function webhook(id, options) {
34
- return new WebhookTrigger(id, options);
29
+ export function webhook(id) {
30
+ return new WebhookTrigger(id);
35
31
  }
@@ -1,5 +1,5 @@
1
1
  import { Router } from 'express';
2
- import { Observable, Subscription } from 'rxjs';
2
+ import { Observable } from 'rxjs';
3
3
  import { ContextProvider } from '../../context/ContextProvider.js';
4
4
  import { ConnectionProvider, RoundTripperFactory } from '../../dsl/http/types.js';
5
5
  import { Workflow } from '../../dsl/Workflow.js';
@@ -18,7 +18,6 @@ type Registration = {
18
18
  task$: ContextOperatorFunction<any, any, any>;
19
19
  localAbortController: AbortController;
20
20
  sigintListener: () => void;
21
- subscription?: Subscription;
22
21
  };
23
22
  export declare class MemoryInterpreter {
24
23
  private readonly log;
@@ -28,14 +27,10 @@ export declare class MemoryInterpreter {
28
27
  private readonly router;
29
28
  private readonly connectionProvider;
30
29
  private registeredWorkflows;
31
- private server?;
32
- private shutdownServer?;
33
- private isShuttingDown;
34
30
  constructor(log: Logger, compiler: ObservableCompiler, contextProvider: ContextProvider, roundTripperFactory: RoundTripperFactory, router: Router, connectionProvider: ConnectionProvider);
35
31
  static newInstance(options?: MemoryInterpreterOptions): Promise<MemoryInterpreter>;
36
32
  register<O>(workflow: Workflow<O>, options?: MemoryInterpreterOptions): Registration;
37
33
  start(): Promise<void>;
38
- stop(): Promise<void>;
39
34
  }
40
35
  export {};
41
36
  //# sourceMappingURL=MemoryInterpreter.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"MemoryInterpreter.d.ts","sourceRoot":"","sources":["../../../../src/src/interpreter/memory/MemoryInterpreter.ts"],"names":[],"mappings":"AAAA,OAAgB,EAAqB,MAAM,EAAE,MAAM,SAAS,CAAC;AAC7D,OAAO,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AAW,CAAC;IACrB,sBAAsB,CAAC,EAAE,OAAO,CAAC;CACpC,CAAC;AAEF,KAAK,YAAY,GAAG;IAChB,QAAQ,EAAE,UAAU,CAAC,WAAW,CAAC,GAAG,EAAE,IAAI,CAAC,CAAC,CAAC;IAC7C,KAAK,EAAE,uBAAuB,CAAC,GAAG,EAAE,GAAG,EAAE,GAAG,CAAC,CAAC;IAC9C,oBAAoB,EAAE,eAAe,CAAC;IACtC,cAAc,EAAE,MAAM,IAAI,CAAC;CAC9B,CAAA;AAED,qBAAa,iBAAiB;IAItB,OAAO,CAAC,QAAQ,CAAC,GAAG;IACpB,OAAO,CAAC,QAAQ,CAAC,QAAQ;IACzB,OAAO,CAAC,QAAQ,CAAC,eAAe;IAChC,OAAO,CAAC,QAAQ,CAAC,mBAAmB;IACpC,OAAO,CAAC,QAAQ,CAAC,MAAM;IACvB,OAAO,CAAC,QAAQ,CAAC,kBAAkB;IARvC,OAAO,CAAC,mBAAmB,CAA2B;gBAGjC,GAAG,EAAE,MAAM,EACX,QAAQ,EAAE,kBAAkB,EAC5B,eAAe,EAAE,eAAe,EAChC,mBAAmB,EAAE,mBAAmB,EACxC,MAAM,EAAE,MAAM,EACd,kBAAkB,EAAE,kBAAkB;WAI9C,WAAW,CAAC,OAAO,GAAE,wBAA6B,GAAG,OAAO,CAAC,iBAAiB,CAAC;IAoC5F,QAAQ,CAAC,CAAC,EAAE,QAAQ,EAAE,QAAQ,CAAC,CAAC,CAAC,EAAE,OAAO,CAAC,EAAE,wBAAwB;IA6C/D,KAAK,IAAI,OAAO,CAAC,IAAI,CAAC;CA0D/B"}
@@ -1,3 +1,4 @@
1
+ import * as dntShim from "../../../_dnt.shims.js";
1
2
  import express from 'express';
2
3
  import { catchError, EMPTY, mergeMap, of, tap } from 'rxjs';
3
4
  import { ContextProviderImpl } from '../../context/ContextProvider.js';
@@ -53,24 +54,6 @@ export class MemoryInterpreter {
53
54
  writable: true,
54
55
  value: []
55
56
  });
56
- Object.defineProperty(this, "server", {
57
- enumerable: true,
58
- configurable: true,
59
- writable: true,
60
- value: void 0
61
- });
62
- Object.defineProperty(this, "shutdownServer", {
63
- enumerable: true,
64
- configurable: true,
65
- writable: true,
66
- value: void 0
67
- });
68
- Object.defineProperty(this, "isShuttingDown", {
69
- enumerable: true,
70
- configurable: true,
71
- writable: true,
72
- value: false
73
- });
74
57
  }
75
58
  static async newInstance(options = {}) {
76
59
  const log = options.logger || new ConsoleLogger('debug');
@@ -120,7 +103,7 @@ export class MemoryInterpreter {
120
103
  return registration;
121
104
  }
122
105
  async start() {
123
- const port = Deno.env.get('PORT') || 3000;
106
+ const port = dntShim.Deno.env.get('PORT') || 3000;
124
107
  const app = express();
125
108
  app.use(express.json()); // Add JSON body parser middleware
126
109
  // Add health check route
@@ -131,13 +114,12 @@ export class MemoryInterpreter {
131
114
  app.use(this.router);
132
115
  // Start all registered workflows
133
116
  for (const registration of this.registeredWorkflows) {
134
- Deno.addSignalListener('SIGINT', registration.sigintListener);
135
- registration.subscription = registration.trigger$
117
+ dntShim.Deno.addSignalListener('SIGINT', registration.sigintListener);
118
+ registration.trigger$
136
119
  .pipe(tap((ctx) => {
137
120
  ctx.log.info('MemoryInterpreter.executionStarted', { data: ctx.data });
138
121
  }), mergeMap((ctx) => of(ctx).pipe(registration.task$, catchError((error) => {
139
122
  ctx.log.error('MemoryInterpreter.executionError', { error });
140
- ctx.options.onError?.(ctx.withData(error));
141
123
  return EMPTY;
142
124
  }))))
143
125
  .subscribe({
@@ -147,66 +129,20 @@ export class MemoryInterpreter {
147
129
  durationMs,
148
130
  data: ctx.data,
149
131
  });
150
- ctx.options.onSuccess?.(ctx);
151
132
  this.contextProvider.destroy(ctx);
152
133
  },
153
134
  error: (err) => {
154
135
  this.log.error('MemoryInterpreter.error', { error: err });
155
- Deno.removeSignalListener('SIGINT', registration.sigintListener);
136
+ dntShim.Deno.removeSignalListener('SIGINT', registration.sigintListener);
156
137
  },
157
138
  complete: () => {
158
139
  this.log.info('MemoryInterpreter.workflowCompleted');
159
- Deno.removeSignalListener('SIGINT', registration.sigintListener);
140
+ dntShim.Deno.removeSignalListener('SIGINT', registration.sigintListener);
160
141
  },
161
142
  });
162
- registration.subscription.add(() => {
163
- registration.subscription = undefined;
164
- });
165
143
  }
166
- this.server = app.listen(port, () => {
144
+ app.listen(port, () => {
167
145
  this.log.info(`Express server listening on http://localhost:${port}`);
168
146
  });
169
- this.shutdownServer = () => {
170
- if (this.isShuttingDown) {
171
- return;
172
- }
173
- this.isShuttingDown = true;
174
- this.log.info('Shutting down server');
175
- // Close the server
176
- if (this.server) {
177
- this.server.close();
178
- }
179
- // Remove all signal listeners
180
- for (const registration of this.registeredWorkflows) {
181
- Deno.removeSignalListener('SIGINT', registration.sigintListener);
182
- // Unsubscribe from all observables
183
- if (registration.subscription) {
184
- registration.subscription.unsubscribe();
185
- }
186
- // Abort all controllers
187
- registration.localAbortController.abort();
188
- }
189
- // Remove the server shutdown listener
190
- if (this.shutdownServer) {
191
- Deno.removeSignalListener('SIGINT', this.shutdownServer);
192
- }
193
- };
194
- Deno.addSignalListener('SIGINT', this.shutdownServer);
195
- return new Promise((resolve) => {
196
- if (this.server) {
197
- this.server.on('close', () => {
198
- this.log.info('Server closed');
199
- resolve();
200
- });
201
- }
202
- else {
203
- resolve();
204
- }
205
- });
206
- }
207
- async stop() {
208
- if (this.shutdownServer) {
209
- this.shutdownServer();
210
- }
211
147
  }
212
148
  }
@@ -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;AA8B7C,eAAO,MAAM,eAAe,EAAE,eAAe,CAAC,WAAW,EAAE,cAAc,CA8KxE,CAAC"}
1
+ {"version":3,"file":"webhook.d.ts","sourceRoot":"","sources":["../../../../../src/src/interpreter/memory/compilers/webhook.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,WAAW,EAAE,cAAc,EAAE,MAAM,yCAAyC,CAAC;AACtF,OAAO,EAAE,eAAe,EAAE,MAAM,YAAY,CAAC;AAK7C,eAAO,MAAM,eAAe,EAAE,eAAe,CAAC,WAAW,EAAE,cAAc,CAwGxE,CAAC"}
@@ -1,136 +1,71 @@
1
1
  // In src/interpreter/memory/compilers/webhook.ts
2
- import cors from 'cors';
3
2
  import { Observable } from 'rxjs';
4
- import { pipeline } from "node:stream/promises";
5
3
  import { WebhookTrigger } from '../../../dsl/triggers/WebhookTrigger.js';
6
- const DEFAULT_SYNC_ON_SUCCESS = (ctx) => new Response(JSON.stringify(ctx.data), { status: 200 });
7
- const DEFAULT_SYNC_ON_ERROR = (ctx) => new Response(JSON.stringify({ message: 'Internal server error', error: ctx.data }), {
8
- status: 500,
9
- });
10
- const DEFAULT_ASYNC_ON_SUCCESS = (ctx) => new Response(JSON.stringify({
11
- status: 'accepted',
12
- executionId: ctx.executionId,
13
- startTime: ctx.startTime,
14
- }), { status: 202 });
15
- const DEFAULT_ASYNC_ON_ERROR = (ctx) => new Response(JSON.stringify({
16
- message: 'Internal server error',
17
- executionId: ctx.executionId,
18
- startTime: ctx.startTime,
19
- }), {
20
- status: 500,
21
- });
22
4
  export const webhookCompiler = {
23
5
  ctor: WebhookTrigger,
24
6
  compile: (ctx, trigger, signal) => {
25
- const { response: { mode = 'async', } = {}, cors: corsOptions, } = trigger.options;
26
- const isSync = mode === 'sync';
27
- const isAsync = mode === 'async';
28
- if (!isSync && !isAsync) {
29
- throw new Error('Invalid response mode, must be either "sync" or "async"');
30
- }
31
- let onSuccess = isSync ? DEFAULT_SYNC_ON_SUCCESS : DEFAULT_ASYNC_ON_SUCCESS;
32
- let onError = isSync ? DEFAULT_SYNC_ON_ERROR : DEFAULT_ASYNC_ON_ERROR;
33
- if (trigger.options.response?.onSuccess) {
34
- onSuccess = trigger.options.response.onSuccess;
35
- }
36
- if (trigger.options.response?.onError) {
37
- onError = trigger.options.response.onError;
38
- }
39
- const ctxOptionsFn = (res) => ({
40
- onSuccess: (ctx) => {
41
- if (isSync) {
42
- sendResponse(res, onSuccess(ctx));
43
- }
44
- },
45
- onError: (ctx) => {
46
- if (isSync) {
47
- sendResponse(res, onError(ctx));
48
- }
49
- },
50
- });
51
7
  return new Observable((subscriber) => {
52
8
  if (!ctx.router) {
53
9
  throw new Error('Router not available in compiler context');
54
10
  }
55
11
  // add the webhook endpoint to the router
56
12
  ctx.log.info('webhook endpoint added:', { trigger });
57
- if (corsOptions) {
58
- if (typeof corsOptions === 'boolean') {
59
- ctx.router.use(cors());
60
- }
61
- else {
62
- ctx.router.use(cors(corsOptions));
63
- }
64
- }
65
13
  // endpoint for sans user because I'm not quite sure how the dynamic routing works
66
14
  ctx.router.post(`/${trigger.id}`, (req, res) => {
67
- const executionCtx = ctx.contextProvider.create(req.body, ctxOptionsFn(res));
15
+ const executionCtx = ctx.contextProvider.create(req.body, undefined);
68
16
  try {
69
17
  subscriber.next(executionCtx);
70
- if (isAsync) {
71
- sendResponse(res, onSuccess(executionCtx));
72
- }
18
+ res.status(200).json({ status: 'accepted' });
73
19
  }
74
20
  catch (error) {
75
- executionCtx.log.error('webhook execution error', {
76
- error: JSON.stringify(error),
77
- });
78
- if (isAsync) {
79
- sendResponse(res, onError(executionCtx.withData(error)));
80
- }
21
+ const message = error instanceof Error ? error.message : 'Unknown error';
22
+ executionCtx.log.error('webhook execution error', { error });
23
+ res.status(500).json({ status: 'error', message });
81
24
  }
82
25
  });
83
26
  // this endpoint will trigger the workflow for each activation given by the external user ID
84
27
  ctx.router.post(`/${trigger.id}/users/:userId`, async (req, res) => {
85
- const userId = req.params.userId;
28
+ const userId = req.params.userId || undefined;
29
+ if (!userId) {
30
+ res.status(400).json({ status: 'error', message: 'User ID is required' });
31
+ return;
32
+ }
86
33
  const activations = await ctx.connectionProvider.getUserActivations(userId);
87
- const executionCtx = ctx.contextProvider.create(req.body, ctxOptionsFn(res));
88
- const errors = [];
34
+ if (!activations || activations.length === 0) {
35
+ res.status(404).json({ status: 'error', message: `No activations found for user: ${userId}` });
36
+ return;
37
+ }
89
38
  activations.forEach((activation) => {
90
- const activationCtx = executionCtx.withActivation(activation);
39
+ const executionCtx = ctx.contextProvider.create(req.body, activation);
91
40
  try {
92
- subscriber.next(activationCtx);
41
+ subscriber.next(executionCtx);
93
42
  }
94
43
  catch (error) {
95
- activationCtx.log.error('webhook execution error', {
96
- error: JSON.stringify(error),
97
- });
98
- errors.push({
99
- activationId: activation.id,
100
- error,
101
- });
44
+ const message = error instanceof Error ? error.message : 'Unknown error';
45
+ executionCtx.log.error('webhook execution error', { error });
46
+ res.status(500).json({ status: 'error', message });
102
47
  }
103
48
  });
104
- if (isAsync) {
105
- if (errors.length === 0) {
106
- sendResponse(res, onSuccess(executionCtx));
107
- }
108
- else {
109
- sendResponse(res, onError(executionCtx.withData(errors)));
110
- }
111
- }
49
+ res.status(200).json({ status: 'accepted' });
112
50
  });
113
51
  // this endpoint will trigger the workflow only for the activation given by its ID
114
52
  ctx.router.post(`/${trigger.id}/activations/:activationId`, async (req, res) => {
115
- const activationId = req.params.activationId;
53
+ const activationId = req.params.activationId || undefined;
116
54
  const activation = await ctx.connectionProvider.getActivation(activationId);
117
- const activationCtx = ctx.contextProvider.create(req.body, {
118
- ...ctxOptionsFn(res),
119
- activation,
120
- });
55
+ if (!activation) {
56
+ // TODO report back actual errors
57
+ res.status(404).json({ status: 'error', message: `No activation found for ID: ${activationId}` });
58
+ return;
59
+ }
60
+ const executionCtx = ctx.contextProvider.create(req.body, activation);
121
61
  try {
122
- subscriber.next(activationCtx);
123
- if (isAsync) {
124
- sendResponse(res, onSuccess(activationCtx));
125
- }
62
+ subscriber.next(executionCtx);
63
+ res.status(200).json({ status: 'accepted' });
126
64
  }
127
65
  catch (error) {
128
- activationCtx.log.error('webhook execution error', {
129
- error: JSON.stringify(error),
130
- });
131
- if (isAsync) {
132
- sendResponse(res, onError(activationCtx.withData(error)));
133
- }
66
+ const message = error instanceof Error ? error.message : 'Unknown error';
67
+ executionCtx.log.error('webhook execution error', { error });
68
+ res.status(500).json({ status: 'error', message });
134
69
  }
135
70
  });
136
71
  function cleanup() {
@@ -145,12 +80,3 @@ export const webhookCompiler = {
145
80
  });
146
81
  },
147
82
  };
148
- function sendResponse(res, response) {
149
- res.status(response.status);
150
- response.headers.forEach((value, key) => {
151
- res.setHeader(key, value);
152
- });
153
- if (response.body) {
154
- pipeline(response.body, res);
155
- }
156
- }