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

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/browser.mjs CHANGED
@@ -1823,83 +1823,70 @@ var HumanTaskService = class {
1823
1823
  this.httpRequest = httpRequest;
1824
1824
  }
1825
1825
  /**
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
1826
+ * If the workflow is disconnected from tasks, this API can be used to clean up (in bulk)
1827
+ * @param requestBody
1828
+ * @returns any OK
1835
1829
  * @throws ApiError
1836
1830
  */
1837
- getTasksByFilter(state, assignee, assigneeType, claimedBy, taskName, freeText, includeInputOutput = false) {
1831
+ deleteTaskFromHumanTaskRecords(requestBody) {
1838
1832
  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
- }
1833
+ method: "DELETE",
1834
+ url: "/human/tasks/delete",
1835
+ body: requestBody,
1836
+ mediaType: "application/json"
1850
1837
  });
1851
1838
  }
1852
1839
  /**
1853
- * Get task load grouped by workflow name and task ref name per user
1854
- * @returns HumanTaskLoad OK
1840
+ * If the workflow is disconnected from tasks, this API can be used to clean up
1841
+ * @param taskId
1842
+ * @returns any OK
1855
1843
  * @throws ApiError
1856
1844
  */
1857
- getTaskLoad() {
1845
+ deleteTaskFromHumanTaskRecords1(taskId) {
1858
1846
  return this.httpRequest.request({
1859
- method: "GET",
1860
- url: "/human/tasks/load"
1847
+ method: "DELETE",
1848
+ url: "/human/tasks/delete/{taskId}",
1849
+ path: {
1850
+ "taskId": taskId
1851
+ }
1861
1852
  });
1862
1853
  }
1863
1854
  /**
1864
1855
  * 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
1856
+ * @param requestBody
1857
+ * @returns HumanTaskSearchResult OK
1873
1858
  * @throws ApiError
1874
1859
  */
1875
- search1(queryId, start, size = 100, freeText = "*", query, jsonQuery, includeInputOutput = false) {
1860
+ search(requestBody) {
1876
1861
  return this.httpRequest.request({
1877
- method: "GET",
1862
+ method: "POST",
1878
1863
  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
- }
1864
+ body: requestBody,
1865
+ mediaType: "application/json"
1888
1866
  });
1889
1867
  }
1890
1868
  /**
1891
- * If the workflow is disconnected from tasks, this API can be used to clean up
1892
- * @param taskId
1869
+ * Update task output, optionally complete
1870
+ * @param workflowId
1871
+ * @param taskRefName
1872
+ * @param requestBody
1873
+ * @param complete
1874
+ * @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
1875
  * @returns any OK
1894
1876
  * @throws ApiError
1895
1877
  */
1896
- updateTaskOutput1(taskId) {
1878
+ updateTaskOutputByRef(workflowId, taskRefName, requestBody, complete = false, iteration) {
1897
1879
  return this.httpRequest.request({
1898
- method: "DELETE",
1899
- url: "/human/tasks/{taskId}",
1900
- path: {
1901
- "taskId": taskId
1902
- }
1880
+ method: "POST",
1881
+ url: "/human/tasks/update/taskRef",
1882
+ query: {
1883
+ "workflowId": workflowId,
1884
+ "taskRefName": taskRefName,
1885
+ "complete": complete,
1886
+ "iteration": iteration
1887
+ },
1888
+ body: requestBody,
1889
+ mediaType: "application/json"
1903
1890
  });
1904
1891
  }
1905
1892
  /**
@@ -1917,33 +1904,22 @@ var HumanTaskService = class {
1917
1904
  }
1918
1905
  });
1919
1906
  }
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
1907
  /**
1936
1908
  * Claim a task by authenticated Conductor user
1937
1909
  * @param taskId
1910
+ * @param overrideAssignment
1938
1911
  * @returns any OK
1939
1912
  * @throws ApiError
1940
1913
  */
1941
- claimTask(taskId) {
1914
+ claimTask(taskId, overrideAssignment = false) {
1942
1915
  return this.httpRequest.request({
1943
1916
  method: "POST",
1944
1917
  url: "/human/tasks/{taskId}/claim",
1945
1918
  path: {
1946
1919
  "taskId": taskId
1920
+ },
1921
+ query: {
1922
+ "overrideAssignment": overrideAssignment
1947
1923
  }
1948
1924
  });
1949
1925
  }
@@ -1951,16 +1927,20 @@ var HumanTaskService = class {
1951
1927
  * Claim a task to an external user
1952
1928
  * @param taskId
1953
1929
  * @param userId
1930
+ * @param overrideAssignment
1954
1931
  * @returns any OK
1955
1932
  * @throws ApiError
1956
1933
  */
1957
- assignAndClaim(taskId, userId) {
1934
+ assignAndClaim(taskId, userId, overrideAssignment = false) {
1958
1935
  return this.httpRequest.request({
1959
1936
  method: "POST",
1960
1937
  url: "/human/tasks/{taskId}/externalUser/{userId}",
1961
1938
  path: {
1962
1939
  "taskId": taskId,
1963
1940
  "userId": userId
1941
+ },
1942
+ query: {
1943
+ "overrideAssignment": overrideAssignment
1964
1944
  }
1965
1945
  });
1966
1946
  }
@@ -1998,17 +1978,21 @@ var HumanTaskService = class {
1998
1978
  });
1999
1979
  }
2000
1980
  /**
2001
- * Get human task state log entries by task id
1981
+ * If a task is assigned to a user, this API can be used to skip that assignment and move to the next assignee
2002
1982
  * @param taskId
2003
- * @returns HumanTaskStateLogEntry OK
1983
+ * @param reason
1984
+ * @returns any OK
2004
1985
  * @throws ApiError
2005
1986
  */
2006
- getStateLogs(taskId) {
1987
+ skipTask(taskId, reason) {
2007
1988
  return this.httpRequest.request({
2008
- method: "GET",
2009
- url: "/human/tasks/{taskId}/stateLogs",
1989
+ method: "POST",
1990
+ url: "/human/tasks/{taskId}/skip",
2010
1991
  path: {
2011
1992
  "taskId": taskId
1993
+ },
1994
+ query: {
1995
+ "reason": reason
2012
1996
  }
2013
1997
  });
2014
1998
  }
@@ -2035,48 +2019,51 @@ var HumanTaskService = class {
2035
2019
  });
2036
2020
  }
2037
2021
  /**
2038
- * Delete human task templates by name
2022
+ * List all user form templates or get templates by name, or a template by name and version
2039
2023
  * @param name
2040
- * @returns any OK
2024
+ * @param version
2025
+ * @returns HumanTaskTemplate OK
2041
2026
  * @throws ApiError
2042
2027
  */
2043
- deleteTemplatesByName(name) {
2028
+ getAllTemplates(name, version) {
2044
2029
  return this.httpRequest.request({
2045
- method: "DELETE",
2030
+ method: "GET",
2046
2031
  url: "/human/template",
2047
2032
  query: {
2048
- "name": name
2033
+ "name": name,
2034
+ "version": version
2049
2035
  }
2050
2036
  });
2051
2037
  }
2052
2038
  /**
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
2039
+ * Save user form template
2040
+ * @param requestBody
2041
+ * @param newVersion
2042
+ * @returns HumanTaskTemplate OK
2057
2043
  * @throws ApiError
2058
2044
  */
2059
- getAllTemplates(name, version) {
2045
+ saveTemplate(requestBody, newVersion = false) {
2060
2046
  return this.httpRequest.request({
2061
- method: "GET",
2047
+ method: "POST",
2062
2048
  url: "/human/template",
2063
2049
  query: {
2064
- "name": name,
2065
- "version": version
2066
- }
2050
+ "newVersion": newVersion
2051
+ },
2052
+ body: requestBody,
2053
+ mediaType: "application/json"
2067
2054
  });
2068
2055
  }
2069
2056
  /**
2070
- * Save human task template
2057
+ * Save user form template
2071
2058
  * @param requestBody
2072
2059
  * @param newVersion
2073
- * @returns string OK
2060
+ * @returns HumanTaskTemplate OK
2074
2061
  * @throws ApiError
2075
2062
  */
2076
- saveTemplate(requestBody, newVersion = false) {
2063
+ saveTemplates(requestBody, newVersion = false) {
2077
2064
  return this.httpRequest.request({
2078
2065
  method: "POST",
2079
- url: "/human/template",
2066
+ url: "/human/template/bulk",
2080
2067
  query: {
2081
2068
  "newVersion": newVersion
2082
2069
  },
@@ -2085,32 +2072,51 @@ var HumanTaskService = class {
2085
2072
  });
2086
2073
  }
2087
2074
  /**
2088
- * Delete human task template
2089
- * @param id
2075
+ * Delete all versions of user form template by name
2076
+ * @param name
2090
2077
  * @returns any OK
2091
2078
  * @throws ApiError
2092
2079
  */
2093
- deleteTemplateById(id) {
2080
+ deleteTemplateByName(name) {
2094
2081
  return this.httpRequest.request({
2095
2082
  method: "DELETE",
2096
- url: "/human/template/{id}",
2083
+ url: "/human/template/{name}",
2097
2084
  path: {
2098
- "id": id
2085
+ "name": name
2099
2086
  }
2100
2087
  });
2101
2088
  }
2102
2089
  /**
2103
- * Get human task template by id
2104
- * @param id
2105
- * @returns HumanTaskTemplateEntry OK
2090
+ * Delete a version of form template by name
2091
+ * @param name
2092
+ * @param version
2093
+ * @returns any OK
2106
2094
  * @throws ApiError
2107
2095
  */
2108
- getTemplateById(id) {
2096
+ deleteTemplatesByNameAndVersion(name, version) {
2097
+ return this.httpRequest.request({
2098
+ method: "DELETE",
2099
+ url: "/human/template/{name}/{version}",
2100
+ path: {
2101
+ "name": name,
2102
+ "version": version
2103
+ }
2104
+ });
2105
+ }
2106
+ /**
2107
+ * Get user form template by name and version
2108
+ * @param name
2109
+ * @param version
2110
+ * @returns HumanTaskTemplate OK
2111
+ * @throws ApiError
2112
+ */
2113
+ getTemplateByNameAndVersion(name, version) {
2109
2114
  return this.httpRequest.request({
2110
2115
  method: "GET",
2111
- url: "/human/template/{id}",
2116
+ url: "/human/template/{name}/{version}",
2112
2117
  path: {
2113
- "id": id
2118
+ "name": name,
2119
+ "version": version
2114
2120
  }
2115
2121
  });
2116
2122
  }
@@ -2568,9 +2574,18 @@ var tryCatchReThrow = (fn) => {
2568
2574
  throw errorMapper(error);
2569
2575
  }
2570
2576
  };
2577
+ function reverseFind(array, predicate) {
2578
+ for (let i = array.length - 1; i >= 0; i--) {
2579
+ if (predicate(array[i], i, array)) {
2580
+ return array[i];
2581
+ }
2582
+ }
2583
+ return void 0;
2584
+ }
2571
2585
 
2572
2586
  // src/core/executor.ts
2573
2587
  var RETRY_TIME_IN_MILLISECONDS = 1e4;
2588
+ var completedTaskMatchingType = (taskType) => (task) => task.status === "COMPLETED" && task.taskType === taskType;
2574
2589
  var WorkflowExecutor = class {
2575
2590
  constructor(client) {
2576
2591
  this._client = client;
@@ -2615,6 +2630,26 @@ var WorkflowExecutor = class {
2615
2630
  startWorkflows(workflowsRequest) {
2616
2631
  return tryCatchReThrow(() => workflowsRequest.map(this.startWorkflow));
2617
2632
  }
2633
+ async goBackToTask(workflowInstanceId, taskFinderPredicate, rerunWorkflowRequestOverrides = {}) {
2634
+ const { tasks: executedTasks = [] } = await this.getExecution(
2635
+ workflowInstanceId
2636
+ );
2637
+ const maybePreviousTask = reverseFind(
2638
+ executedTasks,
2639
+ taskFinderPredicate
2640
+ );
2641
+ if (!maybePreviousTask) {
2642
+ throw new Error("Task not found");
2643
+ }
2644
+ await this.reRun(workflowInstanceId, {
2645
+ //taskInput: previousTask.inputData,
2646
+ ...rerunWorkflowRequestOverrides,
2647
+ reRunFromTaskId: maybePreviousTask.taskId
2648
+ });
2649
+ }
2650
+ async goBackToFirstTaskMatchingType(workflowInstanceId, taskType) {
2651
+ return this.goBackToTask(workflowInstanceId, completedTaskMatchingType(taskType));
2652
+ }
2618
2653
  /**
2619
2654
  * Takes an workflowInstanceId and an includeTasks and an optional retry parameter returns the whole execution status.
2620
2655
  * If includeTasks flag is provided. Details of tasks execution will be returned as well,
@@ -2659,6 +2694,22 @@ var WorkflowExecutor = class {
2659
2694
  )
2660
2695
  );
2661
2696
  }
2697
+ /**
2698
+ * Returns a summary of the current workflow status.
2699
+ *
2700
+ * @param workflowInstanceId current running workflow
2701
+ * @param includeOutput flag to include output
2702
+ * @param includeVariables flag to include variable
2703
+ * @returns Promise<WorkflowStatus>
2704
+ */
2705
+ getExecution(workflowInstanceId, includeTasks = true) {
2706
+ return tryCatchReThrow(
2707
+ () => this._client.workflowResource.getExecutionStatus(
2708
+ workflowInstanceId,
2709
+ includeTasks
2710
+ )
2711
+ );
2712
+ }
2662
2713
  /**
2663
2714
  * Pauses a running workflow
2664
2715
  * @param workflowInstanceId current workflow execution
@@ -2828,11 +2879,24 @@ var WorkflowExecutor = class {
2828
2879
  };
2829
2880
 
2830
2881
  // src/core/human.ts
2882
+ var EMPTY_SEARCH = {
2883
+ size: 15,
2884
+ states: [],
2885
+ taskInputQuery: "",
2886
+ taskOutputQuery: "",
2887
+ definitionNames: [],
2888
+ taskRefNames: [],
2889
+ claimants: [],
2890
+ assignees: [],
2891
+ start: 0
2892
+ };
2893
+ var DEFAULT_POLL_INTERVAL2 = { pollInterval: 100, maxPollTimes: 20 };
2831
2894
  var HumanExecutor = class {
2832
2895
  constructor(client) {
2833
2896
  this._client = client;
2834
2897
  }
2835
2898
  /**
2899
+ * @deprecated use search instead
2836
2900
  * Takes a set of filter parameters. return matches of human tasks for that set of parameters
2837
2901
  * @param state
2838
2902
  * @param assignee
@@ -2843,21 +2907,68 @@ var HumanExecutor = class {
2843
2907
  * @param includeInputOutput
2844
2908
  * @returns
2845
2909
  */
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
2910
+ async getTasksByFilter(state, assignee, assigneeType, claimedBy, taskName, taskInputQuery, taskOutputQuery) {
2911
+ const [claimedUserType, claimedUser] = claimedBy?.split(":") ?? [];
2912
+ if (claimedUserType && !claimedUser) {
2913
+ throw new Error("claimedBy should be in the format of <userType>:<user>");
2914
+ }
2915
+ const response = await this.search({
2916
+ states: [state],
2917
+ assignees: assignee ? [{ userType: assigneeType, user: assignee }] : [],
2918
+ claimants: claimedBy ? [{ userType: claimedUserType, user: claimedUser }] : [],
2919
+ taskRefNames: taskName ? [taskName] : [],
2920
+ taskInputQuery,
2921
+ taskOutputQuery
2922
+ });
2923
+ return response;
2924
+ }
2925
+ /**
2926
+ * Takes a set of filter parameters. return matches of human tasks for that set of parameters
2927
+ * @param state
2928
+ * @param assignee
2929
+ * @param assigneeType
2930
+ * @param claimedBy
2931
+ * @param taskName
2932
+ * @param freeText
2933
+ * @param includeInputOutput
2934
+ * @returns Promise<HumanTaskEntry[]>
2935
+ */
2936
+ async search(searchParams) {
2937
+ const search = { ...EMPTY_SEARCH, ...searchParams };
2938
+ const response = await tryCatchReThrow(
2939
+ () => this._client.humanTask.search(search)
2855
2940
  );
2856
2941
  if (response.results != void 0) {
2857
2942
  return response.results;
2858
2943
  }
2859
2944
  return [];
2860
2945
  }
2946
+ /**
2947
+ * Takes a set of filter parameters. An polling interval options. will poll until the task returns a result
2948
+ * @param state
2949
+ * @param assignee
2950
+ * @param assigneeType
2951
+ * @param claimedBy
2952
+ * @param taskName
2953
+ * @param freeText
2954
+ * @param includeInputOutput
2955
+ * @returns Promise<HumanTaskEntry[]>
2956
+ */
2957
+ async pollSearch(searchParams, {
2958
+ pollInterval = 100,
2959
+ maxPollTimes = 20
2960
+ } = DEFAULT_POLL_INTERVAL2) {
2961
+ let pollCount = 0;
2962
+ while (pollCount < maxPollTimes) {
2963
+ const response = await this.search(searchParams);
2964
+ if (response.length > 0) {
2965
+ return response;
2966
+ }
2967
+ await new Promise((resolve2) => setTimeout(resolve2, pollInterval));
2968
+ pollCount++;
2969
+ }
2970
+ return [];
2971
+ }
2861
2972
  /**
2862
2973
  * Returns task for a given task id
2863
2974
  * @param taskId
@@ -2873,11 +2984,9 @@ var HumanExecutor = class {
2873
2984
  * @returns
2874
2985
  */
2875
2986
  async claimTaskAsExternalUser(taskId, assignee) {
2876
- try {
2877
- await this._client.humanTask.assignAndClaim(taskId, assignee);
2878
- } catch (error) {
2879
- throw errorMapper(error);
2880
- }
2987
+ return tryCatchReThrow(
2988
+ () => this._client.humanTask.assignAndClaim(taskId, assignee)
2989
+ );
2881
2990
  }
2882
2991
  /**
2883
2992
  * Claim task as conductor user
@@ -2885,11 +2994,7 @@ var HumanExecutor = class {
2885
2994
  * @returns
2886
2995
  */
2887
2996
  async claimTaskAsConductorUser(taskId) {
2888
- try {
2889
- await this._client.humanTask.claimTask(taskId);
2890
- } catch (error) {
2891
- throw errorMapper(error);
2892
- }
2997
+ return tryCatchReThrow(() => this._client.humanTask.claimTask(taskId));
2893
2998
  }
2894
2999
  /**
2895
3000
  * Claim task as conductor user
@@ -2905,15 +3010,24 @@ var HumanExecutor = class {
2905
3010
  }
2906
3011
  }
2907
3012
  /**
2908
- * Returns a HumanTaskTemplateEntry for a given templateId
3013
+ * Returns a HumanTaskTemplateEntry for a given name and version
2909
3014
  * @param templateId
2910
3015
  * @returns
2911
3016
  */
2912
- async getTemplateById(templateId) {
3017
+ async getTemplateByNameVersion(name, version) {
2913
3018
  return tryCatchReThrow(
2914
- () => this._client.humanTask.getTemplateById(templateId)
3019
+ () => this._client.humanTask.getTemplateByNameAndVersion(name, version)
2915
3020
  );
2916
3021
  }
3022
+ /**
3023
+ * @deprecated use getTemplate instead. name will be used as id here with version 1
3024
+ * Returns a HumanTaskTemplateEntry for a given templateId
3025
+ * @param templateId
3026
+ * @returns
3027
+ */
3028
+ async getTemplateById(templateNameVersionOne) {
3029
+ return this.getTemplateByNameVersion(templateNameVersionOne, 1);
3030
+ }
2917
3031
  /**
2918
3032
  * Takes a taskId and a partial body. will update with given body
2919
3033
  * @param taskId
@@ -3508,6 +3622,7 @@ export {
3508
3622
  WorkflowBulkResourceService,
3509
3623
  WorkflowExecutor,
3510
3624
  WorkflowResourceService,
3625
+ completedTaskMatchingType,
3511
3626
  conductorEventTask,
3512
3627
  doWhileTask,
3513
3628
  dynamicForkTask,