@versori/run 0.2.0-alpha.1 → 0.2.0-alpha.11

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 (117) hide show
  1. package/{script/deps/jsr.io/@std/fmt/1.0.6 → esm/deps/jsr.io/@std/fmt/1.0.7}/colors.d.ts.map +1 -1
  2. package/esm/deps/jsr.io/@std/fs/{1.0.16 → 1.0.17}/exists.d.ts.map +1 -1
  3. package/esm/deps/jsr.io/@std/log/0.224.14/console_handler.js +1 -1
  4. package/esm/deps/jsr.io/@std/log/0.224.14/rotating_file_handler.js +1 -1
  5. package/esm/src/context/Context.d.ts +7 -1
  6. package/esm/src/context/Context.d.ts.map +1 -1
  7. package/esm/src/context/Context.js +30 -4
  8. package/esm/src/context/ContextProvider.d.ts +3 -1
  9. package/esm/src/context/ContextProvider.d.ts.map +1 -1
  10. package/esm/src/context/ContextProvider.js +9 -2
  11. package/esm/src/dsl/http/default.d.ts +2 -0
  12. package/esm/src/dsl/http/default.d.ts.map +1 -1
  13. package/esm/src/dsl/http/default.js +10 -0
  14. package/esm/src/dsl/http/types.d.ts +13 -2
  15. package/esm/src/dsl/http/types.d.ts.map +1 -1
  16. package/esm/src/dsl/http/versori/activation.d.ts +13 -0
  17. package/esm/src/dsl/http/versori/activation.d.ts.map +1 -0
  18. package/esm/src/dsl/http/versori/activation.js +65 -0
  19. package/esm/src/dsl/http/versori/constants.d.ts +5 -0
  20. package/esm/src/dsl/http/versori/constants.d.ts.map +1 -1
  21. package/esm/src/dsl/http/versori/constants.js +5 -0
  22. package/esm/src/dsl/http/versori/contextcredentials.d.ts +10 -0
  23. package/esm/src/dsl/http/versori/contextcredentials.d.ts.map +1 -0
  24. package/esm/src/dsl/http/versori/contextcredentials.js +1 -0
  25. package/esm/src/dsl/http/versori/credentials/client.d.ts +4 -4
  26. package/esm/src/dsl/http/versori/credentials/client.d.ts.map +1 -1
  27. package/esm/src/dsl/http/versori/credentials/client.js +8 -13
  28. package/esm/src/dsl/http/versori/credentials/credentials.d.ts +38 -0
  29. package/esm/src/dsl/http/versori/credentials/credentials.d.ts.map +1 -1
  30. package/esm/src/dsl/http/versori/credentials/credentials.js +7 -8
  31. package/esm/src/dsl/http/versori/credentials/v1alpha1/common_pb.d.ts +31 -0
  32. package/esm/src/dsl/http/versori/credentials/v1alpha1/common_pb.d.ts.map +1 -0
  33. package/esm/src/dsl/http/versori/credentials/v1alpha1/common_pb.js +31 -0
  34. package/esm/src/dsl/http/versori/credentials/v1alpha1/credential_service_pb.d.ts +84 -0
  35. package/esm/src/dsl/http/versori/credentials/v1alpha1/credential_service_pb.d.ts.map +1 -0
  36. package/esm/src/dsl/http/versori/credentials/v1alpha1/credential_service_pb.js +128 -0
  37. package/esm/src/dsl/http/versori/cronapi.d.ts +10 -0
  38. package/esm/src/dsl/http/versori/cronapi.d.ts.map +1 -0
  39. package/esm/src/dsl/http/versori/cronapi.js +51 -0
  40. package/esm/src/dsl/http/versori/platformapi.d.ts +4 -1
  41. package/esm/src/dsl/http/versori/platformapi.d.ts.map +1 -1
  42. package/esm/src/dsl/http/versori/platformapi.js +38 -6
  43. package/esm/src/dsl/http/versori/roundtripper.d.ts +11 -5
  44. package/esm/src/dsl/http/versori/roundtripper.d.ts.map +1 -1
  45. package/esm/src/dsl/http/versori/roundtripper.js +168 -75
  46. package/esm/src/interpreter/memory/MemoryInterpreter.d.ts +4 -2
  47. package/esm/src/interpreter/memory/MemoryInterpreter.d.ts.map +1 -1
  48. package/esm/src/interpreter/memory/MemoryInterpreter.js +49 -10
  49. package/esm/src/interpreter/memory/ObservableCompiler.d.ts +1 -0
  50. package/esm/src/interpreter/memory/ObservableCompiler.d.ts.map +1 -1
  51. package/esm/src/interpreter/memory/compilers/schedule.d.ts.map +1 -1
  52. package/esm/src/interpreter/memory/compilers/schedule.js +18 -23
  53. package/esm/src/observability/logging/ConsoleLogger.d.ts.map +1 -1
  54. package/esm/src/observability/logging/ConsoleLogger.js +55 -10
  55. package/package.json +1 -1
  56. package/{esm/deps/jsr.io/@std/fmt/1.0.6 → script/deps/jsr.io/@std/fmt/1.0.7}/colors.d.ts.map +1 -1
  57. package/script/deps/jsr.io/@std/fs/{1.0.16 → 1.0.17}/exists.d.ts.map +1 -1
  58. package/script/deps/jsr.io/@std/log/0.224.14/console_handler.js +1 -1
  59. package/script/deps/jsr.io/@std/log/0.224.14/rotating_file_handler.js +1 -1
  60. package/script/src/context/Context.d.ts +7 -1
  61. package/script/src/context/Context.d.ts.map +1 -1
  62. package/script/src/context/Context.js +30 -4
  63. package/script/src/context/ContextProvider.d.ts +3 -1
  64. package/script/src/context/ContextProvider.d.ts.map +1 -1
  65. package/script/src/context/ContextProvider.js +9 -2
  66. package/script/src/dsl/http/default.d.ts +2 -0
  67. package/script/src/dsl/http/default.d.ts.map +1 -1
  68. package/script/src/dsl/http/default.js +10 -0
  69. package/script/src/dsl/http/types.d.ts +13 -2
  70. package/script/src/dsl/http/types.d.ts.map +1 -1
  71. package/script/src/dsl/http/versori/activation.d.ts +13 -0
  72. package/script/src/dsl/http/versori/activation.d.ts.map +1 -0
  73. package/script/src/dsl/http/versori/activation.js +69 -0
  74. package/script/src/dsl/http/versori/constants.d.ts +5 -0
  75. package/script/src/dsl/http/versori/constants.d.ts.map +1 -1
  76. package/script/src/dsl/http/versori/constants.js +6 -1
  77. package/script/src/dsl/http/versori/contextcredentials.d.ts +10 -0
  78. package/script/src/dsl/http/versori/contextcredentials.d.ts.map +1 -0
  79. package/script/src/dsl/http/versori/contextcredentials.js +2 -0
  80. package/script/src/dsl/http/versori/credentials/client.d.ts +4 -4
  81. package/script/src/dsl/http/versori/credentials/client.d.ts.map +1 -1
  82. package/script/src/dsl/http/versori/credentials/client.js +7 -10
  83. package/script/src/dsl/http/versori/credentials/credentials.d.ts +38 -0
  84. package/script/src/dsl/http/versori/credentials/credentials.d.ts.map +1 -1
  85. package/script/src/dsl/http/versori/credentials/credentials.js +8 -8
  86. package/script/src/dsl/http/versori/credentials/v1alpha1/common_pb.d.ts +31 -0
  87. package/script/src/dsl/http/versori/credentials/v1alpha1/common_pb.d.ts.map +1 -0
  88. package/script/src/dsl/http/versori/credentials/v1alpha1/common_pb.js +34 -0
  89. package/script/src/dsl/http/versori/credentials/v1alpha1/credential_service_pb.d.ts +84 -0
  90. package/script/src/dsl/http/versori/credentials/v1alpha1/credential_service_pb.d.ts.map +1 -0
  91. package/script/src/dsl/http/versori/credentials/v1alpha1/credential_service_pb.js +131 -0
  92. package/script/src/dsl/http/versori/cronapi.d.ts +10 -0
  93. package/script/src/dsl/http/versori/cronapi.d.ts.map +1 -0
  94. package/script/src/dsl/http/versori/cronapi.js +55 -0
  95. package/script/src/dsl/http/versori/platformapi.d.ts +4 -1
  96. package/script/src/dsl/http/versori/platformapi.d.ts.map +1 -1
  97. package/script/src/dsl/http/versori/platformapi.js +38 -6
  98. package/script/src/dsl/http/versori/roundtripper.d.ts +11 -5
  99. package/script/src/dsl/http/versori/roundtripper.d.ts.map +1 -1
  100. package/script/src/dsl/http/versori/roundtripper.js +170 -77
  101. package/script/src/interpreter/memory/MemoryInterpreter.d.ts +4 -2
  102. package/script/src/interpreter/memory/MemoryInterpreter.d.ts.map +1 -1
  103. package/script/src/interpreter/memory/MemoryInterpreter.js +48 -9
  104. package/script/src/interpreter/memory/ObservableCompiler.d.ts +1 -0
  105. package/script/src/interpreter/memory/ObservableCompiler.d.ts.map +1 -1
  106. package/script/src/interpreter/memory/compilers/schedule.d.ts.map +1 -1
  107. package/script/src/interpreter/memory/compilers/schedule.js +18 -23
  108. package/script/src/observability/logging/ConsoleLogger.d.ts.map +1 -1
  109. package/script/src/observability/logging/ConsoleLogger.js +55 -10
  110. /package/esm/deps/jsr.io/@std/fmt/{1.0.6 → 1.0.7}/colors.d.ts +0 -0
  111. /package/esm/deps/jsr.io/@std/fmt/{1.0.6 → 1.0.7}/colors.js +0 -0
  112. /package/esm/deps/jsr.io/@std/fs/{1.0.16 → 1.0.17}/exists.d.ts +0 -0
  113. /package/esm/deps/jsr.io/@std/fs/{1.0.16 → 1.0.17}/exists.js +0 -0
  114. /package/script/deps/jsr.io/@std/fmt/{1.0.6 → 1.0.7}/colors.d.ts +0 -0
  115. /package/script/deps/jsr.io/@std/fmt/{1.0.6 → 1.0.7}/colors.js +0 -0
  116. /package/script/deps/jsr.io/@std/fs/{1.0.16 → 1.0.17}/exists.d.ts +0 -0
  117. /package/script/deps/jsr.io/@std/fs/{1.0.16 → 1.0.17}/exists.js +0 -0
@@ -1,11 +1,12 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.VersoriRoundTripperFactory = void 0;
3
+ exports.VersoriCredentialsFactory = void 0;
4
4
  const configloader_js_1 = require("./configloader.js");
5
5
  const mod_js_1 = require("./credentials/mod.js");
6
6
  const platformapi_js_1 = require("./platformapi.js");
7
7
  const mod_js_2 = require("../../../observability/mod.js");
8
8
  const constants_js_1 = require("./constants.js");
9
+ const connect_1 = require("@connectrpc/connect");
9
10
  /**
10
11
  * VersoriRoundTripper is an implementation of the RoundTripperFactory interface for Versori connections.
11
12
  * This is the intended implementation for when projects/services are hosted on Versori infrastructure.
@@ -13,19 +14,25 @@ const constants_js_1 = require("./constants.js");
13
14
  *
14
15
  * @example
15
16
  * ```typescript
16
- * const factory = new VersoriRoundTripperFactory(connectAPIClient, tokenClient);
17
+ * const factory = new VersoriCredentialsFactory(connectAPIClient, tokenClient);
17
18
  * const customFetch = await factory.create('connectionName');
18
19
  * const response = await customFetch('https://api.example.com/data');
19
20
  * ```
20
21
  */
21
- class VersoriRoundTripperFactory {
22
- constructor(credsClient, platformAPIClient, logger) {
22
+ class VersoriCredentialsFactory {
23
+ constructor(credsClient, credsBaseURL, platformAPIClient, logger) {
23
24
  Object.defineProperty(this, "tokenClient", {
24
25
  enumerable: true,
25
26
  configurable: true,
26
27
  writable: true,
27
28
  value: void 0
28
29
  });
30
+ Object.defineProperty(this, "credsBaseURL", {
31
+ enumerable: true,
32
+ configurable: true,
33
+ writable: true,
34
+ value: void 0
35
+ });
29
36
  Object.defineProperty(this, "platformAPIClient", {
30
37
  enumerable: true,
31
38
  configurable: true,
@@ -56,9 +63,11 @@ class VersoriRoundTripperFactory {
56
63
  }
57
64
  });
58
65
  this.tokenClient = credsClient;
66
+ this.credsBaseURL = credsBaseURL;
59
67
  this.platformAPIClient = platformAPIClient;
60
68
  this.versoriCfg = (0, configloader_js_1.LoadConfigFromFile)();
61
69
  this.log = logger;
70
+ this.credentials = this.credentials.bind(this);
62
71
  }
63
72
  static fromEnv(logger) {
64
73
  const credsBaseURL = Deno.env.get(constants_js_1.envVarCredsBaseURL);
@@ -77,20 +86,23 @@ class VersoriRoundTripperFactory {
77
86
  missingVars.push(constants_js_1.envVarCredsBaseURL);
78
87
  throw new Error(`Missing environment variables: ${missingVars.join(', ')}`);
79
88
  }
80
- const pAPIClient = new platformapi_js_1.PlatformAPIClient(platformApiBaseURL, orgId, envId);
81
- const tokenClient = new mod_js_1.VersoriCredentialClient(credsBaseURL);
82
89
  const log = logger || new mod_js_2.ConsoleLogger('debug');
83
- return new VersoriRoundTripperFactory(tokenClient, pAPIClient, log);
90
+ const pAPIClient = new platformapi_js_1.PlatformAPIClient(platformApiBaseURL, orgId, envId, log);
91
+ const tokenClient = new mod_js_1.VersoriCredentialClient(credsBaseURL);
92
+ return new VersoriCredentialsFactory(tokenClient, credsBaseURL, pAPIClient, log);
84
93
  }
85
94
  // takes the info and modifies the url using changeBaseUrl if necessary
95
+ // if a full valid URL is passed as a string, it will be returned as is
96
+ // if a valid URL object is passed, it will be returned as is
86
97
  changeRequestInit(info, conn) {
87
98
  if (typeof info === 'string') {
88
- // should be this most of the time assuming we're using pathnames
99
+ if (isValidURL(info)) {
100
+ return info;
101
+ }
89
102
  return this.changeBaseUrl(info, conn);
90
103
  }
91
104
  else if (info instanceof URL) {
92
- const newUrl = new URL(this.changeBaseUrl(info.toString(), conn));
93
- return newUrl;
105
+ return info;
94
106
  }
95
107
  else if (info instanceof Request) {
96
108
  const url = this.changeBaseUrl(info.url, conn);
@@ -102,6 +114,7 @@ class VersoriRoundTripperFactory {
102
114
  const connBaseURL = conn.baseUrl;
103
115
  // if the connection has no baseUrl set, but the pathname is a valid URL, return it as is
104
116
  if (!connBaseURL && isValidURL(pathname)) {
117
+ this.log.debug('Using given URL as is', { url: pathname });
105
118
  return pathname;
106
119
  }
107
120
  const connBaseURLObj = new URL(connBaseURL);
@@ -111,36 +124,45 @@ class VersoriRoundTripperFactory {
111
124
  _pathname = pathnameObj.pathname;
112
125
  }
113
126
  const newURL = new URL(_pathname, connBaseURLObj.origin);
127
+ this.log.debug('Using baseURL from connection', { url: newURL.toString() });
114
128
  return newURL.toString();
115
129
  }
116
- // TODO: Currently if the connection is edited, then the fetcher will not be updated.
117
- async create(connName, fn = globalThis.fetch) {
130
+ create(connName, fn = globalThis.fetch) {
118
131
  const cnxId = this.getConnectionID(connName);
119
- const conn = await this.platformAPIClient.getStaticConnection(cnxId);
120
- if (!conn) {
132
+ if (!cnxId) {
133
+ this.log.debug('Connection not found in config, could be a dynamic connection', {
134
+ connectionName: connName,
135
+ });
121
136
  return undefined;
122
137
  }
123
- const _fn = (input, init) => {
138
+ const _fn = async (input, init) => {
139
+ const conn = await this.platformAPIClient.getStaticConnection(cnxId);
140
+ if (!conn) {
141
+ this.log.error('Connection not found for user, using default fetch', {
142
+ connectionName: connName,
143
+ });
144
+ return globalThis.fetch(input, init);
145
+ }
124
146
  const _input = this.changeRequestInit(input, conn);
125
- return fn(_input, init);
147
+ switch (conn.credentials[0].authSchemeConfig.type) {
148
+ case 'api-key':
149
+ return (await this.apiKeyFetcher(conn, fn))(_input, init);
150
+ case 'basic-auth':
151
+ return (await this.basicAuthFetcher(conn, fn))(_input, init);
152
+ case 'jwt-bearer':
153
+ return (await this.bearerTokenFetcher(conn, fn))(_input, init);
154
+ case 'oauth2':
155
+ return (await this.oauth2Fetcher(conn, fn))(_input, init);
156
+ default:
157
+ return fn(_input, init);
158
+ }
126
159
  };
127
- switch (conn.credentials[0].authSchemeConfig.type) {
128
- case 'api-key':
129
- return this.apiKeyFetcher(conn, _fn);
130
- case 'basic-auth':
131
- return this.basicAuthFetcher(conn, _fn);
132
- case 'jwt-bearer':
133
- return this.bearerTokenFetcher(conn, _fn);
134
- case 'oauth2':
135
- return this.oauth2Fetcher(conn, _fn);
136
- default:
137
- return fn;
138
- }
160
+ return _fn;
139
161
  }
140
- async createDynamic(templateName, fn = globalThis.fetch) {
162
+ createDynamic(templateName, fn = globalThis.fetch) {
141
163
  const template = this.getTemplateID(templateName);
142
164
  if (!template) {
143
- this.log.info('Template not found in config, could be a static connection', {
165
+ this.log.debug('Template not found in config, could be a static connection', {
144
166
  templateName: templateName,
145
167
  });
146
168
  return undefined;
@@ -170,8 +192,50 @@ class VersoriRoundTripperFactory {
170
192
  };
171
193
  return _fn;
172
194
  }
195
+ credentials() {
196
+ return {
197
+ getRaw: this.getRawByName.bind(this),
198
+ getAccessToken: this.getTokenByName.bind(this),
199
+ };
200
+ }
201
+ async getTokenByName(name) {
202
+ const credId = await this.getCredentialIDFromName(name);
203
+ const token = await this.tokenClient.getToken(credId);
204
+ if (!token?.token) {
205
+ throw new Error(`Token not found for connection ${name} with credential ID ${credId}`);
206
+ }
207
+ return {
208
+ accessToken: token.token.accessToken,
209
+ tokenType: token.token.tokenType,
210
+ expiry: token.token.expiry ? new Date(Number(token.token.expiry.seconds) * 1000) : undefined,
211
+ };
212
+ }
213
+ async getRawByName(name) {
214
+ const credId = await this.getCredentialIDFromName(name);
215
+ const raw = await this.tokenClient.getRaw(credId);
216
+ if (!raw) {
217
+ throw new Error(`Raw data not found for connection ${name} with credential ID ${credId}`);
218
+ }
219
+ let buffer = raw?.credential?.data['raw'];
220
+ return buffer;
221
+ }
222
+ async getCredentialIDFromName(name) {
223
+ const conId = this.getConnectionID(name);
224
+ if (!conId) {
225
+ throw new Error(`Connection ${name} not found`);
226
+ }
227
+ const conn = await this.platformAPIClient.getStaticConnection(conId);
228
+ if (!conn) {
229
+ throw new Error(`Connection ${name} not found`);
230
+ }
231
+ if (!conn?.credentials[0]?.credential?.id) {
232
+ throw new Error(`Connection ${name}/${conId} has no credentials defined on it`);
233
+ }
234
+ return conn.credentials[0].credential.id;
235
+ }
173
236
  getConnectionID(connName) {
174
- const conn = this.versoriCfg.mappings.find((c) => (c.dynamic === undefined || c.dynamic === false) && c.name.toLowerCase() === connName.toLowerCase());
237
+ const conn = this.versoriCfg.mappings.find((c) => (c.dynamic === undefined || c.dynamic === false) &&
238
+ c.name.toLowerCase() === connName.toLowerCase());
175
239
  if (!conn || !conn.connId) {
176
240
  return '';
177
241
  }
@@ -184,17 +248,17 @@ class VersoriRoundTripperFactory {
184
248
  }
185
249
  return template.templateId;
186
250
  }
187
- async apiKeyFetcher(conn, fn) {
188
- const tokenResponse = await this.tokenClient.getToken(conn.credentials[0].credential.id);
189
- const token = tokenResponse.token?.accessToken;
190
- const asc = conn.credentials[0].authSchemeConfig.apiKey;
191
- if (!token) {
192
- throw new Error('Token not found');
193
- }
194
- if (!asc) {
195
- throw new Error('API Key configuration not found');
196
- }
197
- const _fn = (input, init) => {
251
+ apiKeyFetcher(conn, fn) {
252
+ const _fn = async (input, init) => {
253
+ const tokenResponse = await this.getToken(conn.credentials[0].credential.id);
254
+ const token = tokenResponse.token?.accessToken;
255
+ const asc = conn.credentials[0].authSchemeConfig.apiKey;
256
+ if (!token) {
257
+ throw new Error('Token not found');
258
+ }
259
+ if (!asc) {
260
+ throw new Error('API Key configuration not found');
261
+ }
198
262
  if (!init) {
199
263
  init = {};
200
264
  }
@@ -232,13 +296,13 @@ class VersoriRoundTripperFactory {
232
296
  };
233
297
  return _fn;
234
298
  }
235
- async basicAuthFetcher(conn, fn) {
236
- const tokenResponse = await this.tokenClient.getToken(conn.credentials[0].credential.id);
237
- const token = tokenResponse.token?.accessToken;
238
- if (!token) {
239
- throw new Error('Token not found');
240
- }
241
- const _fn = (input, init) => {
299
+ basicAuthFetcher(conn, fn) {
300
+ const _fn = async (input, init) => {
301
+ const tokenResponse = await this.getToken(conn.credentials[0].credential.id);
302
+ const token = tokenResponse.token?.accessToken;
303
+ if (!token) {
304
+ throw new Error('Token not found');
305
+ }
242
306
  if (!init) {
243
307
  init = {};
244
308
  }
@@ -262,13 +326,13 @@ class VersoriRoundTripperFactory {
262
326
  return _fn;
263
327
  }
264
328
  // TODO: need to make the prefix and header name configurable from authschemeconfig
265
- async bearerTokenFetcher(conn, fn) {
266
- const tokenResponse = await this.tokenClient.getToken(conn.credentials[0].credential.id);
267
- const token = tokenResponse.token?.accessToken;
268
- if (!token) {
269
- throw new Error('Token not found');
270
- }
271
- const _fn = (input, init) => {
329
+ bearerTokenFetcher(conn, fn) {
330
+ const _fn = async (input, init) => {
331
+ const tokenResponse = await this.getToken(conn.credentials[0].credential.id);
332
+ const token = tokenResponse.token?.accessToken;
333
+ if (!token) {
334
+ throw new Error('Token not found');
335
+ }
272
336
  if (!init) {
273
337
  init = {};
274
338
  }
@@ -291,27 +355,27 @@ class VersoriRoundTripperFactory {
291
355
  };
292
356
  return _fn;
293
357
  }
294
- async oauth2Fetcher(conn, fn) {
295
- const tokenResponse = await this.tokenClient.getOAuth2Token(conn.credentials[0].credential.id);
296
- const token = tokenResponse.token?.accessToken;
297
- const tokenType = tokenResponse.token?.tokenType;
298
- if (!token) {
299
- throw new Error('Token not found');
300
- }
301
- const _tokenType = () => {
302
- const _tt = tokenType?.toLowerCase();
303
- switch (_tt) {
304
- case 'bearer':
305
- return 'Bearer';
306
- case 'mac':
307
- return 'MAC';
308
- case 'basic':
309
- return 'Basic';
310
- default:
311
- return 'Bearer';
358
+ oauth2Fetcher(conn, fn) {
359
+ const refreshFn = async (input, init, forceRefresh = false) => {
360
+ const tokenResponse = await this.getToken(conn.credentials[0].credential.id, forceRefresh);
361
+ const token = tokenResponse.token?.accessToken;
362
+ const tokenType = tokenResponse.token?.tokenType;
363
+ if (!token) {
364
+ throw new Error('Token not found');
312
365
  }
313
- };
314
- const _fn = (input, init) => {
366
+ const _tokenType = () => {
367
+ const _tt = tokenType?.toLowerCase();
368
+ switch (_tt) {
369
+ case 'bearer':
370
+ return 'Bearer';
371
+ case 'mac':
372
+ return 'MAC';
373
+ case 'basic':
374
+ return 'Basic';
375
+ default:
376
+ return 'Bearer';
377
+ }
378
+ };
315
379
  if (!init) {
316
380
  init = {};
317
381
  }
@@ -332,10 +396,39 @@ class VersoriRoundTripperFactory {
332
396
  }
333
397
  return fn(input, init);
334
398
  };
399
+ const _fn = async (input, init) => {
400
+ const resp = await refreshFn(input, init, false);
401
+ if (resp.status === 401) {
402
+ this.log.debug('Received 401 Unauthorized response, attempting refresh', {
403
+ url: input,
404
+ status: resp.status,
405
+ });
406
+ // TODO: attempt refresh until precondition failed??
407
+ return refreshFn(input, init, true);
408
+ }
409
+ return Promise.resolve(resp);
410
+ };
335
411
  return _fn;
336
412
  }
413
+ async getToken(id) {
414
+ try {
415
+ return await this.tokenClient.getToken(id);
416
+ }
417
+ catch (error) {
418
+ this.log.error('unable to get credential', { error });
419
+ if (error instanceof connect_1.ConnectError) {
420
+ if (error.rawMessage.includes("connection error received: not a result of an error") && error.code === connect_1.Code.Internal) {
421
+ this.log.info('Connection error received, attempting to reconnect');
422
+ this.tokenClient = new mod_js_1.VersoriCredentialClient(this.credsBaseURL);
423
+ return await this.tokenClient.getToken(id);
424
+ }
425
+ throw error;
426
+ }
427
+ throw error;
428
+ }
429
+ }
337
430
  }
338
- exports.VersoriRoundTripperFactory = VersoriRoundTripperFactory;
431
+ exports.VersoriCredentialsFactory = VersoriCredentialsFactory;
339
432
  function isValidURL(url) {
340
433
  try {
341
434
  new URL(url);
@@ -1,7 +1,7 @@
1
1
  import { Router } from 'express';
2
2
  import { Observable, Subscription } from 'rxjs';
3
3
  import { ContextProvider } from '../../context/ContextProvider.js';
4
- import { ConnectionProvider, RoundTripperFactory } from '../../dsl/http/types.js';
4
+ import { ConnectionProvider, CronProvider, RoundTripperFactory } from '../../dsl/http/types.js';
5
5
  import { Workflow } from '../../dsl/Workflow.js';
6
6
  import { Logger } from '../../observability/logging/Logger.js';
7
7
  import { ObservableCompiler } from './ObservableCompiler.js';
@@ -26,12 +26,14 @@ export declare class MemoryInterpreter {
26
26
  private readonly contextProvider;
27
27
  private readonly roundTripperFactory;
28
28
  private readonly router;
29
+ private cronRegistry;
29
30
  private readonly connectionProvider;
31
+ private readonly cronProvider;
30
32
  private registeredWorkflows;
31
33
  private server?;
32
34
  private shutdownServer?;
33
35
  private isShuttingDown;
34
- constructor(log: Logger, compiler: ObservableCompiler, contextProvider: ContextProvider, roundTripperFactory: RoundTripperFactory, router: Router, connectionProvider: ConnectionProvider);
36
+ constructor(log: Logger, compiler: ObservableCompiler, contextProvider: ContextProvider, roundTripperFactory: RoundTripperFactory, router: Router, cronRegistry: Map<string, string>, connectionProvider: ConnectionProvider, cronProvider: CronProvider);
35
37
  static newInstance(options?: MemoryInterpreterOptions): Promise<MemoryInterpreter>;
36
38
  register<O>(workflow: Workflow<O>, options?: MemoryInterpreterOptions): Registration;
37
39
  start(): Promise<void>;
@@ -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,EAA+B,UAAU,EAAW,YAAY,EAAE,MAAM,MAAM,CAAC;AACtF,OAAO,EAAE,eAAe,EAAuB,MAAM,kCAAkC,CAAC;AAExF,OAAO,EAAE,kBAAkB,EAAE,mBAAmB,EAAE,MAAM,yBAAyB,CAAC;AAGlF,OAAO,EAAE,QAAQ,EAAgB,MAAM,uBAAuB,CAAC;AAI/D,OAAO,EAAE,MAAM,EAAE,MAAM,uCAAuC,CAAC;AAC/D,OAAO,EAAmB,kBAAkB,EAAE,MAAM,yBAAyB,CAAC;AAC9E,OAAO,EAAE,WAAW,EAAE,uBAAuB,EAAE,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C/B,CAAA;AAED,qBAAa,iBAAiB;IAOtB,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,YAAY;IACpB,OAAO,CAAC,QAAQ,CAAC,kBAAkB;IACnC,OAAO,CAAC,QAAQ,CAAC,YAAY;IAbjC,OAAO,CAAC,mBAAmB,CAA2B;IACtD,OAAO,CAAC,MAAM,CAAC,CAAS;IACxB,OAAO,CAAC,cAAc,CAAC,CAAa;IACpC,OAAO,CAAC,cAAc,CAAS;gBAGV,GAAG,EAAE,MAAM,EACX,QAAQ,EAAE,kBAAkB,EAC5B,eAAe,EAAE,eAAe,EAChC,mBAAmB,EAAE,mBAAmB,EACxC,MAAM,EAAE,MAAM,EACvB,YAAY,EAAE,GAAG,CAAC,MAAM,EAAE,MAAM,CAAC,EACxB,kBAAkB,EAAE,kBAAkB,EACtC,YAAY,EAAE,YAAY;WASlC,WAAW,CAAC,OAAO,GAAE,wBAA6B,GAAG,OAAO,CAAC,iBAAiB,CAAC;IAwC5F,QAAQ,CAAC,CAAC,EAAE,QAAQ,EAAE,QAAQ,CAAC,CAAC,CAAC,EAAE,OAAO,CAAC,EAAE,wBAAwB;IA8C/D,KAAK,IAAI,OAAO,CAAC,IAAI,CAAC;IA2ItB,IAAI,IAAI,OAAO,CAAC,IAAI,CAAC;CAK9B"}
@@ -15,8 +15,9 @@ const MemoryKeyValueProvider_js_1 = require("../../kv/memory/MemoryKeyValueProvi
15
15
  const NatsKeyValueProvider_js_1 = require("../../kv/nats/NatsKeyValueProvider.js");
16
16
  const ConsoleLogger_js_1 = require("../../observability/logging/ConsoleLogger.js");
17
17
  const ObservableCompiler_js_1 = require("./ObservableCompiler.js");
18
+ const cronapi_js_1 = require("../../dsl/http/versori/cronapi.js");
18
19
  class MemoryInterpreter {
19
- constructor(log, compiler, contextProvider, roundTripperFactory, router, connectionProvider) {
20
+ constructor(log, compiler, contextProvider, roundTripperFactory, router, cronRegistry, connectionProvider, cronProvider) {
20
21
  Object.defineProperty(this, "log", {
21
22
  enumerable: true,
22
23
  configurable: true,
@@ -47,12 +48,24 @@ class MemoryInterpreter {
47
48
  writable: true,
48
49
  value: router
49
50
  });
51
+ Object.defineProperty(this, "cronRegistry", {
52
+ enumerable: true,
53
+ configurable: true,
54
+ writable: true,
55
+ value: cronRegistry
56
+ });
50
57
  Object.defineProperty(this, "connectionProvider", {
51
58
  enumerable: true,
52
59
  configurable: true,
53
60
  writable: true,
54
61
  value: connectionProvider
55
62
  });
63
+ Object.defineProperty(this, "cronProvider", {
64
+ enumerable: true,
65
+ configurable: true,
66
+ writable: true,
67
+ value: cronProvider
68
+ });
56
69
  Object.defineProperty(this, "registeredWorkflows", {
57
70
  enumerable: true,
58
71
  configurable: true,
@@ -88,16 +101,16 @@ class MemoryInterpreter {
88
101
  const compiler = options.compiler || new ObservableCompiler_js_1.ObservableCompiler();
89
102
  const roundTripperFactory = options.skipVersoriCredentials
90
103
  ? new default_js_1.DefaultRoundTripperFactory()
91
- : roundtripper_js_1.VersoriRoundTripperFactory.fromEnv(log);
104
+ : roundtripper_js_1.VersoriCredentialsFactory.fromEnv(log);
92
105
  if (options.contextProvider) {
93
106
  // no need to set up a key-value provider if options.contextProvider is already
94
107
  // initialised.
95
- return new MemoryInterpreter(log, compiler, options.contextProvider, roundTripperFactory, express_1.default.Router(), platformapi_js_1.PlatformAPIClient.fromEnv());
108
+ return new MemoryInterpreter(log, compiler, options.contextProvider, roundTripperFactory, express_1.default.Router(), new Map(), platformapi_js_1.PlatformAPIClient.fromEnv(), cronapi_js_1.CronAPIClient.fromEnv());
96
109
  }
97
110
  const kvp = await (options.skipVersoriCredentials
98
111
  ? new MemoryKeyValueProvider_js_1.MemoryKeyValueProvider()
99
112
  : NatsKeyValueProvider_js_1.NatsKeyValueProvider.fromEnv());
100
- return new MemoryInterpreter(log, compiler, new ContextProvider_js_1.ContextProviderImpl(log, kvp), roundTripperFactory, express_1.default.Router(), platformapi_js_1.PlatformAPIClient.fromEnv());
113
+ 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());
101
114
  }
102
115
  register(workflow, options) {
103
116
  const localAbortController = new AbortController();
@@ -114,6 +127,7 @@ class MemoryInterpreter {
114
127
  contextProvider: this.contextProvider,
115
128
  roundTripperFactory: this.roundTripperFactory,
116
129
  router: this.router,
130
+ cronRegistry: this.cronRegistry,
117
131
  connectionProvider: this.connectionProvider
118
132
  };
119
133
  const trigger$ = this.compiler.compileTrigger(compilerContext, workflow.trigger, combinedSignal);
@@ -146,9 +160,18 @@ class MemoryInterpreter {
146
160
  registration.subscription = registration.trigger$
147
161
  .pipe((0, rxjs_1.tap)((ctx) => {
148
162
  ctx.log.info('MemoryInterpreter.executionStarted', { data: ctx.data });
149
- }), (0, rxjs_1.mergeMap)((ctx) => (0, rxjs_1.of)(ctx).pipe(registration.task$, (0, rxjs_1.catchError)((error) => {
150
- ctx.log.error('MemoryInterpreter.executionError', { error });
151
- ctx.options.onError?.(ctx.withData(error));
163
+ }), (0, rxjs_1.mergeMap)((ctx) => (0, rxjs_1.of)(ctx).pipe(registration.task$, (0, rxjs_1.catchError)((err) => {
164
+ ctx.log.error('MemoryInterpreter.executionError', { error: err instanceof Error ? err.toString() : err });
165
+ try {
166
+ ctx.options.onError?.(ctx.withData(err));
167
+ }
168
+ catch (err) {
169
+ ctx.log.error('MemoryInterpreter.onErrorError: failed to call onError handler', { error: err instanceof Error ? err.toString() : err });
170
+ ctx.options.onError?.(ctx.withData({
171
+ message: 'Internal server error',
172
+ error: err instanceof Error ? err.toString() : err,
173
+ }));
174
+ }
152
175
  return rxjs_1.EMPTY;
153
176
  }))))
154
177
  .subscribe({
@@ -158,11 +181,20 @@ class MemoryInterpreter {
158
181
  durationMs,
159
182
  data: ctx.data,
160
183
  });
161
- ctx.options.onSuccess?.(ctx);
184
+ try {
185
+ ctx.options.onSuccess?.(ctx);
186
+ }
187
+ catch (err) {
188
+ ctx.log.error('MemoryInterpreter.onSuccessError: failed to call onSuccess handler', { error: err instanceof Error ? err.toString() : err });
189
+ ctx.options.onSuccess?.(ctx.withData({
190
+ message: 'Internal server error',
191
+ error: err instanceof Error ? err.toString() : err,
192
+ }));
193
+ }
162
194
  this.contextProvider.destroy(ctx);
163
195
  },
164
196
  error: (err) => {
165
- this.log.error('MemoryInterpreter.error', { error: err });
197
+ this.log.error('MemoryInterpreter.error', { error: err instanceof Error ? err.toString() : err });
166
198
  Deno.removeSignalListener('SIGINT', registration.sigintListener);
167
199
  },
168
200
  complete: () => {
@@ -174,6 +206,13 @@ class MemoryInterpreter {
174
206
  registration.subscription = undefined;
175
207
  });
176
208
  }
209
+ try {
210
+ this.cronProvider.updateCrons(this.cronRegistry);
211
+ }
212
+ catch (err) {
213
+ this.log.error('MemoryInterpreter.updateCronsError', { error: err instanceof Error ? err.toString() : err });
214
+ throw new Error('Unable to register scheduler tasks with central cron provider');
215
+ }
177
216
  this.server = app.listen(port, () => {
178
217
  this.log.info(`Express server listening on http://localhost:${port}`);
179
218
  });
@@ -14,6 +14,7 @@ export type CompilerContext = {
14
14
  roundTripperFactory: RoundTripperFactory;
15
15
  connectionProvider: ConnectionProvider;
16
16
  router: Router;
17
+ cronRegistry: Map<string, string>;
17
18
  };
18
19
  export type CompilerFunc<In = any, Out = any, T extends Task<In, Out> = Task<In, Out>> = (ctx: CompilerContext, task: T) => OperatorFunction<In, Out>;
19
20
  export declare class ObservableCompiler {
@@ -1 +1 @@
1
- {"version":3,"file":"ObservableCompiler.d.ts","sourceRoot":"","sources":["../../../../src/src/interpreter/memory/ObservableCompiler.ts"],"names":[],"m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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"}
@@ -1 +1 @@
1
- {"version":3,"file":"schedule.d.ts","sourceRoot":"","sources":["../../../../../src/src/interpreter/memory/compilers/schedule.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,YAAY,EAAE,eAAe,EAAE,MAAM,0CAA0C,CAAC;AAEzF,OAAO,EAAE,eAAe,EAAE,MAAM,YAAY,CAAC;AA6F7C,eAAO,MAAM,gBAAgB,EAAE,eAAe,CAAC,YAAY,EAAE,eAAe,CAG3E,CAAC"}
1
+ {"version":3,"file":"schedule.d.ts","sourceRoot":"","sources":["../../../../../src/src/interpreter/memory/compilers/schedule.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,YAAY,EAAE,eAAe,EAAE,MAAM,0CAA0C,CAAC;AAEzF,OAAO,EAAE,eAAe,EAAE,MAAM,YAAY,CAAC;AAuF7C,eAAO,MAAM,gBAAgB,EAAE,eAAe,CAAC,YAAY,EAAE,eAAe,CAG3E,CAAC"}
@@ -1,15 +1,18 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.scheduleCompiler = void 0;
4
- const cron_1 = require("cron");
5
4
  const rxjs_1 = require("rxjs");
6
5
  const ScheduleTrigger_js_1 = require("../../../dsl/triggers/ScheduleTrigger.js");
7
6
  function compileSchedule(ctx, trigger, signal) {
8
7
  return new rxjs_1.Observable((subscriber) => {
8
+ // Add HTTP endpoint for manual triggering
9
+ if (!ctx.router) {
10
+ throw new Error('Router not available in compiler context');
11
+ }
9
12
  const client = ctx.connectionProvider;
10
- const job = cron_1.CronJob.from({
11
- cronTime: trigger.schedule,
12
- onTick: async () => {
13
+ ctx.cronRegistry.set(trigger.id, trigger.schedule);
14
+ ctx.router.post(`/cron/${trigger.id}`, async (req, res) => {
15
+ try {
13
16
  if (trigger.activationPredicate === undefined) {
14
17
  const executionCtx = ctx.contextProvider.create({}, undefined);
15
18
  try {
@@ -18,6 +21,7 @@ function compileSchedule(ctx, trigger, signal) {
18
21
  catch (error) {
19
22
  executionCtx.log.error('execution error inside schedule', { error });
20
23
  }
24
+ res.status(200).json({ status: 'triggered', executionId: executionCtx.executionId });
21
25
  return;
22
26
  }
23
27
  const activations = await client.listActivations();
@@ -30,6 +34,7 @@ function compileSchedule(ctx, trigger, signal) {
30
34
  catch (error) {
31
35
  executionCtx.log.error('execution error inside schedule', { error });
32
36
  }
37
+ res.status(200).json({ status: 'triggered', executionId: executionCtx.executionId });
33
38
  return;
34
39
  }
35
40
  activations.forEach((activation) => {
@@ -42,31 +47,21 @@ function compileSchedule(ctx, trigger, signal) {
42
47
  executionCtx.log.error('execution error inside schedule', { error });
43
48
  }
44
49
  });
45
- },
46
- onComplete: () => {
47
- if (subscriber.closed) {
48
- return;
49
- }
50
- ctx.log.debug('schedule execution completed');
51
- subscriber.complete();
52
- },
53
- errorHandler: (error) => {
54
- ctx.log.error('schedule execution error', { error });
55
- subscriber.error(error);
56
- },
57
- start: true,
50
+ res.status(200).json({ status: 'triggered' });
51
+ }
52
+ catch (error) {
53
+ executionCtx.log.error('execution error inside schedule', { error });
54
+ res.status(500).json({ error: 'Failed to trigger schedule' });
55
+ }
58
56
  });
59
57
  function cleanup() {
60
- ctx.log.debug('schedule execution stopped');
61
- job.stop();
58
+ ctx.log.debug('scheduler trigger stopped');
59
+ subscriber.complete();
62
60
  }
63
61
  signal.addEventListener('abort', cleanup, { once: true });
64
62
  return () => {
65
63
  signal.removeEventListener('abort', cleanup);
66
- ctx.log.debug('schedule execution unsubscribed');
67
- // call job.stop() directly rather than using cleanup since cleanup is called when the
68
- // signal is aborted and we don't want duplicate logs when the unsubscription happens.
69
- job.stop();
64
+ ctx.log.debug('scheduler execution unsubscribed');
70
65
  };
71
66
  });
72
67
  }
@@ -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;AA+B/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,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,IAAI;IAO9D,IAAI,CAAC,OAAO,EAAE,MAAM,EAAE,MAAM,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,IAAI;IAO7D,KAAK,CAAC,OAAO,EAAE,MAAM,EAAE,MAAM,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,IAAI;IAO9D,KAAK,CAAC,MAAM,EAAE;QAAE,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,CAAA;KAAE,GAAG,aAAa;IAOvD,QAAQ,CAAC,KAAK,EAAE,QAAQ,GAAG,IAAI;CAGlC"}
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;AAmF/C;;GAEG;AACH,qBAAa,aAAc,YAAW,MAA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