@io-orkes/conductor-javascript 1.2.3 → 2.0.0-rc2

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.
package/dist/index.mjs CHANGED
@@ -5,16 +5,9 @@ var LOG_LEVELS = {
5
5
  ERROR: 60
6
6
  };
7
7
  var DefaultLogger = class {
8
+ tags;
9
+ level;
8
10
  constructor(config = {}) {
9
- this.info = (...args) => {
10
- this.log("INFO", ...args);
11
- };
12
- this.debug = (...args) => {
13
- this.log("DEBUG", ...args);
14
- };
15
- this.error = (...args) => {
16
- this.log("ERROR", ...args);
17
- };
18
11
  const { level, tags = [] } = config;
19
12
  this.tags = tags;
20
13
  if (level && level in LOG_LEVELS) {
@@ -36,6 +29,15 @@ var DefaultLogger = class {
36
29
  console.log(name, ...this.tags, ...args);
37
30
  }
38
31
  }
32
+ info = (...args) => {
33
+ this.log("INFO", ...args);
34
+ };
35
+ debug = (...args) => {
36
+ this.log("DEBUG", ...args);
37
+ };
38
+ error = (...args) => {
39
+ this.log("ERROR", ...args);
40
+ };
39
41
  };
40
42
  var noopLogger = {
41
43
  //eslint-disable-next-line
@@ -1486,6 +1488,11 @@ var WorkflowResourceService = class {
1486
1488
 
1487
1489
  // src/common/open-api/core/ApiError.ts
1488
1490
  var ApiError = class extends Error {
1491
+ url;
1492
+ status;
1493
+ statusText;
1494
+ body;
1495
+ request;
1489
1496
  constructor(request3, response, message) {
1490
1497
  super(message);
1491
1498
  this.name = "ApiError";
@@ -1508,9 +1515,14 @@ var CancelError = class extends Error {
1508
1515
  }
1509
1516
  };
1510
1517
  var CancelablePromise = class {
1511
- static {
1512
- Symbol.toStringTag;
1513
- }
1518
+ [Symbol.toStringTag];
1519
+ _isResolved;
1520
+ _isRejected;
1521
+ _isCancelled;
1522
+ _cancelHandlers;
1523
+ _promise;
1524
+ _resolve;
1525
+ _reject;
1514
1526
  constructor(executor) {
1515
1527
  this._isResolved = false;
1516
1528
  this._isRejected = false;
@@ -1823,83 +1835,70 @@ var HumanTaskService = class {
1823
1835
  this.httpRequest = httpRequest;
1824
1836
  }
1825
1837
  /**
1826
- * List tasks by filters - task name, state, assignee, assignee type, claimed
1827
- * @param state
1828
- * @param assignee
1829
- * @param assigneeType
1830
- * @param claimedBy
1831
- * @param taskName
1832
- * @param freeText
1833
- * @param includeInputOutput
1834
- * @returns SearchResultHumanTaskEntry OK
1838
+ * If the workflow is disconnected from tasks, this API can be used to clean up (in bulk)
1839
+ * @param requestBody
1840
+ * @returns any OK
1835
1841
  * @throws ApiError
1836
1842
  */
1837
- getTasksByFilter(state, assignee, assigneeType, claimedBy, taskName, freeText, includeInputOutput = false) {
1843
+ deleteTaskFromHumanTaskRecords(requestBody) {
1838
1844
  return this.httpRequest.request({
1839
- method: "GET",
1840
- url: "/human/tasks",
1841
- query: {
1842
- "state": state,
1843
- "assignee": assignee,
1844
- "assigneeType": assigneeType,
1845
- "claimedBy": claimedBy,
1846
- "taskName": taskName,
1847
- "freeText": freeText,
1848
- "includeInputOutput": includeInputOutput
1849
- }
1845
+ method: "DELETE",
1846
+ url: "/human/tasks/delete",
1847
+ body: requestBody,
1848
+ mediaType: "application/json"
1850
1849
  });
1851
1850
  }
1852
1851
  /**
1853
- * Get task load grouped by workflow name and task ref name per user
1854
- * @returns HumanTaskLoad OK
1852
+ * If the workflow is disconnected from tasks, this API can be used to clean up
1853
+ * @param taskId
1854
+ * @returns any OK
1855
1855
  * @throws ApiError
1856
1856
  */
1857
- getTaskLoad() {
1857
+ deleteTaskFromHumanTaskRecords1(taskId) {
1858
1858
  return this.httpRequest.request({
1859
- method: "GET",
1860
- url: "/human/tasks/load"
1859
+ method: "DELETE",
1860
+ url: "/human/tasks/delete/{taskId}",
1861
+ path: {
1862
+ "taskId": taskId
1863
+ }
1861
1864
  });
1862
1865
  }
1863
1866
  /**
1864
1867
  * Search human tasks
1865
- * @param queryId
1866
- * @param start
1867
- * @param size
1868
- * @param freeText
1869
- * @param query
1870
- * @param jsonQuery
1871
- * @param includeInputOutput
1872
- * @returns HTScrollableSearchResultHumanTaskEntry OK
1868
+ * @param requestBody
1869
+ * @returns HumanTaskSearchResult OK
1873
1870
  * @throws ApiError
1874
1871
  */
1875
- search1(queryId, start, size = 100, freeText = "*", query, jsonQuery, includeInputOutput = false) {
1872
+ search(requestBody) {
1876
1873
  return this.httpRequest.request({
1877
- method: "GET",
1874
+ method: "POST",
1878
1875
  url: "/human/tasks/search",
1879
- query: {
1880
- "queryId": queryId,
1881
- "start": start,
1882
- "size": size,
1883
- "freeText": freeText,
1884
- "query": query,
1885
- "jsonQuery": jsonQuery,
1886
- "includeInputOutput": includeInputOutput
1887
- }
1876
+ body: requestBody,
1877
+ mediaType: "application/json"
1888
1878
  });
1889
1879
  }
1890
1880
  /**
1891
- * If the workflow is disconnected from tasks, this API can be used to clean up
1892
- * @param taskId
1881
+ * Update task output, optionally complete
1882
+ * @param workflowId
1883
+ * @param taskRefName
1884
+ * @param requestBody
1885
+ * @param complete
1886
+ * @param iteration Populate this value if your task is in a loop and you want to update a specific iteration. If its not in a loop OR if you want to just update the latest iteration, leave this as empty
1893
1887
  * @returns any OK
1894
1888
  * @throws ApiError
1895
1889
  */
1896
- updateTaskOutput1(taskId) {
1890
+ updateTaskOutputByRef(workflowId, taskRefName, requestBody, complete = false, iteration) {
1897
1891
  return this.httpRequest.request({
1898
- method: "DELETE",
1899
- url: "/human/tasks/{taskId}",
1900
- path: {
1901
- "taskId": taskId
1902
- }
1892
+ method: "POST",
1893
+ url: "/human/tasks/update/taskRef",
1894
+ query: {
1895
+ "workflowId": workflowId,
1896
+ "taskRefName": taskRefName,
1897
+ "complete": complete,
1898
+ "iteration": iteration
1899
+ },
1900
+ body: requestBody,
1901
+ mediaType: "application/json"
1903
1902
  });
1904
1903
  }
1905
1904
  /**
@@ -1917,33 +1916,22 @@ var HumanTaskService = class {
1917
1916
  }
1918
1917
  });
1919
1918
  }
1920
- /**
1921
- * Get human task action log entries by task id
1922
- * @param taskId
1923
- * @returns HumanTaskActionLogEntry OK
1924
- * @throws ApiError
1925
- */
1926
- getActionLogs(taskId) {
1927
- return this.httpRequest.request({
1928
- method: "GET",
1929
- url: "/human/tasks/{taskId}/actionLogs",
1930
- path: {
1931
- "taskId": taskId
1932
- }
1933
- });
1934
- }
1935
1919
  /**
1936
1920
  * Claim a task by authenticated Conductor user
1937
1921
  * @param taskId
1922
+ * @param overrideAssignment
1938
1923
  * @returns any OK
1939
1924
  * @throws ApiError
1940
1925
  */
1941
- claimTask(taskId) {
1926
+ claimTask(taskId, overrideAssignment = false) {
1942
1927
  return this.httpRequest.request({
1943
1928
  method: "POST",
1944
1929
  url: "/human/tasks/{taskId}/claim",
1945
1930
  path: {
1946
1931
  "taskId": taskId
1932
+ },
1933
+ query: {
1934
+ "overrideAssignment": overrideAssignment
1947
1935
  }
1948
1936
  });
1949
1937
  }
@@ -1951,16 +1939,20 @@ var HumanTaskService = class {
1951
1939
  * Claim a task to an external user
1952
1940
  * @param taskId
1953
1941
  * @param userId
1942
+ * @param overrideAssignment
1954
1943
  * @returns any OK
1955
1944
  * @throws ApiError
1956
1945
  */
1957
- assignAndClaim(taskId, userId) {
1946
+ assignAndClaim(taskId, userId, overrideAssignment = false) {
1958
1947
  return this.httpRequest.request({
1959
1948
  method: "POST",
1960
1949
  url: "/human/tasks/{taskId}/externalUser/{userId}",
1961
1950
  path: {
1962
1951
  "taskId": taskId,
1963
1952
  "userId": userId
1953
+ },
1954
+ query: {
1955
+ "overrideAssignment": overrideAssignment
1964
1956
  }
1965
1957
  });
1966
1958
  }
@@ -1998,17 +1990,21 @@ var HumanTaskService = class {
1998
1990
  });
1999
1991
  }
2000
1992
  /**
2001
- * Get human task state log entries by task id
1993
+ * If a task is assigned to a user, this API can be used to skip that assignment and move to the next assignee
2002
1994
  * @param taskId
2003
- * @returns HumanTaskStateLogEntry OK
1995
+ * @param reason
1996
+ * @returns any OK
2004
1997
  * @throws ApiError
2005
1998
  */
2006
- getStateLogs(taskId) {
1999
+ skipTask(taskId, reason) {
2007
2000
  return this.httpRequest.request({
2008
- method: "GET",
2009
- url: "/human/tasks/{taskId}/stateLogs",
2001
+ method: "POST",
2002
+ url: "/human/tasks/{taskId}/skip",
2010
2003
  path: {
2011
2004
  "taskId": taskId
2005
+ },
2006
+ query: {
2007
+ "reason": reason
2012
2008
  }
2013
2009
  });
2014
2010
  }
@@ -2035,48 +2031,51 @@ var HumanTaskService = class {
2035
2031
  });
2036
2032
  }
2037
2033
  /**
2038
- * Delete human task templates by name
2034
+ * List all user form templates or get templates by name, or a template by name and version
2039
2035
  * @param name
2040
- * @returns any OK
2036
+ * @param version
2037
+ * @returns HumanTaskTemplate OK
2041
2038
  * @throws ApiError
2042
2039
  */
2043
- deleteTemplatesByName(name) {
2040
+ getAllTemplates(name, version) {
2044
2041
  return this.httpRequest.request({
2045
- method: "DELETE",
2042
+ method: "GET",
2046
2043
  url: "/human/template",
2047
2044
  query: {
2048
- "name": name
2045
+ "name": name,
2046
+ "version": version
2049
2047
  }
2050
2048
  });
2051
2049
  }
2052
2050
  /**
2053
- * List all human task templates or get templates by name, or a template by name and version
2054
- * @param name
2055
- * @param version
2056
- * @returns HumanTaskTemplateEntry OK
2051
+ * Save user form template
2052
+ * @param requestBody
2053
+ * @param newVersion
2054
+ * @returns HumanTaskTemplate OK
2057
2055
  * @throws ApiError
2058
2056
  */
2059
- getAllTemplates(name, version) {
2057
+ saveTemplate(requestBody, newVersion = false) {
2060
2058
  return this.httpRequest.request({
2061
- method: "GET",
2059
+ method: "POST",
2062
2060
  url: "/human/template",
2063
2061
  query: {
2064
- "name": name,
2065
- "version": version
2066
- }
2062
+ "newVersion": newVersion
2063
+ },
2064
+ body: requestBody,
2065
+ mediaType: "application/json"
2067
2066
  });
2068
2067
  }
2069
2068
  /**
2070
- * Save human task template
2069
+ * Save user form template
2071
2070
  * @param requestBody
2072
2071
  * @param newVersion
2073
- * @returns string OK
2072
+ * @returns HumanTaskTemplate OK
2074
2073
  * @throws ApiError
2075
2074
  */
2076
- saveTemplate(requestBody, newVersion = false) {
2075
+ saveTemplates(requestBody, newVersion = false) {
2077
2076
  return this.httpRequest.request({
2078
2077
  method: "POST",
2079
- url: "/human/template",
2078
+ url: "/human/template/bulk",
2080
2079
  query: {
2081
2080
  "newVersion": newVersion
2082
2081
  },
@@ -2085,32 +2084,51 @@ var HumanTaskService = class {
2085
2084
  });
2086
2085
  }
2087
2086
  /**
2088
- * Delete human task template
2089
- * @param id
2087
+ * Delete all versions of user form template by name
2088
+ * @param name
2089
+ * @returns any OK
2090
+ * @throws ApiError
2091
+ */
2092
+ deleteTemplateByName(name) {
2093
+ return this.httpRequest.request({
2094
+ method: "DELETE",
2095
+ url: "/human/template/{name}",
2096
+ path: {
2097
+ "name": name
2098
+ }
2099
+ });
2100
+ }
2101
+ /**
2102
+ * Delete a version of form template by name
2103
+ * @param name
2104
+ * @param version
2090
2105
  * @returns any OK
2091
2106
  * @throws ApiError
2092
2107
  */
2093
- deleteTemplateById(id) {
2108
+ deleteTemplatesByNameAndVersion(name, version) {
2094
2109
  return this.httpRequest.request({
2095
2110
  method: "DELETE",
2096
- url: "/human/template/{id}",
2111
+ url: "/human/template/{name}/{version}",
2097
2112
  path: {
2098
- "id": id
2113
+ "name": name,
2114
+ "version": version
2099
2115
  }
2100
2116
  });
2101
2117
  }
2102
2118
  /**
2103
- * Get human task template by id
2104
- * @param id
2105
- * @returns HumanTaskTemplateEntry OK
2119
+ * Get user form template by name and version
2120
+ * @param name
2121
+ * @param version
2122
+ * @returns HumanTaskTemplate OK
2106
2123
  * @throws ApiError
2107
2124
  */
2108
- getTemplateById(id) {
2125
+ getTemplateByNameAndVersion(name, version) {
2109
2126
  return this.httpRequest.request({
2110
2127
  method: "GET",
2111
- url: "/human/template/{id}",
2128
+ url: "/human/template/{name}/{version}",
2112
2129
  path: {
2113
- "id": id
2130
+ "name": name,
2131
+ "version": version
2114
2132
  }
2115
2133
  });
2116
2134
  }
@@ -2141,6 +2159,18 @@ var HumanTaskResourceService = class {
2141
2159
  // src/common/open-api/ConductorClient.ts
2142
2160
  var defaultRequestHandler = (request3, config, options) => request3(config, options);
2143
2161
  var ConductorClient = class {
2162
+ eventResource;
2163
+ healthCheckResource;
2164
+ metadataResource;
2165
+ schedulerResource;
2166
+ taskResource;
2167
+ tokenResource;
2168
+ workflowBulkResource;
2169
+ workflowResource;
2170
+ humanTask;
2171
+ humanTaskResource;
2172
+ request;
2173
+ token;
2144
2174
  constructor(config, requestHandler = defaultRequestHandler) {
2145
2175
  const resolvedConfig = {
2146
2176
  BASE: config?.serverUrl ?? "http://localhost:8080",
@@ -2194,75 +2224,21 @@ var DEFAULT_BATCH_POLLING_TIMEOUT = 100;
2194
2224
 
2195
2225
  // src/task/Poller.ts
2196
2226
  var Poller = class {
2227
+ timeoutHandler;
2228
+ pollFunction;
2229
+ performWorkFunction = async () => {
2230
+ };
2231
+ polling = false;
2232
+ _tasksInProcess = 0;
2233
+ _counterAtO = 0;
2234
+ _pollerId = "";
2235
+ options = {
2236
+ pollInterval: DEFAULT_POLL_INTERVAL,
2237
+ concurrency: DEFAULT_CONCURRENCY,
2238
+ warnAtO: DEFAULT_WARN_AT_O
2239
+ };
2240
+ logger = noopLogger;
2197
2241
  constructor(pollerId, pollFunction, performWorkFunction, pollerOptions, logger) {
2198
- this.performWorkFunction = async () => {
2199
- };
2200
- this.polling = false;
2201
- this._tasksInProcess = 0;
2202
- this._counterAtO = 0;
2203
- this._pollerId = "";
2204
- this.options = {
2205
- pollInterval: DEFAULT_POLL_INTERVAL,
2206
- concurrency: DEFAULT_CONCURRENCY,
2207
- warnAtO: DEFAULT_WARN_AT_O
2208
- };
2209
- this.logger = noopLogger;
2210
- /**
2211
- * Starts polling for work
2212
- */
2213
- this.startPolling = () => {
2214
- if (this.polling) {
2215
- throw new Error("Runner is already started");
2216
- }
2217
- this._tasksInProcess = 0;
2218
- this.polling = true;
2219
- this.poll();
2220
- };
2221
- /**
2222
- * Stops Polling for work
2223
- */
2224
- this.stopPolling = async () => {
2225
- this.polling = false;
2226
- clearTimeout(this.timeoutHandler);
2227
- };
2228
- this.performWork = async (work) => {
2229
- await this.performWorkFunction(work);
2230
- this._tasksInProcess--;
2231
- };
2232
- this.poll = async () => {
2233
- while (this.isPolling) {
2234
- try {
2235
- const count = Math.max(
2236
- 0,
2237
- this.options.concurrency - this._tasksInProcess
2238
- );
2239
- if (count === 0) {
2240
- this.logger.debug(
2241
- "Max in process reached, Will skip polling for " + this._pollerId
2242
- );
2243
- this._counterAtO++;
2244
- if (this._counterAtO > (this.options.warnAtO ?? 100)) {
2245
- this.logger.info(
2246
- `Not polling anything because in process tasks is maxed as concurrency level. ${this._pollerId}`
2247
- );
2248
- }
2249
- } else {
2250
- this._counterAtO = 0;
2251
- const tasksResult = await this.pollFunction(count);
2252
- this._tasksInProcess = this._tasksInProcess + (tasksResult ?? []).length;
2253
- tasksResult.forEach(this.performWork);
2254
- }
2255
- } catch (e) {
2256
- this.logger.error(`Error polling for tasks: ${e.message}`, e);
2257
- }
2258
- await new Promise(
2259
- (r) => this.isPolling ? this.timeoutHandler = setTimeout(
2260
- () => r(true),
2261
- this.options.pollInterval
2262
- ) : r(true)
2263
- );
2264
- }
2265
- };
2266
2242
  this._pollerId = pollerId;
2267
2243
  this.pollFunction = pollFunction;
2268
2244
  this.performWorkFunction = performWorkFunction;
@@ -2275,10 +2251,66 @@ var Poller = class {
2275
2251
  get tasksInProcess() {
2276
2252
  return this._tasksInProcess;
2277
2253
  }
2254
+ /**
2255
+ * Starts polling for work
2256
+ */
2257
+ startPolling = () => {
2258
+ if (this.polling) {
2259
+ throw new Error("Runner is already started");
2260
+ }
2261
+ this._tasksInProcess = 0;
2262
+ this.polling = true;
2263
+ this.poll();
2264
+ };
2265
+ /**
2266
+ * Stops Polling for work
2267
+ */
2268
+ stopPolling = async () => {
2269
+ this.polling = false;
2270
+ clearTimeout(this.timeoutHandler);
2271
+ };
2272
+ performWork = async (work) => {
2273
+ await this.performWorkFunction(work);
2274
+ this._tasksInProcess--;
2275
+ };
2278
2276
  updateOptions(options) {
2279
2277
  const newOptions = { ...this.options, ...options };
2280
2278
  this.options = newOptions;
2281
2279
  }
2280
+ poll = async () => {
2281
+ while (this.isPolling) {
2282
+ try {
2283
+ const count = Math.max(
2284
+ 0,
2285
+ this.options.concurrency - this._tasksInProcess
2286
+ );
2287
+ if (count === 0) {
2288
+ this.logger.debug(
2289
+ "Max in process reached, Will skip polling for " + this._pollerId
2290
+ );
2291
+ this._counterAtO++;
2292
+ if (this._counterAtO > (this.options.warnAtO ?? 100)) {
2293
+ this.logger.info(
2294
+ `Not polling anything because in process tasks is maxed as concurrency level. ${this._pollerId}`
2295
+ );
2296
+ }
2297
+ } else {
2298
+ this._counterAtO = 0;
2299
+ const tasksResult = await this.pollFunction(count);
2300
+ this._tasksInProcess = this._tasksInProcess + (tasksResult ?? []).length;
2301
+ tasksResult.forEach(this.performWork);
2302
+ }
2303
+ } catch (e) {
2304
+ this.logger.error(`Error polling for tasks: ${e.message}`, e);
2305
+ }
2306
+ await new Promise(
2307
+ (r) => this.isPolling ? this.timeoutHandler = setTimeout(
2308
+ () => r(true),
2309
+ this.options.pollInterval
2310
+ ) : r(true)
2311
+ );
2312
+ }
2313
+ };
2282
2314
  };
2283
2315
 
2284
2316
  // src/task/helpers.ts
@@ -2303,6 +2335,12 @@ var defaultRunnerOptions = {
2303
2335
  batchPollingTimeout: DEFAULT_BATCH_POLLING_TIMEOUT
2304
2336
  };
2305
2337
  var TaskRunner = class {
2338
+ taskResource;
2339
+ worker;
2340
+ logger;
2341
+ options;
2342
+ errorHandler;
2343
+ poller;
2306
2344
  constructor({
2307
2345
  worker,
2308
2346
  taskResource,
@@ -2310,91 +2348,6 @@ var TaskRunner = class {
2310
2348
  logger = noopLogger,
2311
2349
  onError: errorHandler = noopErrorHandler
2312
2350
  }) {
2313
- /**
2314
- * Starts polling for work
2315
- */
2316
- this.startPolling = () => {
2317
- this.poller.startPolling();
2318
- this.logger.info(
2319
- `TaskWorker ${this.worker.taskDefName} initialized with concurrency of ${this.poller.options.concurrency} and poll interval of ${this.poller.options.pollInterval}`
2320
- );
2321
- };
2322
- /**
2323
- * Stops Polling for work
2324
- */
2325
- this.stopPolling = async () => {
2326
- await this.poller.stopPolling();
2327
- };
2328
- this.batchPoll = async (count) => {
2329
- const { workerID } = this.options;
2330
- const tasks = await this.taskResource.batchPoll(
2331
- this.worker.taskDefName,
2332
- workerID,
2333
- this.worker.domain ?? this.options.domain,
2334
- count,
2335
- this.options.batchPollingTimeout ?? 100
2336
- // default batch poll defined in the method
2337
- );
2338
- return tasks;
2339
- };
2340
- this.updateTaskWithRetry = async (task, taskResult) => {
2341
- const { workerID } = this.options;
2342
- let retryCount = 0;
2343
- while (retryCount < MAX_RETRIES) {
2344
- try {
2345
- await this.taskResource.updateTask1({
2346
- ...taskResult,
2347
- workerId: workerID
2348
- });
2349
- return;
2350
- } catch (error) {
2351
- this.errorHandler(error, task);
2352
- this.logger.error(
2353
- `Error updating task ${taskResult.taskId} on retry ${retryCount}`,
2354
- error
2355
- );
2356
- retryCount++;
2357
- await new Promise((r) => setTimeout(() => r(true), retryCount * 10));
2358
- }
2359
- }
2360
- this.logger.error(
2361
- `Unable to update task ${taskResult.taskId} after ${retryCount} retries`
2362
- );
2363
- };
2364
- this.executeTask = async (task) => {
2365
- try {
2366
- const result = await this.worker.execute(task);
2367
- await this.updateTaskWithRetry(task, {
2368
- ...result,
2369
- workflowInstanceId: task.workflowInstanceId,
2370
- taskId: task.taskId
2371
- });
2372
- this.logger.debug(`Task has executed successfully ${task.taskId}`);
2373
- } catch (error) {
2374
- await this.updateTaskWithRetry(task, {
2375
- workflowInstanceId: task.workflowInstanceId,
2376
- taskId: task.taskId,
2377
- reasonForIncompletion: error?.message ?? DEFAULT_ERROR_MESSAGE,
2378
- status: "FAILED",
2379
- outputData: {}
2380
- });
2381
- this.errorHandler(error, task);
2382
- this.logger.error(`Error executing ${task.taskId}`, error);
2383
- }
2384
- };
2385
- this.handleUnknownError = (unknownError) => {
2386
- let message = "";
2387
- let stack = "";
2388
- if (unknownError.stack) {
2389
- stack = unknownError.stack;
2390
- }
2391
- if (unknownError.message) {
2392
- message = unknownError.message;
2393
- }
2394
- this.logger.error(
2395
- `Error for ${this.worker.taskDefName}: error: ${message}, stack: ${stack}`
2396
- );
2397
- };
2398
2351
  this.taskResource = taskResource;
2399
2352
  this.logger = logger;
2400
2353
  this.worker = worker;
@@ -2414,6 +2367,21 @@ var TaskRunner = class {
2414
2367
  get isPolling() {
2415
2368
  return this.poller.isPolling;
2416
2369
  }
2370
+ /**
2371
+ * Starts polling for work
2372
+ */
2373
+ startPolling = () => {
2374
+ this.poller.startPolling();
2375
+ this.logger.info(
2376
+ `TaskWorker ${this.worker.taskDefName} initialized with concurrency of ${this.poller.options.concurrency} and poll interval of ${this.poller.options.pollInterval}`
2377
+ );
2378
+ };
2379
+ /**
2380
+ * Stops Polling for work
2381
+ */
2382
+ stopPolling = async () => {
2383
+ await this.poller.stopPolling();
2384
+ };
2417
2385
  updateOptions(options) {
2418
2386
  const newOptions = { ...this.options, ...options };
2419
2387
  const isOptionsUpdated = !optionEquals(this.options, newOptions);
@@ -2431,6 +2399,76 @@ var TaskRunner = class {
2431
2399
  get getOptions() {
2432
2400
  return this.options;
2433
2401
  }
2402
+ batchPoll = async (count) => {
2403
+ const { workerID } = this.options;
2404
+ const tasks = await this.taskResource.batchPoll(
2405
+ this.worker.taskDefName,
2406
+ workerID,
2407
+ this.worker.domain ?? this.options.domain,
2408
+ count,
2409
+ this.options.batchPollingTimeout ?? 100
2410
+ // default batch poll defined in the method
2411
+ );
2412
+ return tasks;
2413
+ };
2414
+ updateTaskWithRetry = async (task, taskResult) => {
2415
+ const { workerID } = this.options;
2416
+ let retryCount = 0;
2417
+ while (retryCount < MAX_RETRIES) {
2418
+ try {
2419
+ await this.taskResource.updateTask1({
2420
+ ...taskResult,
2421
+ workerId: workerID
2422
+ });
2423
+ return;
2424
+ } catch (error) {
2425
+ this.errorHandler(error, task);
2426
+ this.logger.error(
2427
+ `Error updating task ${taskResult.taskId} on retry ${retryCount}`,
2428
+ error
2429
+ );
2430
+ retryCount++;
2431
+ await new Promise((r) => setTimeout(() => r(true), retryCount * 10));
2432
+ }
2433
+ }
2434
+ this.logger.error(
2435
+ `Unable to update task ${taskResult.taskId} after ${retryCount} retries`
2436
+ );
2437
+ };
2438
+ executeTask = async (task) => {
2439
+ try {
2440
+ const result = await this.worker.execute(task);
2441
+ await this.updateTaskWithRetry(task, {
2442
+ ...result,
2443
+ workflowInstanceId: task.workflowInstanceId,
2444
+ taskId: task.taskId
2445
+ });
2446
+ this.logger.debug(`Task has executed successfully ${task.taskId}`);
2447
+ } catch (error) {
2448
+ await this.updateTaskWithRetry(task, {
2449
+ workflowInstanceId: task.workflowInstanceId,
2450
+ taskId: task.taskId,
2451
+ reasonForIncompletion: error?.message ?? DEFAULT_ERROR_MESSAGE,
2452
+ status: "FAILED",
2453
+ outputData: {}
2454
+ });
2455
+ this.errorHandler(error, task);
2456
+ this.logger.error(`Error executing ${task.taskId}`, error);
2457
+ }
2458
+ };
2459
+ handleUnknownError = (unknownError) => {
2460
+ let message = "";
2461
+ let stack = "";
2462
+ if (unknownError.stack) {
2463
+ stack = unknownError.stack;
2464
+ }
2465
+ if (unknownError.message) {
2466
+ message = unknownError.message;
2467
+ }
2468
+ this.logger.error(
2469
+ `Error for ${this.worker.taskDefName}: error: ${message}, stack: ${stack}`
2470
+ );
2471
+ };
2434
2472
  };
2435
2473
 
2436
2474
  // src/task/TaskManager.ts
@@ -2446,84 +2484,14 @@ function workerId(options) {
2446
2484
  return options.workerID ?? os.hostname();
2447
2485
  }
2448
2486
  var TaskManager = class {
2487
+ workerRunners = /* @__PURE__ */ new Map();
2488
+ client;
2489
+ logger;
2490
+ errorHandler;
2491
+ workers;
2492
+ options;
2493
+ polling = false;
2449
2494
  constructor(client, workers, config = {}) {
2450
- this.workerRunners = /* @__PURE__ */ new Map();
2451
- this.polling = false;
2452
- this.workerManagerWorkerOptions = (worker) => {
2453
- return {
2454
- ...this.options,
2455
- concurrency: worker.concurrency ?? this.options.concurrency,
2456
- pollInterval: worker.pollInterval ?? this.options.pollInterval,
2457
- domain: worker.domain ?? this.options.domain
2458
- };
2459
- };
2460
- this.updatePollingOptionForWorker = (workerTaskDefName, options) => {
2461
- const maybeRunner = this.workerRunners.get(workerTaskDefName);
2462
- if (maybeRunner != null) {
2463
- maybeRunner.updateOptions(options);
2464
- } else {
2465
- this.logger.info(
2466
- `No runner found for worker with taskDefName: ${workerTaskDefName}`
2467
- );
2468
- }
2469
- };
2470
- /**
2471
- * new options will get merged to existing options
2472
- * @param options new options to update polling options
2473
- */
2474
- this.updatePollingOptions = (options) => {
2475
- this.workers.forEach((worker) => {
2476
- const newOptions = {
2477
- ...this.workerManagerWorkerOptions(worker),
2478
- ...options
2479
- };
2480
- this.updatePollingOptionForWorker(worker.taskDefName, newOptions);
2481
- });
2482
- this.options.concurrency = options.concurrency ?? this.options.concurrency;
2483
- this.options.pollInterval = options.pollInterval ?? this.options.pollInterval;
2484
- };
2485
- this.sanityCheck = () => {
2486
- if (this.workers.length === 0) {
2487
- throw new Error("No workers supplied to TaskManager");
2488
- }
2489
- const workerIDs = /* @__PURE__ */ new Set();
2490
- for (const item of this.workers) {
2491
- if (workerIDs.has(item.taskDefName)) {
2492
- throw new Error(`Duplicate worker taskDefName: ${item.taskDefName}`);
2493
- }
2494
- workerIDs.add(item.taskDefName);
2495
- }
2496
- };
2497
- /**
2498
- * Start polling for tasks
2499
- */
2500
- this.startPolling = () => {
2501
- this.sanityCheck();
2502
- this.workers.forEach((worker) => {
2503
- const options = this.workerManagerWorkerOptions(worker);
2504
- const runner = new TaskRunner({
2505
- worker,
2506
- options,
2507
- taskResource: this.client.taskResource,
2508
- logger: this.logger,
2509
- onError: this.errorHandler
2510
- });
2511
- runner.startPolling();
2512
- this.workerRunners.set(worker.taskDefName, runner);
2513
- });
2514
- this.polling = true;
2515
- };
2516
- /**
2517
- * Stops polling for tasks
2518
- */
2519
- this.stopPolling = async () => {
2520
- for (const [workerTaskDefName, runner] of this.workerRunners) {
2521
- this.logger.debug(`Stopping taskDefName=${workerTaskDefName}`);
2522
- await runner.stopPolling();
2523
- this.workerRunners.delete(workerTaskDefName);
2524
- }
2525
- this.polling = false;
2526
- };
2527
2495
  if (!workers) {
2528
2496
  throw new Error(
2529
2497
  "No workers supplied to TaskManager. Please pass an array of workers."
@@ -2540,21 +2508,98 @@ var TaskManager = class {
2540
2508
  workerID: workerId(providedOptions)
2541
2509
  };
2542
2510
  }
2511
+ workerManagerWorkerOptions = (worker) => {
2512
+ return {
2513
+ ...this.options,
2514
+ concurrency: worker.concurrency ?? this.options.concurrency,
2515
+ pollInterval: worker.pollInterval ?? this.options.pollInterval,
2516
+ domain: worker.domain ?? this.options.domain
2517
+ };
2518
+ };
2543
2519
  get isPolling() {
2544
2520
  return this.polling;
2545
2521
  }
2546
- };
2547
-
2548
- // src/core/types.ts
2549
- var ConductorError = class extends Error {
2550
- constructor(message, innerError) {
2551
- super(message);
2552
- this._trace = innerError;
2553
- const actualProto = new.target.prototype;
2554
- if (Object.setPrototypeOf) {
2555
- Object.setPrototypeOf(this, actualProto);
2522
+ updatePollingOptionForWorker = (workerTaskDefName, options) => {
2523
+ const maybeRunner = this.workerRunners.get(workerTaskDefName);
2524
+ if (maybeRunner != null) {
2525
+ maybeRunner.updateOptions(options);
2556
2526
  } else {
2557
- this.__proto__ = actualProto;
2527
+ this.logger.info(
2528
+ `No runner found for worker with taskDefName: ${workerTaskDefName}`
2529
+ );
2530
+ }
2531
+ };
2532
+ /**
2533
+ * new options will get merged to existing options
2534
+ * @param options new options to update polling options
2535
+ */
2536
+ updatePollingOptions = (options) => {
2537
+ this.workers.forEach((worker) => {
2538
+ const newOptions = {
2539
+ ...this.workerManagerWorkerOptions(worker),
2540
+ ...options
2541
+ };
2542
+ this.updatePollingOptionForWorker(worker.taskDefName, newOptions);
2543
+ });
2544
+ this.options.concurrency = options.concurrency ?? this.options.concurrency;
2545
+ this.options.pollInterval = options.pollInterval ?? this.options.pollInterval;
2546
+ };
2547
+ sanityCheck = () => {
2548
+ if (this.workers.length === 0) {
2549
+ throw new Error("No workers supplied to TaskManager");
2550
+ }
2551
+ const workerIDs = /* @__PURE__ */ new Set();
2552
+ for (const item of this.workers) {
2553
+ if (workerIDs.has(item.taskDefName)) {
2554
+ throw new Error(`Duplicate worker taskDefName: ${item.taskDefName}`);
2555
+ }
2556
+ workerIDs.add(item.taskDefName);
2557
+ }
2558
+ };
2559
+ /**
2560
+ * Start polling for tasks
2561
+ */
2562
+ startPolling = () => {
2563
+ this.sanityCheck();
2564
+ this.workers.forEach((worker) => {
2565
+ const options = this.workerManagerWorkerOptions(worker);
2566
+ const runner = new TaskRunner({
2567
+ worker,
2568
+ options,
2569
+ taskResource: this.client.taskResource,
2570
+ logger: this.logger,
2571
+ onError: this.errorHandler
2572
+ });
2573
+ runner.startPolling();
2574
+ this.workerRunners.set(worker.taskDefName, runner);
2575
+ });
2576
+ this.polling = true;
2577
+ };
2578
+ /**
2579
+ * Stops polling for tasks
2580
+ */
2581
+ stopPolling = async () => {
2582
+ for (const [workerTaskDefName, runner] of this.workerRunners) {
2583
+ this.logger.debug(`Stopping taskDefName=${workerTaskDefName}`);
2584
+ await runner.stopPolling();
2585
+ this.workerRunners.delete(workerTaskDefName);
2586
+ }
2587
+ this.polling = false;
2588
+ };
2589
+ };
2590
+
2591
+ // src/core/types.ts
2592
+ var ConductorError = class extends Error {
2593
+ _trace;
2594
+ __proto__;
2595
+ constructor(message, innerError) {
2596
+ super(message);
2597
+ this._trace = innerError;
2598
+ const actualProto = new.target.prototype;
2599
+ if (Object.setPrototypeOf) {
2600
+ Object.setPrototypeOf(this, actualProto);
2601
+ } else {
2602
+ this.__proto__ = actualProto;
2558
2603
  }
2559
2604
  }
2560
2605
  };
@@ -2568,10 +2613,20 @@ var tryCatchReThrow = (fn) => {
2568
2613
  throw errorMapper(error);
2569
2614
  }
2570
2615
  };
2616
+ function reverseFind(array, predicate) {
2617
+ for (let i = array.length - 1; i >= 0; i--) {
2618
+ if (predicate(array[i], i, array)) {
2619
+ return array[i];
2620
+ }
2621
+ }
2622
+ return void 0;
2623
+ }
2571
2624
 
2572
2625
  // src/core/executor.ts
2573
2626
  var RETRY_TIME_IN_MILLISECONDS = 1e4;
2627
+ var completedTaskMatchingType = (taskType) => (task) => task.status === "COMPLETED" && task.taskType === taskType;
2574
2628
  var WorkflowExecutor = class {
2629
+ _client;
2575
2630
  constructor(client) {
2576
2631
  this._client = client;
2577
2632
  }
@@ -2615,6 +2670,26 @@ var WorkflowExecutor = class {
2615
2670
  startWorkflows(workflowsRequest) {
2616
2671
  return tryCatchReThrow(() => workflowsRequest.map(this.startWorkflow));
2617
2672
  }
2673
+ async goBackToTask(workflowInstanceId, taskFinderPredicate, rerunWorkflowRequestOverrides = {}) {
2674
+ const { tasks: executedTasks = [] } = await this.getExecution(
2675
+ workflowInstanceId
2676
+ );
2677
+ const maybePreviousTask = reverseFind(
2678
+ executedTasks,
2679
+ taskFinderPredicate
2680
+ );
2681
+ if (!maybePreviousTask) {
2682
+ throw new Error("Task not found");
2683
+ }
2684
+ await this.reRun(workflowInstanceId, {
2685
+ //taskInput: previousTask.inputData,
2686
+ ...rerunWorkflowRequestOverrides,
2687
+ reRunFromTaskId: maybePreviousTask.taskId
2688
+ });
2689
+ }
2690
+ async goBackToFirstTaskMatchingType(workflowInstanceId, taskType) {
2691
+ return this.goBackToTask(workflowInstanceId, completedTaskMatchingType(taskType));
2692
+ }
2618
2693
  /**
2619
2694
  * Takes an workflowInstanceId and an includeTasks and an optional retry parameter returns the whole execution status.
2620
2695
  * If includeTasks flag is provided. Details of tasks execution will be returned as well,
@@ -2659,6 +2734,22 @@ var WorkflowExecutor = class {
2659
2734
  )
2660
2735
  );
2661
2736
  }
2737
+ /**
2738
+ * Returns a summary of the current workflow status.
2739
+ *
2740
+ * @param workflowInstanceId current running workflow
2741
+ * @param includeOutput flag to include output
2742
+ * @param includeVariables flag to include variable
2743
+ * @returns Promise<WorkflowStatus>
2744
+ */
2745
+ getExecution(workflowInstanceId, includeTasks = true) {
2746
+ return tryCatchReThrow(
2747
+ () => this._client.workflowResource.getExecutionStatus(
2748
+ workflowInstanceId,
2749
+ includeTasks
2750
+ )
2751
+ );
2752
+ }
2662
2753
  /**
2663
2754
  * Pauses a running workflow
2664
2755
  * @param workflowInstanceId current workflow execution
@@ -2828,11 +2919,25 @@ var WorkflowExecutor = class {
2828
2919
  };
2829
2920
 
2830
2921
  // src/core/human.ts
2922
+ var EMPTY_SEARCH = {
2923
+ size: 15,
2924
+ states: [],
2925
+ taskInputQuery: "",
2926
+ taskOutputQuery: "",
2927
+ definitionNames: [],
2928
+ taskRefNames: [],
2929
+ claimants: [],
2930
+ assignees: [],
2931
+ start: 0
2932
+ };
2933
+ var DEFAULT_POLL_INTERVAL2 = { pollInterval: 100, maxPollTimes: 20 };
2831
2934
  var HumanExecutor = class {
2935
+ _client;
2832
2936
  constructor(client) {
2833
2937
  this._client = client;
2834
2938
  }
2835
2939
  /**
2940
+ * @deprecated use search instead
2836
2941
  * Takes a set of filter parameters. return matches of human tasks for that set of parameters
2837
2942
  * @param state
2838
2943
  * @param assignee
@@ -2843,21 +2948,68 @@ var HumanExecutor = class {
2843
2948
  * @param includeInputOutput
2844
2949
  * @returns
2845
2950
  */
2846
- async getTasksByFilter(state, assignee, assigneeType, claimedBy, taskName, freeText, includeInputOutput = false) {
2847
- const response = await this._client.humanTask.getTasksByFilter(
2848
- state,
2849
- assignee,
2850
- assigneeType,
2851
- claimedBy,
2852
- taskName,
2853
- freeText,
2854
- includeInputOutput
2951
+ async getTasksByFilter(state, assignee, assigneeType, claimedBy, taskName, taskInputQuery, taskOutputQuery) {
2952
+ const [claimedUserType, claimedUser] = claimedBy?.split(":") ?? [];
2953
+ if (claimedUserType && !claimedUser) {
2954
+ throw new Error("claimedBy should be in the format of <userType>:<user>");
2955
+ }
2956
+ const response = await this.search({
2957
+ states: [state],
2958
+ assignees: assignee ? [{ userType: assigneeType, user: assignee }] : [],
2959
+ claimants: claimedBy ? [{ userType: claimedUserType, user: claimedUser }] : [],
2960
+ taskRefNames: taskName ? [taskName] : [],
2961
+ taskInputQuery,
2962
+ taskOutputQuery
2963
+ });
2964
+ return response;
2965
+ }
2966
+ /**
2967
+ * Takes a set of filter parameters. return matches of human tasks for that set of parameters
2968
+ * @param state
2969
+ * @param assignee
2970
+ * @param assigneeType
2971
+ * @param claimedBy
2972
+ * @param taskName
2973
+ * @param freeText
2974
+ * @param includeInputOutput
2975
+ * @returns Promise<HumanTaskEntry[]>
2976
+ */
2977
+ async search(searchParams) {
2978
+ const search = { ...EMPTY_SEARCH, ...searchParams };
2979
+ const response = await tryCatchReThrow(
2980
+ () => this._client.humanTask.search(search)
2855
2981
  );
2856
2982
  if (response.results != void 0) {
2857
2983
  return response.results;
2858
2984
  }
2859
2985
  return [];
2860
2986
  }
2987
+ /**
2988
+ * Takes a set of filter parameters. An polling interval options. will poll until the task returns a result
2989
+ * @param state
2990
+ * @param assignee
2991
+ * @param assigneeType
2992
+ * @param claimedBy
2993
+ * @param taskName
2994
+ * @param freeText
2995
+ * @param includeInputOutput
2996
+ * @returns Promise<HumanTaskEntry[]>
2997
+ */
2998
+ async pollSearch(searchParams, {
2999
+ pollInterval = 100,
3000
+ maxPollTimes = 20
3001
+ } = DEFAULT_POLL_INTERVAL2) {
3002
+ let pollCount = 0;
3003
+ while (pollCount < maxPollTimes) {
3004
+ const response = await this.search(searchParams);
3005
+ if (response.length > 0) {
3006
+ return response;
3007
+ }
3008
+ await new Promise((resolve3) => setTimeout(resolve3, pollInterval));
3009
+ pollCount++;
3010
+ }
3011
+ return [];
3012
+ }
2861
3013
  /**
2862
3014
  * Returns task for a given task id
2863
3015
  * @param taskId
@@ -2873,11 +3025,9 @@ var HumanExecutor = class {
2873
3025
  * @returns
2874
3026
  */
2875
3027
  async claimTaskAsExternalUser(taskId, assignee) {
2876
- try {
2877
- await this._client.humanTask.assignAndClaim(taskId, assignee);
2878
- } catch (error) {
2879
- throw errorMapper(error);
2880
- }
3028
+ return tryCatchReThrow(
3029
+ () => this._client.humanTask.assignAndClaim(taskId, assignee)
3030
+ );
2881
3031
  }
2882
3032
  /**
2883
3033
  * Claim task as conductor user
@@ -2885,11 +3035,7 @@ var HumanExecutor = class {
2885
3035
  * @returns
2886
3036
  */
2887
3037
  async claimTaskAsConductorUser(taskId) {
2888
- try {
2889
- await this._client.humanTask.claimTask(taskId);
2890
- } catch (error) {
2891
- throw errorMapper(error);
2892
- }
3038
+ return tryCatchReThrow(() => this._client.humanTask.claimTask(taskId));
2893
3039
  }
2894
3040
  /**
2895
3041
  * Claim task as conductor user
@@ -2905,15 +3051,24 @@ var HumanExecutor = class {
2905
3051
  }
2906
3052
  }
2907
3053
  /**
2908
- * Returns a HumanTaskTemplateEntry for a given templateId
3054
+ * Returns a HumanTaskTemplateEntry for a given name and version
2909
3055
  * @param templateId
2910
3056
  * @returns
2911
3057
  */
2912
- async getTemplateById(templateId) {
3058
+ async getTemplateByNameVersion(name, version) {
2913
3059
  return tryCatchReThrow(
2914
- () => this._client.humanTask.getTemplateById(templateId)
3060
+ () => this._client.humanTask.getTemplateByNameAndVersion(name, version)
2915
3061
  );
2916
3062
  }
3063
+ /**
3064
+ * @deprecated use getTemplate instead. name will be used as id here with version 1
3065
+ * Returns a HumanTaskTemplateEntry for a given templateId
3066
+ * @param templateId
3067
+ * @returns
3068
+ */
3069
+ async getTemplateById(templateNameVersionOne) {
3070
+ return this.getTemplateByNameVersion(templateNameVersionOne, 1);
3071
+ }
2917
3072
  /**
2918
3073
  * Takes a taskId and a partial body. will update with given body
2919
3074
  * @param taskId
@@ -3422,105 +3577,73 @@ var workflow = (name, tasks) => ({
3422
3577
  timeoutSeconds: 0
3423
3578
  });
3424
3579
 
3425
- // src/orkes/request/fetchCatchDns/DnsResolver.ts
3426
- import { promises } from "dns";
3427
- var DEFAULT_OPTIONS = {
3428
- logger: noopLogger,
3429
- resolver: promises.resolve4
3430
- };
3431
- var dnsResolver = async (host, { resolver = promises.resolve4, logger = console } = DEFAULT_OPTIONS) => {
3432
- try {
3433
- const addresses = await resolver(host);
3434
- if (addresses.length > 0)
3435
- return addresses[0];
3436
- } catch (e) {
3437
- logger.error("Could not resolve host: " + host + " error: " + e);
3438
- }
3439
- return void 0;
3440
- };
3441
-
3442
- // src/orkes/request/fetchCatchDns/DnsCache.ts
3443
- var DnsCacheResolver = class {
3444
- constructor({ initialCache = /* @__PURE__ */ new Map() } = {}) {
3445
- this._cache = /* @__PURE__ */ new Map();
3446
- this._cache = initialCache;
3580
+ // src/orkes/BaseOrkesConductorClient.ts
3581
+ var defaultRequestHandler2 = (request3, config, options) => request3(config, options);
3582
+ var REFRESH_TOKEN_IN_MILLISECONDS = 30 * 60 * 1e3;
3583
+ var AuthConductorClient = class extends ConductorClient {
3584
+ intervalId;
3585
+ constructor(config, requestHandler = defaultRequestHandler2) {
3586
+ super(config, requestHandler);
3447
3587
  }
3448
- async resolve(host) {
3449
- const cachedIp = this._cache.get(host);
3450
- if (cachedIp) {
3451
- return cachedIp;
3452
- }
3453
- const ip = await dnsResolver(host);
3454
- if (ip != void 0) {
3455
- this._cache.set(host, ip);
3588
+ /**
3589
+ * Stops the interval that refreshes the token
3590
+ */
3591
+ stop() {
3592
+ if (this.intervalId != null) {
3593
+ clearInterval(this.intervalId);
3456
3594
  }
3457
- return ip;
3458
- }
3459
- clearCache() {
3460
- this._cache.clear();
3461
- }
3462
- removeCache(host) {
3463
- this._cache.delete(host);
3464
- }
3465
- get cache() {
3466
- return this._cache;
3467
3595
  }
3468
3596
  };
3469
-
3470
- // src/orkes/request/fetchCatchDns/fetchCatchDns.ts
3471
- import { isIP } from "net";
3472
- var isEmpty = (value) => {
3473
- return value === void 0 || value.trim().length === 0;
3474
- };
3475
- var toMaybeUrl = (originalUrl, modifiedParams) => {
3476
- const urlToHit = new URL(originalUrl.toString());
3477
- urlToHit.host = isEmpty(modifiedParams.port) ? `${modifiedParams.host}:${modifiedParams.port}` : modifiedParams.host;
3478
- return urlToHit;
3479
- };
3480
- var DEFAULT_OPTIONS2 = {
3481
- dnsCache: new DnsCacheResolver(),
3482
- headerFactory: (headers) => new Headers(headers || {})
3483
- };
3484
- var fetchCatchDns = (fetch3, {
3485
- dnsCache = new DnsCacheResolver(),
3486
- headerFactory = (headers) => new Headers(headers || {})
3487
- } = DEFAULT_OPTIONS2) => {
3488
- const fetchWithDns = async (input, options) => {
3489
- const parsedUrl = new URL(input.toString());
3490
- const { hostname, host, port } = parsedUrl;
3491
- if (isIP(hostname)) {
3492
- return await fetch3(input, options);
3493
- }
3494
- const maybeTargetIp = await dnsCache.resolve(hostname);
3495
- if (isEmpty(maybeTargetIp)) {
3496
- return await fetch3(input, options);
3497
- }
3498
- const target = toMaybeUrl(input, {
3499
- ...parsedUrl,
3500
- host: maybeTargetIp,
3501
- port
3502
- });
3503
- const headersOverride = headerFactory(options?.headers ?? {});
3504
- if (!headersOverride.has("Host")) {
3505
- headersOverride.set("Host", host);
3506
- }
3507
- const optionsOverride = {
3508
- ...options,
3509
- headers: headersOverride
3510
- };
3511
- try {
3512
- const res = await fetch3(target.toString(), optionsOverride);
3513
- return res;
3514
- } catch (e) {
3515
- if (e && e?.code === "ETIMEDOUT") {
3516
- dnsCache.removeCache(hostname);
3597
+ var baseOrkesConductorClient = (fetchFn, baseRequestHandler = defaultRequestHandler2) => {
3598
+ const requestTokenForKeySecret = (keyId, keySecret, tokenUrl) => fetchFn(tokenUrl, {
3599
+ headers: {
3600
+ "Content-Type": "application/json",
3601
+ Accept: "application/json"
3602
+ },
3603
+ body: JSON.stringify({ keyId, keySecret }),
3604
+ method: "POST"
3605
+ });
3606
+ return async (config, requestHandler = baseRequestHandler) => {
3607
+ if (config?.keySecret != null && config?.keyId != null) {
3608
+ const {
3609
+ serverUrl,
3610
+ keyId,
3611
+ keySecret,
3612
+ refreshTokenInterval = REFRESH_TOKEN_IN_MILLISECONDS
3613
+ } = config;
3614
+ const tokenUrl = `${serverUrl}/token`;
3615
+ const res = await requestTokenForKeySecret(keyId, keySecret, tokenUrl);
3616
+ const { token } = await res.json();
3617
+ const conductorClientInstance = new AuthConductorClient(
3618
+ { ...config, TOKEN: token },
3619
+ requestHandler
3620
+ );
3621
+ if (token != null && refreshTokenInterval > 0) {
3622
+ const intervalId = setInterval(async () => {
3623
+ const res2 = await requestTokenForKeySecret(
3624
+ keyId,
3625
+ keySecret,
3626
+ tokenUrl
3627
+ );
3628
+ const { token: token2 } = await res2.json();
3629
+ conductorClientInstance.token = token2;
3630
+ }, refreshTokenInterval);
3631
+ conductorClientInstance.intervalId = intervalId;
3517
3632
  }
3518
- throw e;
3633
+ return conductorClientInstance;
3634
+ } else {
3635
+ return new ConductorClient(config, requestHandler);
3519
3636
  }
3520
3637
  };
3521
- return fetchWithDns;
3522
3638
  };
3523
3639
 
3640
+ // src/orkes/OrkesConductorClient.ts
3641
+ var defaultRequestHandler3 = (request3, config, options) => request3(config, options);
3642
+ var orkesConductorClient = baseOrkesConductorClient(
3643
+ fetch,
3644
+ defaultRequestHandler3
3645
+ );
3646
+
3524
3647
  // src/orkes/request/request.ts
3525
3648
  var isDefined2 = (value) => {
3526
3649
  return value !== void 0 && value !== null;
@@ -3756,91 +3879,104 @@ var request2 = (config, options, fetchFn = fetch) => {
3756
3879
  });
3757
3880
  };
3758
3881
 
3759
- // src/orkes/BaseOrkesConductorClient.ts
3760
- var defaultRequestHandler2 = (request3, config, options) => request3(config, options);
3761
- var REFRESH_TOKEN_IN_MILLISECONDS = 30 * 60 * 1e3;
3762
- var AuthConductorClient = class extends ConductorClient {
3763
- constructor(config, requestHandler = defaultRequestHandler2) {
3764
- super(config, requestHandler);
3882
+ // src/orkes/request/fetchCatchDns/DnsResolver.ts
3883
+ import { promises } from "dns";
3884
+ var DEFAULT_OPTIONS = {
3885
+ logger: noopLogger,
3886
+ resolver: promises.resolve4
3887
+ };
3888
+ var dnsResolver = async (host, { resolver = promises.resolve4, logger = console } = DEFAULT_OPTIONS) => {
3889
+ try {
3890
+ const addresses = await resolver(host);
3891
+ if (addresses.length > 0)
3892
+ return addresses[0];
3893
+ } catch (e) {
3894
+ logger.error("Could not resolve host: " + host + " error: " + e);
3765
3895
  }
3766
- /**
3767
- * Stops the interval that refreshes the token
3768
- */
3769
- stop() {
3770
- if (this.intervalId != null) {
3771
- clearInterval(this.intervalId);
3896
+ return void 0;
3897
+ };
3898
+
3899
+ // src/orkes/request/fetchCatchDns/DnsCache.ts
3900
+ var DnsCacheResolver = class {
3901
+ _cache = /* @__PURE__ */ new Map();
3902
+ constructor({ initialCache = /* @__PURE__ */ new Map() } = {}) {
3903
+ this._cache = initialCache;
3904
+ }
3905
+ async resolve(host) {
3906
+ const cachedIp = this._cache.get(host);
3907
+ if (cachedIp) {
3908
+ return cachedIp;
3909
+ }
3910
+ const ip = await dnsResolver(host);
3911
+ if (ip != void 0) {
3912
+ this._cache.set(host, ip);
3772
3913
  }
3914
+ return ip;
3915
+ }
3916
+ clearCache() {
3917
+ this._cache.clear();
3918
+ }
3919
+ removeCache(host) {
3920
+ this._cache.delete(host);
3921
+ }
3922
+ get cache() {
3923
+ return this._cache;
3773
3924
  }
3774
3925
  };
3775
- var baseOrkesConductorClient = (fetchFn, baseRequestHandler = defaultRequestHandler2) => {
3776
- const requestTokenForKeySecret = (keyId, keySecret, tokenUrl) => fetchFn(tokenUrl, {
3777
- headers: {
3778
- "Content-Type": "application/json",
3779
- Accept: "application/json"
3780
- },
3781
- body: JSON.stringify({ keyId, keySecret }),
3782
- method: "POST"
3783
- });
3784
- return async (config, requestHandler = baseRequestHandler) => {
3785
- if (config?.keySecret != null && config?.keyId != null) {
3786
- const {
3787
- serverUrl,
3788
- keyId,
3789
- keySecret,
3790
- refreshTokenInterval = REFRESH_TOKEN_IN_MILLISECONDS
3791
- } = config;
3792
- const tokenUrl = `${serverUrl}/token`;
3793
- const res = await requestTokenForKeySecret(keyId, keySecret, tokenUrl);
3794
- const { token } = await res.json();
3795
- const conductorClientInstance = new AuthConductorClient(
3796
- { ...config, TOKEN: token },
3797
- requestHandler
3798
- );
3799
- if (token != null && refreshTokenInterval > 0) {
3800
- const intervalId = setInterval(async () => {
3801
- const res2 = await requestTokenForKeySecret(
3802
- keyId,
3803
- keySecret,
3804
- tokenUrl
3805
- );
3806
- const { token: token2 } = await res2.json();
3807
- conductorClientInstance.token = token2;
3808
- }, refreshTokenInterval);
3809
- conductorClientInstance.intervalId = intervalId;
3926
+
3927
+ // src/orkes/request/fetchCatchDns/fetchCatchDns.ts
3928
+ import { isIP } from "net";
3929
+ var isEmpty = (value) => {
3930
+ return value === void 0 || value.trim().length === 0;
3931
+ };
3932
+ var toMaybeUrl = (originalUrl, modifiedParams) => {
3933
+ const urlToHit = new URL(originalUrl.toString());
3934
+ urlToHit.host = isEmpty(modifiedParams.port) ? `${modifiedParams.host}:${modifiedParams.port}` : modifiedParams.host;
3935
+ return urlToHit;
3936
+ };
3937
+ var DEFAULT_OPTIONS2 = {
3938
+ dnsCache: new DnsCacheResolver(),
3939
+ headerFactory: (headers) => new Headers(headers || {})
3940
+ };
3941
+ var fetchCatchDns = (fetch2, {
3942
+ dnsCache = new DnsCacheResolver(),
3943
+ headerFactory = (headers) => new Headers(headers || {})
3944
+ } = DEFAULT_OPTIONS2) => {
3945
+ const fetchWithDns = async (input, options) => {
3946
+ const parsedUrl = new URL(input.toString());
3947
+ const { hostname, host, port } = parsedUrl;
3948
+ if (isIP(hostname)) {
3949
+ return await fetch2(input, options);
3950
+ }
3951
+ const maybeTargetIp = await dnsCache.resolve(hostname);
3952
+ if (isEmpty(maybeTargetIp)) {
3953
+ return await fetch2(input, options);
3954
+ }
3955
+ const target = toMaybeUrl(input, {
3956
+ ...parsedUrl,
3957
+ host: maybeTargetIp,
3958
+ port
3959
+ });
3960
+ const headersOverride = headerFactory(options?.headers ?? {});
3961
+ if (!headersOverride.has("Host")) {
3962
+ headersOverride.set("Host", host);
3963
+ }
3964
+ const optionsOverride = {
3965
+ ...options,
3966
+ headers: headersOverride
3967
+ };
3968
+ try {
3969
+ const res = await fetch2(target.toString(), optionsOverride);
3970
+ return res;
3971
+ } catch (e) {
3972
+ if (e && e?.code === "ETIMEDOUT") {
3973
+ dnsCache.removeCache(hostname);
3810
3974
  }
3811
- return conductorClientInstance;
3812
- } else {
3813
- return new ConductorClient(config, requestHandler);
3975
+ throw e;
3814
3976
  }
3815
3977
  };
3978
+ return fetchWithDns;
3816
3979
  };
3817
-
3818
- // src/orkes/OrkesConductorClient.ts
3819
- import fetch2, { Headers as Headers2 } from "node-fetch";
3820
- import http from "http";
3821
- import https from "https";
3822
- var httpAgent = new http.Agent({ keepAlive: true });
3823
- var httpsAgent = new https.Agent({ keepAlive: true });
3824
- var agent = (_parsedURL) => _parsedURL.protocol == "http:" ? httpAgent : httpsAgent;
3825
- var nodeFetchWrapper = async (input, options = {}) => {
3826
- const res = await fetch2(input.toString(), {
3827
- ...options,
3828
- agent
3829
- });
3830
- return res;
3831
- };
3832
- var fetchCache = fetchCatchDns(
3833
- nodeFetchWrapper,
3834
- {
3835
- //@ts-ignore
3836
- headerFactory: (headers) => new Headers2(headers || {})
3837
- }
3838
- );
3839
- var defaultRequestHandler3 = (__request, config, options) => request2(config, options, fetchCache);
3840
- var orkesConductorClient = baseOrkesConductorClient(
3841
- fetchCache,
3842
- defaultRequestHandler3
3843
- );
3844
3980
  export {
3845
3981
  ApiError,
3846
3982
  AuthConductorClient,
@@ -3865,6 +4001,7 @@ export {
3865
4001
  WorkflowExecutor,
3866
4002
  WorkflowResourceService,
3867
4003
  baseOrkesConductorClient,
4004
+ completedTaskMatchingType,
3868
4005
  conductorEventTask,
3869
4006
  doWhileTask,
3870
4007
  dynamicForkTask,