@red-hat-developer-hub/backstage-plugin-orchestrator-backend 5.1.0 → 5.2.0

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/CHANGELOG.md CHANGED
@@ -1,5 +1,44 @@
1
1
  ### Dependencies
2
2
 
3
+ ## 5.2.0
4
+
5
+ ### Minor Changes
6
+
7
+ - 967c377: Fixed unsupported filter operators
8
+
9
+ ### Patch Changes
10
+
11
+ - e3ebb0c: replace abort mutation with call to delete
12
+ - 665947d: fix bug in error handling of execute API
13
+ - 4e3ccc2: Add retrigger option to UI using v2 API
14
+ - d1010f9: improve logging of router
15
+ - bee24dc: add unavailable workflows to cache and overview
16
+ - b0e3ede: improve data index network error
17
+ - 10f17e3: Fixed a typo in FilterBuilder error message
18
+ - aebd2b0: improved devMode, added podman and macos support
19
+ - Updated dependencies [967c377]
20
+ - Updated dependencies [05a1ce0]
21
+ - Updated dependencies [816d8bc]
22
+ - Updated dependencies [c7de094]
23
+ - Updated dependencies [bee24dc]
24
+ - Updated dependencies [d4fa6bf]
25
+ - @red-hat-developer-hub/backstage-plugin-orchestrator-common@1.26.0
26
+
27
+ ## 5.1.1
28
+
29
+ ### Patch Changes
30
+
31
+ - d59e940: Updated dependency `@openapitools/openapi-generator-cli` to `2.15.3`.
32
+ Updated dependency `prettier` to `3.4.2`.
33
+ Updated dependency `@janus-idp/cli` to `1.19.1`.
34
+ Updated dependency `monaco-editor` to `0.52.2`.
35
+ Updated dependency `monaco-yaml` to `5.2.3`.
36
+ Updated dependency `sass` to `1.83.0`.
37
+ Updated dependency `webpack` to `5.97.1`.
38
+ - Updated dependencies [d59e940]
39
+ - Updated dependencies [9cc8c89]
40
+ - @red-hat-developer-hub/backstage-plugin-orchestrator-common@1.25.1
41
+
3
42
  ## 5.1.0
4
43
 
5
44
  ### Minor Changes
@@ -1,8 +1,40 @@
1
1
  'use strict';
2
2
 
3
3
  var backstagePluginOrchestratorCommon = require('@red-hat-developer-hub/backstage-plugin-orchestrator-common');
4
- var V2Mappings = require('../service/api/mapping/V2Mappings.cjs.js');
5
4
 
5
+ const supportedOperators = [
6
+ backstagePluginOrchestratorCommon.FieldFilterOperatorEnum.Eq,
7
+ backstagePluginOrchestratorCommon.FieldFilterOperatorEnum.Like,
8
+ backstagePluginOrchestratorCommon.FieldFilterOperatorEnum.In,
9
+ backstagePluginOrchestratorCommon.FieldFilterOperatorEnum.IsNull,
10
+ backstagePluginOrchestratorCommon.FieldFilterOperatorEnum.Gt,
11
+ backstagePluginOrchestratorCommon.FieldFilterOperatorEnum.Gte,
12
+ backstagePluginOrchestratorCommon.FieldFilterOperatorEnum.Lt,
13
+ backstagePluginOrchestratorCommon.FieldFilterOperatorEnum.Lte,
14
+ backstagePluginOrchestratorCommon.FieldFilterOperatorEnum.Between
15
+ ];
16
+ const supportedOperatorsByType = {
17
+ [backstagePluginOrchestratorCommon.TypeName.String]: [
18
+ backstagePluginOrchestratorCommon.FieldFilterOperatorEnum.In,
19
+ backstagePluginOrchestratorCommon.FieldFilterOperatorEnum.Like,
20
+ backstagePluginOrchestratorCommon.FieldFilterOperatorEnum.IsNull,
21
+ backstagePluginOrchestratorCommon.FieldFilterOperatorEnum.Eq
22
+ ],
23
+ [backstagePluginOrchestratorCommon.TypeName.Id]: [
24
+ backstagePluginOrchestratorCommon.FieldFilterOperatorEnum.In,
25
+ backstagePluginOrchestratorCommon.FieldFilterOperatorEnum.IsNull,
26
+ backstagePluginOrchestratorCommon.FieldFilterOperatorEnum.Eq
27
+ ],
28
+ [backstagePluginOrchestratorCommon.TypeName.Date]: [
29
+ backstagePluginOrchestratorCommon.FieldFilterOperatorEnum.IsNull,
30
+ backstagePluginOrchestratorCommon.FieldFilterOperatorEnum.Eq,
31
+ backstagePluginOrchestratorCommon.FieldFilterOperatorEnum.Gt,
32
+ backstagePluginOrchestratorCommon.FieldFilterOperatorEnum.Gte,
33
+ backstagePluginOrchestratorCommon.FieldFilterOperatorEnum.Lt,
34
+ backstagePluginOrchestratorCommon.FieldFilterOperatorEnum.Lte,
35
+ backstagePluginOrchestratorCommon.FieldFilterOperatorEnum.Between
36
+ ]
37
+ };
6
38
  function isLogicalFilter(filter) {
7
39
  return filter.filters !== void 0;
8
40
  }
@@ -34,22 +66,6 @@ function isEnumFilter(fieldName, type) {
34
66
  }
35
67
  return false;
36
68
  }
37
- function convertEnumValue(fieldName, fieldValue, type) {
38
- if (type === "ProcessInstance") {
39
- if (fieldName === "state") {
40
- const state = backstagePluginOrchestratorCommon.ProcessInstanceStatusDTO[fieldValue];
41
- if (!state) {
42
- throw new Error(
43
- `status ${fieldValue} is not a valid value of ProcessInstanceStatusDTO`
44
- );
45
- }
46
- return V2Mappings.getProcessInstanceStateFromStatusDTOString(state).valueOf();
47
- }
48
- }
49
- throw new Error(
50
- `Unsupported enum ${fieldName}: can't convert value ${fieldValue}`
51
- );
52
- }
53
69
  function isValidEnumOperator(operator) {
54
70
  return operator === backstagePluginOrchestratorCommon.FieldFilterOperatorEnum.In || operator === backstagePluginOrchestratorCommon.FieldFilterOperatorEnum.Eq;
55
71
  }
@@ -60,11 +76,6 @@ function handleBinaryOperator(binaryFilter, fieldDef, type) {
60
76
  `Invalid operator ${binaryFilter.operator} for enum field ${binaryFilter.field} filter`
61
77
  );
62
78
  }
63
- binaryFilter.value = convertEnumValue(
64
- binaryFilter.field,
65
- binaryFilter.value,
66
- type
67
- );
68
79
  }
69
80
  const formattedValue = Array.isArray(binaryFilter.value) ? `[${binaryFilter.value.map((v) => formatValue(binaryFilter.field, v, fieldDef, type)).join(", ")}]` : formatValue(binaryFilter.field, binaryFilter.value, fieldDef, type);
70
81
  return `${binaryFilter.field}: {${getGraphQLOperator(
@@ -79,14 +90,19 @@ function buildFilterCondition(introspection, type, filters) {
79
90
  return handleLogicalFilter(introspection, type, filters);
80
91
  }
81
92
  if (!isOperatorSupported(filters.operator)) {
82
- throw new Error(`Unsopported operator ${filters.operator}`);
93
+ throw new Error(
94
+ `Unsupported operator ${filters.operator}. Supported operators are: ${supportedOperators.join(", ")}`
95
+ );
83
96
  }
84
97
  const fieldDef = introspection.find((f) => f.name === filters.field);
85
98
  if (!fieldDef) {
86
99
  throw new Error(`Can't find field "${filters.field}" definition`);
87
100
  }
88
- if (!isOperatorAllowedForField(filters.operator, fieldDef)) {
89
- throw new Error(`Unsupported field type ${fieldDef.type.name}`);
101
+ if (!isOperatorAllowedForField(filters.operator, fieldDef, type)) {
102
+ const allowedOperators = supportedOperatorsByType[fieldDef.type.name] || [];
103
+ throw new Error(
104
+ `Unsupported operator ${filters.operator} for field "${fieldDef.name}" of type "${fieldDef.type.name}". Allowed operators are: ${allowedOperators.join(", ")}`
105
+ );
90
106
  }
91
107
  switch (filters.operator) {
92
108
  case backstagePluginOrchestratorCommon.FieldFilterOperatorEnum.IsNull:
@@ -106,36 +122,16 @@ function buildFilterCondition(introspection, type, filters) {
106
122
  }
107
123
  }
108
124
  function isOperatorSupported(operator) {
109
- return operator === backstagePluginOrchestratorCommon.FieldFilterOperatorEnum.Eq || operator === backstagePluginOrchestratorCommon.FieldFilterOperatorEnum.Like || operator === backstagePluginOrchestratorCommon.FieldFilterOperatorEnum.In || operator === backstagePluginOrchestratorCommon.FieldFilterOperatorEnum.IsNull || operator === backstagePluginOrchestratorCommon.FieldFilterOperatorEnum.Gt || operator === backstagePluginOrchestratorCommon.FieldFilterOperatorEnum.Gte || operator === backstagePluginOrchestratorCommon.FieldFilterOperatorEnum.Lt || operator === backstagePluginOrchestratorCommon.FieldFilterOperatorEnum.Lte || operator === backstagePluginOrchestratorCommon.FieldFilterOperatorEnum.Between;
125
+ return supportedOperators.includes(operator);
110
126
  }
111
127
  function isFieldFilterSupported(fieldDef) {
112
128
  return fieldDef?.type.name === backstagePluginOrchestratorCommon.TypeName.String;
113
129
  }
114
- function isOperatorAllowedForField(operator, fieldDef) {
115
- const allowedOperators = {
116
- [backstagePluginOrchestratorCommon.TypeName.String]: [
117
- backstagePluginOrchestratorCommon.FieldFilterOperatorEnum.In,
118
- backstagePluginOrchestratorCommon.FieldFilterOperatorEnum.Like,
119
- backstagePluginOrchestratorCommon.FieldFilterOperatorEnum.IsNull,
120
- backstagePluginOrchestratorCommon.FieldFilterOperatorEnum.Eq
121
- ],
122
- [backstagePluginOrchestratorCommon.TypeName.Id]: [
123
- backstagePluginOrchestratorCommon.FieldFilterOperatorEnum.In,
124
- backstagePluginOrchestratorCommon.FieldFilterOperatorEnum.IsNull,
125
- backstagePluginOrchestratorCommon.FieldFilterOperatorEnum.Eq
126
- ],
127
- [backstagePluginOrchestratorCommon.TypeName.Date]: [
128
- backstagePluginOrchestratorCommon.FieldFilterOperatorEnum.IsNull,
129
- backstagePluginOrchestratorCommon.FieldFilterOperatorEnum.Eq,
130
- backstagePluginOrchestratorCommon.FieldFilterOperatorEnum.Gt,
131
- backstagePluginOrchestratorCommon.FieldFilterOperatorEnum.Gte,
132
- backstagePluginOrchestratorCommon.FieldFilterOperatorEnum.Lt,
133
- backstagePluginOrchestratorCommon.FieldFilterOperatorEnum.Lte,
134
- backstagePluginOrchestratorCommon.FieldFilterOperatorEnum.Between
135
- ],
136
- [backstagePluginOrchestratorCommon.TypeName.StringArray]: []
137
- };
138
- const allowedForType = allowedOperators[fieldDef.type.name];
130
+ function isOperatorAllowedForField(operator, fieldDef, type) {
131
+ if (isEnumFilter(fieldDef.name, type) && isValidEnumOperator(operator)) {
132
+ return true;
133
+ }
134
+ const allowedForType = supportedOperatorsByType[fieldDef.type.name];
139
135
  return allowedForType ? allowedForType.includes(operator) : false;
140
136
  }
141
137
  function convertToBoolean(value) {
@@ -182,10 +178,6 @@ function getGraphQLOperator(operator) {
182
178
  return "lessThan";
183
179
  case "LTE":
184
180
  return "lessThanEqual";
185
- // case 'CONTAINS':
186
- // return "contains"
187
- // case 'CONTAINS_ALL':
188
- // case 'CONTAINS_ANY':
189
181
  case "BETWEEN":
190
182
  return "between";
191
183
  default:
@@ -194,4 +186,5 @@ function getGraphQLOperator(operator) {
194
186
  }
195
187
 
196
188
  exports.buildFilterCondition = buildFilterCondition;
189
+ exports.isOperatorAllowedForField = isOperatorAllowedForField;
197
190
  //# sourceMappingURL=filterBuilder.cjs.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"filterBuilder.cjs.js","sources":["../../src/helpers/filterBuilder.ts"],"sourcesContent":["/*\n * Copyright 2024 The Backstage Authors\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\nimport {\n FieldFilter,\n FieldFilterOperatorEnum,\n Filter,\n IntrospectionField,\n LogicalFilter,\n ProcessInstanceStatusDTO,\n TypeName,\n} from '@red-hat-developer-hub/backstage-plugin-orchestrator-common';\n\nimport { getProcessInstanceStateFromStatusDTOString } from '../service/api/mapping/V2Mappings';\n\ntype ProcessType = 'ProcessDefinition' | 'ProcessInstance';\n\nfunction isLogicalFilter(filter: Filter): filter is LogicalFilter {\n return (filter as LogicalFilter).filters !== undefined;\n}\n\nfunction handleLogicalFilter(\n introspection: IntrospectionField[],\n type: ProcessType,\n filter: LogicalFilter,\n): string {\n if (!filter.operator) return '';\n\n const subClauses = filter.filters.map(f =>\n buildFilterCondition(introspection, type, f),\n );\n\n return `${filter.operator.toLowerCase()}: {${subClauses.join(', ')}}`;\n}\n\nfunction handleBetweenOperator(filter: FieldFilter): string {\n if (!Array.isArray(filter.value) || filter.value.length !== 2) {\n throw new Error('Between operator requires an array of two elements');\n }\n return `${filter.field}: {${getGraphQLOperator(\n FieldFilterOperatorEnum.Between,\n )}: {from: \"${filter.value[0]}\", to: \"${filter.value[1]}\"}}`;\n}\n\nfunction handleIsNullOperator(filter: FieldFilter): string {\n return `${filter.field}: {${getGraphQLOperator(\n FieldFilterOperatorEnum.IsNull,\n )}: ${convertToBoolean(filter.value)}}`;\n}\n\nfunction isEnumFilter(\n fieldName: string,\n type: 'ProcessDefinition' | 'ProcessInstance',\n): boolean {\n if (type === 'ProcessInstance') {\n if (fieldName === 'state') {\n return true;\n }\n }\n return false;\n}\n\nfunction convertEnumValue(\n fieldName: string,\n fieldValue: string,\n type: 'ProcessDefinition' | 'ProcessInstance',\n): string {\n if (type === 'ProcessInstance') {\n if (fieldName === 'state') {\n const state = (ProcessInstanceStatusDTO as any)[\n fieldValue as keyof typeof ProcessInstanceStatusDTO\n ];\n\n if (!state) {\n throw new Error(\n `status ${fieldValue} is not a valid value of ProcessInstanceStatusDTO`,\n );\n }\n return getProcessInstanceStateFromStatusDTOString(state).valueOf();\n }\n }\n throw new Error(\n `Unsupported enum ${fieldName}: can't convert value ${fieldValue}`,\n );\n}\n\nfunction isValidEnumOperator(operator: FieldFilterOperatorEnum): boolean {\n return (\n operator === FieldFilterOperatorEnum.In ||\n operator === FieldFilterOperatorEnum.Eq\n );\n}\n\nfunction handleBinaryOperator(\n binaryFilter: FieldFilter,\n fieldDef: IntrospectionField,\n type: 'ProcessDefinition' | 'ProcessInstance',\n): string {\n if (isEnumFilter(binaryFilter.field, type)) {\n if (!isValidEnumOperator(binaryFilter.operator)) {\n throw new Error(\n `Invalid operator ${binaryFilter.operator} for enum field ${binaryFilter.field} filter`,\n );\n }\n binaryFilter.value = convertEnumValue(\n binaryFilter.field,\n binaryFilter.value,\n type,\n );\n }\n const formattedValue = Array.isArray(binaryFilter.value)\n ? `[${binaryFilter.value\n .map(v => formatValue(binaryFilter.field, v, fieldDef, type))\n .join(', ')}]`\n : formatValue(binaryFilter.field, binaryFilter.value, fieldDef, type);\n return `${binaryFilter.field}: {${getGraphQLOperator(\n binaryFilter.operator,\n )}: ${formattedValue}}`;\n}\n\nexport function buildFilterCondition(\n introspection: IntrospectionField[],\n type: ProcessType,\n filters?: Filter,\n): string {\n if (!filters) {\n return '';\n }\n\n if (isLogicalFilter(filters)) {\n return handleLogicalFilter(introspection, type, filters);\n }\n\n if (!isOperatorSupported(filters.operator)) {\n throw new Error(`Unsopported operator ${filters.operator}`);\n }\n\n const fieldDef = introspection.find(f => f.name === filters.field);\n if (!fieldDef) {\n throw new Error(`Can't find field \"${filters.field}\" definition`);\n }\n\n if (!isOperatorAllowedForField(filters.operator, fieldDef)) {\n throw new Error(`Unsupported field type ${fieldDef.type.name}`);\n }\n\n switch (filters.operator) {\n case FieldFilterOperatorEnum.IsNull:\n return handleIsNullOperator(filters);\n case FieldFilterOperatorEnum.Between:\n return handleBetweenOperator(filters);\n case FieldFilterOperatorEnum.Eq:\n case FieldFilterOperatorEnum.Like:\n case FieldFilterOperatorEnum.In:\n case FieldFilterOperatorEnum.Gt:\n case FieldFilterOperatorEnum.Gte:\n case FieldFilterOperatorEnum.Lt:\n case FieldFilterOperatorEnum.Lte:\n return handleBinaryOperator(filters, fieldDef, type);\n\n default:\n throw new Error(`Can't build filter condition`);\n }\n}\n\nfunction isOperatorSupported(operator: FieldFilterOperatorEnum): boolean {\n return (\n operator === FieldFilterOperatorEnum.Eq ||\n operator === FieldFilterOperatorEnum.Like ||\n operator === FieldFilterOperatorEnum.In ||\n operator === FieldFilterOperatorEnum.IsNull ||\n operator === FieldFilterOperatorEnum.Gt ||\n operator === FieldFilterOperatorEnum.Gte ||\n operator === FieldFilterOperatorEnum.Lt ||\n operator === FieldFilterOperatorEnum.Lte ||\n operator === FieldFilterOperatorEnum.Between\n );\n}\n\nfunction isFieldFilterSupported(fieldDef: IntrospectionField): boolean {\n return fieldDef?.type.name === TypeName.String;\n}\n\nfunction isOperatorAllowedForField(\n operator: FieldFilterOperatorEnum,\n fieldDef: IntrospectionField,\n): boolean {\n const allowedOperators: Record<TypeName, FieldFilterOperatorEnum[]> = {\n [TypeName.String]: [\n FieldFilterOperatorEnum.In,\n FieldFilterOperatorEnum.Like,\n FieldFilterOperatorEnum.IsNull,\n FieldFilterOperatorEnum.Eq,\n ],\n [TypeName.Id]: [\n FieldFilterOperatorEnum.In,\n FieldFilterOperatorEnum.IsNull,\n FieldFilterOperatorEnum.Eq,\n ],\n [TypeName.Date]: [\n FieldFilterOperatorEnum.IsNull,\n FieldFilterOperatorEnum.Eq,\n FieldFilterOperatorEnum.Gt,\n FieldFilterOperatorEnum.Gte,\n FieldFilterOperatorEnum.Lt,\n FieldFilterOperatorEnum.Lte,\n FieldFilterOperatorEnum.Between,\n ],\n [TypeName.StringArray]: [],\n };\n const allowedForType = allowedOperators[fieldDef.type.name];\n return allowedForType ? allowedForType.includes(operator) : false;\n}\n\nfunction convertToBoolean(value: any): boolean {\n if (typeof value === 'boolean') {\n return value;\n }\n if (typeof value === 'string') {\n return value.toLowerCase() === 'true';\n }\n if (typeof value === 'number') {\n return value === 1;\n }\n return false; // Default to false for unsupported types\n}\n\nfunction formatValue(\n fieldName: string,\n fieldValue: any,\n fieldDef: IntrospectionField,\n type: ProcessType,\n): string {\n if (!isFieldFilterSupported) {\n throw new Error(`Unsupported field type ${fieldDef.type.name}`);\n }\n\n if (isEnumFilter(fieldName, type)) {\n return `${fieldValue}`;\n }\n if (\n fieldDef.type.name === TypeName.String ||\n fieldDef.type.name === TypeName.Id ||\n fieldDef.type.name === TypeName.Date\n ) {\n return `\"${fieldValue}\"`;\n }\n throw new Error(\n `Failed to format value for ${fieldName} ${fieldValue} with type ${fieldDef.type.name}`,\n );\n}\n\nfunction getGraphQLOperator(operator: FieldFilterOperatorEnum): string {\n switch (operator) {\n case 'EQ':\n return 'equal';\n case 'LIKE':\n return 'like';\n case 'IN':\n return 'in';\n case 'IS_NULL':\n return 'isNull';\n case 'GT':\n return 'greaterThan';\n case 'GTE':\n return 'greaterThanEqual';\n case 'LT':\n return 'lessThan';\n case 'LTE':\n return 'lessThanEqual';\n // case 'CONTAINS':\n // return \"contains\"\n // case 'CONTAINS_ALL':\n // case 'CONTAINS_ANY':\n case 'BETWEEN':\n return 'between';\n default:\n throw new Error(`Operation \"${operator}\" not supported`);\n }\n}\n"],"names":["FieldFilterOperatorEnum","ProcessInstanceStatusDTO","getProcessInstanceStateFromStatusDTOString","TypeName"],"mappings":";;;;;AA6BA,SAAS,gBAAgB,MAAyC,EAAA;AAChE,EAAA,OAAQ,OAAyB,OAAY,KAAA,KAAA,CAAA,CAAA;AAC/C,CAAA;AAEA,SAAS,mBAAA,CACP,aACA,EAAA,IAAA,EACA,MACQ,EAAA;AACR,EAAI,IAAA,CAAC,MAAO,CAAA,QAAA,EAAiB,OAAA,EAAA,CAAA;AAE7B,EAAM,MAAA,UAAA,GAAa,OAAO,OAAQ,CAAA,GAAA;AAAA,IAAI,CACpC,CAAA,KAAA,oBAAA,CAAqB,aAAe,EAAA,IAAA,EAAM,CAAC,CAAA;AAAA,GAC7C,CAAA;AAEA,EAAO,OAAA,CAAA,EAAG,OAAO,QAAS,CAAA,WAAA,EAAa,CAAM,GAAA,EAAA,UAAA,CAAW,IAAK,CAAA,IAAI,CAAC,CAAA,CAAA,CAAA,CAAA;AACpE,CAAA;AAEA,SAAS,sBAAsB,MAA6B,EAAA;AAC1D,EAAI,IAAA,CAAC,MAAM,OAAQ,CAAA,MAAA,CAAO,KAAK,CAAK,IAAA,MAAA,CAAO,KAAM,CAAA,MAAA,KAAW,CAAG,EAAA;AAC7D,IAAM,MAAA,IAAI,MAAM,oDAAoD,CAAA,CAAA;AAAA,GACtE;AACA,EAAO,OAAA,CAAA,EAAG,MAAO,CAAA,KAAK,CAAM,GAAA,EAAA,kBAAA;AAAA,IAC1BA,yDAAwB,CAAA,OAAA;AAAA,GACzB,CAAa,UAAA,EAAA,MAAA,CAAO,KAAM,CAAA,CAAC,CAAC,CAAW,QAAA,EAAA,MAAA,CAAO,KAAM,CAAA,CAAC,CAAC,CAAA,GAAA,CAAA,CAAA;AACzD,CAAA;AAEA,SAAS,qBAAqB,MAA6B,EAAA;AACzD,EAAO,OAAA,CAAA,EAAG,MAAO,CAAA,KAAK,CAAM,GA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,CAAA;AAAA,GACvB;AACA,EAAA,MAAM,IAAI,KAAA;AAAA,IACR,8BAA8B,SAAS,CAAA,CAAA,EAAI,UAAU,CAAc,WAAA,EAAA,QAAA,CAAS,KAAK,IAAI,CAAA,CAAA;AAAA,GACvF,CAAA;AACF,CAAA;AAEA,SAAS,mBAAmB,QAA2C,EAAA;AACrE,EAAA,QAAQ,QAAU;AAAA,IAChB,KAAK,IAAA;AACH,MAAO,OAAA,OAAA,CAAA;AAAA,IACT,KAAK,MAAA;AACH,MAAO,OAAA,MAAA,CAAA;AAAA,IACT,KAAK,IAAA;AACH,MAAO,OAAA,IAAA,CAAA;AAAA,IACT,KAAK,SAAA;AACH,MAAO,OAAA,QAAA,CAAA;AAAA,IACT,KAAK,IAAA;AACH,MAAO,OAAA,aAAA,CAAA;AAAA,IACT,KAAK,KAAA;AACH,MAAO,OAAA,kBAAA,CAAA;AAAA,IACT,KAAK,IAAA;AACH,MAAO,OAAA,UAAA,CAAA;AAAA,IACT,KAAK,KAAA;AACH,MAAO,OAAA,eAAA,CAAA;AAAA;AAAA;AAAA;AAAA;AAAA,IAKT,KAAK,SAAA;AACH,MAAO,OAAA,SAAA,CAAA;AAAA,IACT;AACE,MAAA,MAAM,IAAI,KAAA,CAAM,CAAc,WAAA,EAAA,QAAQ,CAAiB,eAAA,CAAA,CAAA,CAAA;AAAA,GAC3D;AACF;;;;"}
1
+ {"version":3,"file":"filterBuilder.cjs.js","sources":["../../src/helpers/filterBuilder.ts"],"sourcesContent":["/*\n * Copyright Red Hat, Inc.\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport {\n FieldFilter,\n FieldFilterOperatorEnum,\n Filter,\n IntrospectionField,\n LogicalFilter,\n TypeName,\n} from '@red-hat-developer-hub/backstage-plugin-orchestrator-common';\n\ntype ProcessType = 'ProcessDefinition' | 'ProcessInstance';\n\nconst supportedOperators = [\n FieldFilterOperatorEnum.Eq,\n FieldFilterOperatorEnum.Like,\n FieldFilterOperatorEnum.In,\n FieldFilterOperatorEnum.IsNull,\n FieldFilterOperatorEnum.Gt,\n FieldFilterOperatorEnum.Gte,\n FieldFilterOperatorEnum.Lt,\n FieldFilterOperatorEnum.Lte,\n FieldFilterOperatorEnum.Between,\n];\n\nconst supportedOperatorsByType: Record<TypeName, FieldFilterOperatorEnum[]> = {\n [TypeName.String]: [\n FieldFilterOperatorEnum.In,\n FieldFilterOperatorEnum.Like,\n FieldFilterOperatorEnum.IsNull,\n FieldFilterOperatorEnum.Eq,\n ],\n [TypeName.Id]: [\n FieldFilterOperatorEnum.In,\n FieldFilterOperatorEnum.IsNull,\n FieldFilterOperatorEnum.Eq,\n ],\n [TypeName.Date]: [\n FieldFilterOperatorEnum.IsNull,\n FieldFilterOperatorEnum.Eq,\n FieldFilterOperatorEnum.Gt,\n FieldFilterOperatorEnum.Gte,\n FieldFilterOperatorEnum.Lt,\n FieldFilterOperatorEnum.Lte,\n FieldFilterOperatorEnum.Between,\n ],\n};\n\nfunction isLogicalFilter(filter: Filter): filter is LogicalFilter {\n return (filter as LogicalFilter).filters !== undefined;\n}\n\nfunction handleLogicalFilter(\n introspection: IntrospectionField[],\n type: ProcessType,\n filter: LogicalFilter,\n): string {\n if (!filter.operator) return '';\n\n const subClauses = filter.filters.map(f =>\n buildFilterCondition(introspection, type, f),\n );\n\n return `${filter.operator.toLowerCase()}: {${subClauses.join(', ')}}`;\n}\n\nfunction handleBetweenOperator(filter: FieldFilter): string {\n if (!Array.isArray(filter.value) || filter.value.length !== 2) {\n throw new Error('Between operator requires an array of two elements');\n }\n return `${filter.field}: {${getGraphQLOperator(\n FieldFilterOperatorEnum.Between,\n )}: {from: \"${filter.value[0]}\", to: \"${filter.value[1]}\"}}`;\n}\n\nfunction handleIsNullOperator(filter: FieldFilter): string {\n return `${filter.field}: {${getGraphQLOperator(\n FieldFilterOperatorEnum.IsNull,\n )}: ${convertToBoolean(filter.value)}}`;\n}\n\nfunction isEnumFilter(\n fieldName: string,\n type: 'ProcessDefinition' | 'ProcessInstance',\n): boolean {\n if (type === 'ProcessInstance') {\n if (fieldName === 'state') {\n return true;\n }\n }\n return false;\n}\n\nfunction isValidEnumOperator(operator: FieldFilterOperatorEnum): boolean {\n return (\n operator === FieldFilterOperatorEnum.In ||\n operator === FieldFilterOperatorEnum.Eq\n );\n}\n\nfunction handleBinaryOperator(\n binaryFilter: FieldFilter,\n fieldDef: IntrospectionField,\n type: 'ProcessDefinition' | 'ProcessInstance',\n): string {\n if (isEnumFilter(binaryFilter.field, type)) {\n if (!isValidEnumOperator(binaryFilter.operator)) {\n throw new Error(\n `Invalid operator ${binaryFilter.operator} for enum field ${binaryFilter.field} filter`,\n );\n }\n }\n const formattedValue = Array.isArray(binaryFilter.value)\n ? `[${binaryFilter.value\n .map(v => formatValue(binaryFilter.field, v, fieldDef, type))\n .join(', ')}]`\n : formatValue(binaryFilter.field, binaryFilter.value, fieldDef, type);\n return `${binaryFilter.field}: {${getGraphQLOperator(\n binaryFilter.operator,\n )}: ${formattedValue}}`;\n}\n\nexport function buildFilterCondition(\n introspection: IntrospectionField[],\n type: ProcessType,\n filters?: Filter,\n): string {\n if (!filters) {\n return '';\n }\n\n if (isLogicalFilter(filters)) {\n return handleLogicalFilter(introspection, type, filters);\n }\n\n if (!isOperatorSupported(filters.operator)) {\n throw new Error(\n `Unsupported operator ${filters.operator}. Supported operators are: ${supportedOperators.join(', ')}`,\n );\n }\n\n const fieldDef = introspection.find(f => f.name === filters.field);\n if (!fieldDef) {\n throw new Error(`Can't find field \"${filters.field}\" definition`);\n }\n\n if (!isOperatorAllowedForField(filters.operator, fieldDef, type)) {\n const allowedOperators = supportedOperatorsByType[fieldDef.type.name] || [];\n throw new Error(\n `Unsupported operator ${filters.operator} for field \"${fieldDef.name}\" of type \"${fieldDef.type.name}\". Allowed operators are: ${allowedOperators.join(', ')}`,\n );\n }\n\n switch (filters.operator) {\n case FieldFilterOperatorEnum.IsNull:\n return handleIsNullOperator(filters);\n case FieldFilterOperatorEnum.Between:\n return handleBetweenOperator(filters);\n case FieldFilterOperatorEnum.Eq:\n case FieldFilterOperatorEnum.Like:\n case FieldFilterOperatorEnum.In:\n case FieldFilterOperatorEnum.Gt:\n case FieldFilterOperatorEnum.Gte:\n case FieldFilterOperatorEnum.Lt:\n case FieldFilterOperatorEnum.Lte:\n return handleBinaryOperator(filters, fieldDef, type);\n\n default:\n throw new Error(`Can't build filter condition`);\n }\n}\n\nfunction isOperatorSupported(operator: FieldFilterOperatorEnum): boolean {\n return supportedOperators.includes(operator);\n}\n\nfunction isFieldFilterSupported(fieldDef: IntrospectionField): boolean {\n return fieldDef?.type.name === TypeName.String;\n}\n\nexport function isOperatorAllowedForField(\n operator: FieldFilterOperatorEnum,\n fieldDef: IntrospectionField,\n type: ProcessType,\n): boolean {\n if (isEnumFilter(fieldDef.name, type) && isValidEnumOperator(operator)) {\n return true;\n }\n\n const allowedForType = supportedOperatorsByType[fieldDef.type.name];\n return allowedForType ? allowedForType.includes(operator) : false;\n}\n\nfunction convertToBoolean(value: any): boolean {\n if (typeof value === 'boolean') {\n return value;\n }\n if (typeof value === 'string') {\n return value.toLowerCase() === 'true';\n }\n if (typeof value === 'number') {\n return value === 1;\n }\n return false; // Default to false for unsupported types\n}\n\nfunction formatValue(\n fieldName: string,\n fieldValue: any,\n fieldDef: IntrospectionField,\n type: ProcessType,\n): string {\n if (!isFieldFilterSupported) {\n throw new Error(`Unsupported field type ${fieldDef.type.name}`);\n }\n\n if (isEnumFilter(fieldName, type)) {\n return `${fieldValue}`;\n }\n if (\n fieldDef.type.name === TypeName.String ||\n fieldDef.type.name === TypeName.Id ||\n fieldDef.type.name === TypeName.Date\n ) {\n return `\"${fieldValue}\"`;\n }\n throw new Error(\n `Failed to format value for ${fieldName} ${fieldValue} with type ${fieldDef.type.name}`,\n );\n}\n\nfunction getGraphQLOperator(operator: FieldFilterOperatorEnum): string {\n switch (operator) {\n case 'EQ':\n return 'equal';\n case 'LIKE':\n return 'like';\n case 'IN':\n return 'in';\n case 'IS_NULL':\n return 'isNull';\n case 'GT':\n return 'greaterThan';\n case 'GTE':\n return 'greaterThanEqual';\n case 'LT':\n return 'lessThan';\n case 'LTE':\n return 'lessThanEqual';\n case 'BETWEEN':\n return 'between';\n default:\n throw new Error(`Operation \"${operator}\" not supported`);\n }\n}\n"],"names":["FieldFilterOperatorEnum","TypeName"],"mappings":";;;;AA2BA,MAAM,kBAAqB,GAAA;AAAA,EACzBA,yDAAwB,CAAA,EAAA;AAAA,EACxBA,yDAAwB,CAAA,IAAA;AAAA,EACxBA,yDAAwB,CAAA,EAAA;AAAA,EACxBA,yDAAwB,CAAA,MAAA;AAAA,EACxBA,yDAAwB,CAAA,EAAA;AAAA,EACxBA,yDAAwB,CAAA,GAAA;AAAA,EACxBA,yDAAwB,CAAA,EAAA;AAAA,EACxBA,yDAAwB,CAAA,GAAA;AAAA,EACxBA,yDAAwB,CAAA,OAAA;AAC1B,CAAA,CAAA;AAEA,MAAM,wBAAwE,GAAA;AAAA,EAC5E,CAACC,0CAAS,CAAA,MAAM,GAAG;AAAA,IACjBD,yDAAwB,CAAA,EAAA;AAAA,IACxBA,yDAAwB,CAAA,IAAA;AAAA,IACxBA,yDAAwB,CAAA,MAAA;AAAA,IACxBA,yDAAwB,CAAA,EAAA;AAAA,GAC1B;AAAA,EACA,CAACC,0CAAS,CAAA,EAAE,GAAG;AAAA,IACbD,yDAAwB,CAAA,EAAA;AAAA,IACxBA,yDAAwB,CAAA,MAAA;AAAA,IACxBA,yDAAwB,CAAA,EAAA;AAAA,GAC1B;AAAA,EACA,CAACC,0CAAS,CAAA,IAAI,GAAG;AAAA,IACfD,yD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AA,KAASA,2CAAS,IAChC,EAAA;AACA,IAAA,OAAO,IAAI,UAAU,CAAA,CAAA,CAAA,CAAA;AAAA,GACvB;AACA,EAAA,MAAM,IAAI,KAAA;AAAA,IACR,8BAA8B,SAAS,CAAA,CAAA,EAAI,UAAU,CAAc,WAAA,EAAA,QAAA,CAAS,KAAK,IAAI,CAAA,CAAA;AAAA,GACvF,CAAA;AACF,CAAA;AAEA,SAAS,mBAAmB,QAA2C,EAAA;AACrE,EAAA,QAAQ,QAAU;AAAA,IAChB,KAAK,IAAA;AACH,MAAO,OAAA,OAAA,CAAA;AAAA,IACT,KAAK,MAAA;AACH,MAAO,OAAA,MAAA,CAAA;AAAA,IACT,KAAK,IAAA;AACH,MAAO,OAAA,IAAA,CAAA;AAAA,IACT,KAAK,SAAA;AACH,MAAO,OAAA,QAAA,CAAA;AAAA,IACT,KAAK,IAAA;AACH,MAAO,OAAA,aAAA,CAAA;AAAA,IACT,KAAK,KAAA;AACH,MAAO,OAAA,kBAAA,CAAA;AAAA,IACT,KAAK,IAAA;AACH,MAAO,OAAA,UAAA,CAAA;AAAA,IACT,KAAK,KAAA;AACH,MAAO,OAAA,eAAA,CAAA;AAAA,IACT,KAAK,SAAA;AACH,MAAO,OAAA,SAAA,CAAA;AAAA,IACT;AACE,MAAA,MAAM,IAAI,KAAA,CAAM,CAAc,WAAA,EAAA,QAAQ,CAAiB,eAAA,CAAA,CAAA,CAAA;AAAA,GAC3D;AACF;;;;;"}
@@ -62,10 +62,10 @@ class DataIndexService {
62
62
  async inspectInputArgument(type) {
63
63
  const result = await this.client.query(this.graphQLArgumentQuery(type), {});
64
64
  this.logger.debug(`Introspection query result: ${JSON.stringify(result)}`);
65
- if (result?.error) {
66
- this.logger.error(`Error executing introspection query ${result.error}`);
67
- throw result.error;
68
- }
65
+ this.handleGraphqlClientError(
66
+ "Error executing introspection query",
67
+ result
68
+ );
69
69
  const pairs = [];
70
70
  if (result?.data?.__type?.inputFields) {
71
71
  for (const field of result.data.__type.inputFields) {
@@ -83,37 +83,13 @@ class DataIndexService {
83
83
  }
84
84
  return pairs;
85
85
  }
86
- async abortWorkflowInstance(instanceId) {
87
- this.logger.info(`Aborting workflow instance ${instanceId}`);
88
- const ProcessInstanceAbortMutationDocument = core.gql`
89
- mutation ProcessInstanceAbortMutation($id: String) {
90
- ProcessInstanceAbort(id: $id)
91
- }
92
- `;
93
- const result = await this.client.mutation(
94
- ProcessInstanceAbortMutationDocument,
95
- { id: instanceId }
96
- );
97
- this.logger.debug(
98
- `Abort workflow instance result: ${JSON.stringify(result)}`
99
- );
100
- if (result.error) {
101
- throw new Error(
102
- `Error aborting workflow instance ${instanceId}: ${result.error}`
103
- );
104
- }
105
- this.logger.debug(`Successfully aborted workflow instance ${instanceId}`);
106
- }
107
86
  async fetchWorkflowInfo(definitionId) {
108
87
  const graphQlQuery = `{ ProcessDefinitions ( where: {id: {equal: "${definitionId}" } } ) { id, name, version, type, endpoint, serviceUrl, source } }`;
109
88
  const result = await this.client.query(graphQlQuery, {});
110
89
  this.logger.debug(
111
90
  `Get workflow definition result: ${JSON.stringify(result)}`
112
91
  );
113
- if (result.error) {
114
- this.logger.error(`Error fetching workflow definition ${result.error}`);
115
- throw result.error;
116
- }
92
+ this.handleGraphqlClientError("Error fetching workflow definition", result);
117
93
  const processDefinitions = result.data.ProcessDefinitions;
118
94
  if (processDefinitions.length === 0) {
119
95
  this.logger.info(`No workflow definition found for ${definitionId}`);
@@ -127,10 +103,10 @@ class DataIndexService {
127
103
  this.logger.debug(
128
104
  `Get workflow service urls result: ${JSON.stringify(result)}`
129
105
  );
130
- if (result.error) {
131
- this.logger.error(`Error fetching workflow service urls ${result.error}`);
132
- throw result.error;
133
- }
106
+ this.handleGraphqlClientError(
107
+ "Error fetching workflow service urls",
108
+ result
109
+ );
134
110
  const processDefinitions = result.data.ProcessDefinitions;
135
111
  return processDefinitions.filter((definition) => definition.serviceUrl).map((definition) => ({ [definition.id]: definition.serviceUrl })).reduce((acc, curr) => ({ ...acc, ...curr }), {});
136
112
  }
@@ -162,12 +138,10 @@ class DataIndexService {
162
138
  this.logger.debug(
163
139
  `Get workflow definitions result: ${JSON.stringify(result)}`
164
140
  );
165
- if (result.error) {
166
- this.logger.error(
167
- `Error fetching data index swf results ${result.error}`
168
- );
169
- throw result.error;
170
- }
141
+ this.handleGraphqlClientError(
142
+ "Error fetching data index swf results",
143
+ result
144
+ );
171
145
  return result.data.ProcessDefinitions;
172
146
  }
173
147
  async fetchInstances(args) {
@@ -210,7 +184,8 @@ class DataIndexService {
210
184
  this.logger.debug(
211
185
  `Fetch process instances result: ${JSON.stringify(result)}`
212
186
  );
213
- const processInstancesSrc = result.data.ProcessInstances;
187
+ this.handleGraphqlClientError("Error when fetching instances", result);
188
+ const processInstancesSrc = result.data ? result.data.ProcessInstances : [];
214
189
  const processInstances = await Promise.all(
215
190
  processInstancesSrc.map(async (instance) => {
216
191
  return await this.getWorkflowDefinitionFromInstance(instance);
@@ -218,36 +193,6 @@ class DataIndexService {
218
193
  );
219
194
  return processInstances;
220
195
  }
221
- async fetchInstancesTotalCount(definitionIds, filter) {
222
- const definitionIdsCondition = definitionIds ? `processId: {in: ${JSON.stringify(definitionIds)}}` : void 0;
223
- this.initInputProcessDefinitionArgs();
224
- const filterCondition = filter ? filterBuilder.buildFilterCondition(
225
- await this.inspectInputArgument("ProcessInstance"),
226
- "ProcessInstance",
227
- filter
228
- ) : "";
229
- let whereClause;
230
- if (definitionIds && filter) {
231
- whereClause = `and: [{${definitionIdsCondition}}, {${filterCondition}}]`;
232
- } else if (definitionIdsCondition || filterCondition) {
233
- whereClause = definitionIdsCondition ?? filterCondition;
234
- }
235
- const graphQlQuery = queryBuilder.buildGraphQlQuery({
236
- type: "ProcessInstances",
237
- queryBody: "id",
238
- whereClause
239
- });
240
- this.logger.debug(`GraphQL query: ${graphQlQuery}`);
241
- const result = await this.client.query(graphQlQuery, {});
242
- if (result.error) {
243
- this.logger.error(
244
- `Error when fetching instances total count: ${result.error}`
245
- );
246
- throw result.error;
247
- }
248
- const idArr = result.data.ProcessInstances;
249
- return idArr.length;
250
- }
251
196
  async getWorkflowDefinitionFromInstance(instance) {
252
197
  const workflowInfo = await this.fetchWorkflowInfo(instance.processId);
253
198
  if (!workflowInfo?.source) {
@@ -270,10 +215,10 @@ class DataIndexService {
270
215
  this.logger.debug(
271
216
  `Fetch workflow source result: ${JSON.stringify(result)}`
272
217
  );
273
- if (result.error) {
274
- this.logger.error(`Error when fetching workflow source: ${result.error}`);
275
- return void 0;
276
- }
218
+ this.handleGraphqlClientError(
219
+ "Error when fetching workflow source",
220
+ result
221
+ );
277
222
  const processDefinitions = result.data.ProcessDefinitions;
278
223
  if (processDefinitions.length === 0) {
279
224
  this.logger.info(`No workflow source found for ${definitionId}`);
@@ -287,12 +232,10 @@ class DataIndexService {
287
232
  this.logger.debug(
288
233
  `Fetch workflow instances result: ${JSON.stringify(result)}`
289
234
  );
290
- if (result.error) {
291
- this.logger.error(
292
- `Error when fetching workflow instances: ${result.error}`
293
- );
294
- throw result.error;
295
- }
235
+ this.handleGraphqlClientError(
236
+ "Error when fetching workflow instances",
237
+ result
238
+ );
296
239
  return result.data.ProcessInstances;
297
240
  }
298
241
  async fetchInstanceVariables(instanceId) {
@@ -301,12 +244,10 @@ class DataIndexService {
301
244
  this.logger.debug(
302
245
  `Fetch process instance variables result: ${JSON.stringify(result)}`
303
246
  );
304
- if (result.error) {
305
- this.logger.error(
306
- `Error when fetching process instance variables: ${result.error}`
307
- );
308
- throw result.error;
309
- }
247
+ this.handleGraphqlClientError(
248
+ "Error when fetching process instance variables",
249
+ result
250
+ );
310
251
  const processInstances = result.data.ProcessInstances;
311
252
  if (processInstances.length === 0) {
312
253
  return void 0;
@@ -319,12 +260,10 @@ class DataIndexService {
319
260
  this.logger.debug(
320
261
  `Fetch process id from instance result: ${JSON.stringify(result)}`
321
262
  );
322
- if (result.error) {
323
- this.logger.error(
324
- `Error when fetching process id from instance: ${result.error}`
325
- );
326
- throw result.error;
327
- }
263
+ this.handleGraphqlClientError(
264
+ "Error when fetching process id from instance",
265
+ result
266
+ );
328
267
  const processInstances = result.data.ProcessInstances;
329
268
  if (processInstances.length === 0) {
330
269
  return void 0;
@@ -371,12 +310,10 @@ class DataIndexService {
371
310
  this.logger.debug(
372
311
  `Fetch process instance result: ${JSON.stringify(result)}`
373
312
  );
374
- if (result.error) {
375
- this.logger.error(
376
- `Error when fetching process instances: ${result.error}`
377
- );
378
- throw result.error;
379
- }
313
+ this.handleGraphqlClientError(
314
+ "Error when fetching process instances",
315
+ result
316
+ );
380
317
  const processInstances = result.data.ProcessInstances;
381
318
  if (processInstances.length === 0) {
382
319
  return void 0;
@@ -397,6 +334,20 @@ class DataIndexService {
397
334
  }
398
335
  return instance;
399
336
  }
337
+ handleGraphqlClientError(scenario, result) {
338
+ if (!result?.error) {
339
+ return;
340
+ }
341
+ this.logger.error(`${scenario} ${result}`);
342
+ const networkError = result.error.networkError?.cause?.message;
343
+ if (networkError) {
344
+ const toThrow = new Error(`${result.error.message}. ${networkError}`);
345
+ toThrow.name = "Network Error";
346
+ throw toThrow;
347
+ } else {
348
+ throw result.error;
349
+ }
350
+ }
400
351
  }
401
352
 
402
353
  exports.DataIndexService = DataIndexService;
@@ -1 +1 @@
1
- {"version":3,"file":"DataIndexService.cjs.js","sources":["../../src/service/DataIndexService.ts"],"sourcesContent":["/*\n * Copyright 2024 The Backstage Authors\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\nimport { LoggerService } from '@backstage/backend-plugin-api';\n\nimport { Client, fetchExchange, gql } from '@urql/core';\n\nimport {\n Filter,\n fromWorkflowSource,\n getWorkflowCategory,\n IntrospectionField,\n parseWorkflowVariables,\n ProcessInstance,\n WorkflowDefinition,\n WorkflowInfo,\n} from '@red-hat-developer-hub/backstage-plugin-orchestrator-common';\n\nimport { ErrorBuilder } from '../helpers/errorBuilder';\nimport { buildFilterCondition } from '../helpers/filterBuilder';\nimport { buildGraphQlQuery } from '../helpers/queryBuilder';\nimport { Pagination } from '../types/pagination';\nimport { FETCH_PROCESS_INSTANCES_SORT_FIELD } from './constants';\n\nexport class DataIndexService {\n private readonly client: Client;\n public processDefinitionArguments: IntrospectionField[] = [];\n public processInstanceArguments: IntrospectionField[] = [];\n\n public constructor(\n private readonly dataIndexUrl: string,\n private readonly logger: LoggerService,\n ) {\n if (!dataIndexUrl.length) {\n throw ErrorBuilder.GET_NO_DATA_INDEX_URL_ERR();\n }\n\n this.client = this.getNewGraphQLClient();\n }\n\n private getNewGraphQLClient(): Client {\n const diURL = `${this.dataIndexUrl}/graphql`;\n return new Client({\n url: diURL,\n exchanges: [fetchExchange],\n });\n }\n\n public async initInputProcessDefinitionArgs(): Promise<IntrospectionField[]> {\n if (this.processDefinitionArguments.length === 0) {\n this.processDefinitionArguments =\n await this.inspectInputArgument('ProcessDefinition');\n }\n return this.processDefinitionArguments; // For testing purposes\n }\n\n public graphQLArgumentQuery(type: string): string {\n return `query ${type}Argument {\n __type(name: \"${type}Argument\") {\n kind\n name\n inputFields {\n name\n type {\n kind\n name\n ofType {\n kind\n name\n ofType {\n kind\n name\n ofType {\n kind\n name\n }\n }\n }\n }\n }\n }\n }`;\n }\n\n public async inspectInputArgument(\n type: string,\n ): Promise<IntrospectionField[]> {\n const result = await this.client.query(this.graphQLArgumentQuery(type), {});\n\n this.logger.debug(`Introspection query result: ${JSON.stringify(result)}`);\n\n if (result?.error) {\n this.logger.error(`Error executing introspection query ${result.error}`);\n throw result.error;\n }\n\n const pairs: IntrospectionField[] = [];\n if (result?.data?.__type?.inputFields) {\n for (const field of result.data.__type.inputFields) {\n if (\n field.name !== 'and' &&\n field.name !== 'or' &&\n field.name !== 'not'\n ) {\n pairs.push({\n name: field.name,\n type: {\n name: field.type.name,\n kind: field.type.kind,\n ofType: field.type.ofType,\n },\n });\n }\n }\n }\n return pairs;\n }\n\n public async abortWorkflowInstance(instanceId: string): Promise<void> {\n this.logger.info(`Aborting workflow instance ${instanceId}`);\n const ProcessInstanceAbortMutationDocument = gql`\n mutation ProcessInstanceAbortMutation($id: String) {\n ProcessInstanceAbort(id: $id)\n }\n `;\n\n const result = await this.client.mutation(\n ProcessInstanceAbortMutationDocument,\n { id: instanceId },\n );\n\n this.logger.debug(\n `Abort workflow instance result: ${JSON.stringify(result)}`,\n );\n\n if (result.error) {\n throw new Error(\n `Error aborting workflow instance ${instanceId}: ${result.error}`,\n );\n }\n this.logger.debug(`Successfully aborted workflow instance ${instanceId}`);\n }\n\n public async fetchWorkflowInfo(\n definitionId: string,\n ): Promise<WorkflowInfo | undefined> {\n const graphQlQuery = `{ ProcessDefinitions ( where: {id: {equal: \"${definitionId}\" } } ) { id, name, version, type, endpoint, serviceUrl, source } }`;\n\n const result = await this.client.query(graphQlQuery, {});\n\n this.logger.debug(\n `Get workflow definition result: ${JSON.stringify(result)}`,\n );\n\n if (result.error) {\n this.logger.error(`Error fetching workflow definition ${result.error}`);\n throw result.error;\n }\n\n const processDefinitions = result.data.ProcessDefinitions as WorkflowInfo[];\n\n if (processDefinitions.length === 0) {\n this.logger.info(`No workflow definition found for ${definitionId}`);\n return undefined;\n }\n\n return processDefinitions[0];\n }\n\n public async fetchWorkflowServiceUrls(): Promise<Record<string, string>> {\n const graphQlQuery = `{ ProcessDefinitions { id, serviceUrl } }`;\n\n const result = await this.client.query(graphQlQuery, {});\n\n this.logger.debug(\n `Get workflow service urls result: ${JSON.stringify(result)}`,\n );\n\n if (result.error) {\n this.logger.error(`Error fetching workflow service urls ${result.error}`);\n throw result.error;\n }\n\n const processDefinitions = result.data.ProcessDefinitions as WorkflowInfo[];\n return processDefinitions\n .filter(definition => definition.serviceUrl)\n .map(definition => ({ [definition.id]: definition.serviceUrl! }))\n .reduce((acc, curr) => ({ ...acc, ...curr }), {});\n }\n\n public async fetchWorkflowInfos(args: {\n definitionIds?: string[];\n pagination?: Pagination;\n filter?: Filter;\n }): Promise<WorkflowInfo[]> {\n this.logger.info(`fetchWorkflowInfos() called: ${this.dataIndexUrl}`);\n const { definitionIds, pagination, filter } = args;\n\n const definitionIdsCondition =\n definitionIds !== undefined && definitionIds.length > 0\n ? `id: {in: ${JSON.stringify(definitionIds)}}`\n : undefined;\n\n const filterCondition = filter\n ? buildFilterCondition(\n await this.initInputProcessDefinitionArgs(),\n 'ProcessDefinition',\n filter,\n )\n : undefined;\n\n let whereClause: string | undefined;\n if (definitionIds && filter) {\n whereClause = `and: [{${definitionIdsCondition}}, {${filterCondition}}]`;\n } else if (definitionIdsCondition || filterCondition) {\n whereClause = definitionIdsCondition ?? filterCondition;\n } else {\n whereClause = undefined;\n }\n\n const graphQlQuery = buildGraphQlQuery({\n type: 'ProcessDefinitions',\n queryBody: 'id, name, version, type, endpoint, serviceUrl, source',\n whereClause,\n pagination,\n });\n this.logger.debug(`GraphQL query: ${graphQlQuery}`);\n const result = await this.client.query(graphQlQuery, {});\n this.logger.debug(\n `Get workflow definitions result: ${JSON.stringify(result)}`,\n );\n\n if (result.error) {\n this.logger.error(\n `Error fetching data index swf results ${result.error}`,\n );\n throw result.error;\n }\n\n return result.data.ProcessDefinitions;\n }\n\n public async fetchInstances(args: {\n definitionIds?: string[];\n pagination?: Pagination;\n filter?: Filter;\n }): Promise<ProcessInstance[]> {\n const { pagination, definitionIds, filter } = args;\n if (pagination) pagination.sortField ??= FETCH_PROCESS_INSTANCES_SORT_FIELD;\n\n const processIdNotNullCondition = 'processId: {isNull: false}';\n const definitionIdsCondition = definitionIds\n ? `processId: {in: ${JSON.stringify(definitionIds)}}`\n : undefined;\n const type = 'ProcessInstance';\n const filterCondition = filter\n ? buildFilterCondition(\n await this.inspectInputArgument(type),\n type,\n filter,\n )\n : '';\n\n let whereClause = '';\n const conditions = [];\n\n if (processIdNotNullCondition) {\n conditions.push(`{${processIdNotNullCondition}}`);\n }\n\n if (definitionIdsCondition) {\n conditions.push(`{${definitionIdsCondition}}`);\n }\n\n if (filter) {\n conditions.push(`{${filterCondition}}`);\n }\n\n if (conditions.length === 0) {\n whereClause = processIdNotNullCondition;\n } else if (conditions.length === 1) {\n whereClause = conditions[0].slice(1, -1); // Remove the outer braces\n } else if (conditions.length > 1) {\n whereClause = `and: [${conditions.join(', ')}]`;\n }\n\n const graphQlQuery = buildGraphQlQuery({\n type: 'ProcessInstances',\n queryBody:\n 'id, processName, processId, businessKey, state, start, end, nodes { id }, variables, parentProcessInstance {id, processName, businessKey}',\n whereClause,\n pagination,\n });\n\n this.logger.debug(`GraphQL query: ${graphQlQuery}`);\n\n const result = await this.client.query(graphQlQuery, {});\n\n this.logger.debug(\n `Fetch process instances result: ${JSON.stringify(result)}`,\n );\n\n const processInstancesSrc = result.data\n .ProcessInstances as ProcessInstance[];\n\n const processInstances = await Promise.all(\n processInstancesSrc.map(async instance => {\n return await this.getWorkflowDefinitionFromInstance(instance);\n }),\n );\n return processInstances;\n }\n\n public async fetchInstancesTotalCount(\n definitionIds?: string[],\n filter?: Filter,\n ): Promise<number> {\n const definitionIdsCondition = definitionIds\n ? `processId: {in: ${JSON.stringify(definitionIds)}}`\n : undefined;\n this.initInputProcessDefinitionArgs();\n const filterCondition = filter\n ? buildFilterCondition(\n await this.inspectInputArgument('ProcessInstance'),\n 'ProcessInstance',\n filter,\n )\n : '';\n\n let whereClause: string | undefined;\n if (definitionIds && filter) {\n whereClause = `and: [{${definitionIdsCondition}}, {${filterCondition}}]`;\n } else if (definitionIdsCondition || filterCondition) {\n whereClause = definitionIdsCondition ?? filterCondition;\n }\n\n const graphQlQuery = buildGraphQlQuery({\n type: 'ProcessInstances',\n queryBody: 'id',\n whereClause,\n });\n this.logger.debug(`GraphQL query: ${graphQlQuery}`);\n\n const result = await this.client.query(graphQlQuery, {});\n\n if (result.error) {\n this.logger.error(\n `Error when fetching instances total count: ${result.error}`,\n );\n throw result.error;\n }\n\n const idArr = result.data.ProcessInstances as ProcessInstance[];\n\n return idArr.length;\n }\n\n private async getWorkflowDefinitionFromInstance(instance: ProcessInstance) {\n const workflowInfo = await this.fetchWorkflowInfo(instance.processId);\n if (!workflowInfo?.source) {\n throw new Error(\n `Workflow defintion is required to fetch instance ${instance.id}`,\n );\n }\n const workflowDefinitionSrc: WorkflowDefinition = fromWorkflowSource(\n workflowInfo.source,\n );\n if (workflowInfo) {\n instance.category = getWorkflowCategory(workflowDefinitionSrc);\n instance.description = workflowInfo.description;\n }\n return instance;\n }\n\n public async fetchWorkflowSource(\n definitionId: string,\n ): Promise<string | undefined> {\n const graphQlQuery = `{ ProcessDefinitions ( where: {id: {equal: \"${definitionId}\" } } ) { id, source } }`;\n\n const result = await this.client.query(graphQlQuery, {});\n\n this.logger.debug(\n `Fetch workflow source result: ${JSON.stringify(result)}`,\n );\n\n if (result.error) {\n this.logger.error(`Error when fetching workflow source: ${result.error}`);\n return undefined;\n }\n\n const processDefinitions = result.data.ProcessDefinitions as WorkflowInfo[];\n\n if (processDefinitions.length === 0) {\n this.logger.info(`No workflow source found for ${definitionId}`);\n return undefined;\n }\n\n return processDefinitions[0].source;\n }\n\n public async fetchInstancesByDefinitionId(args: {\n definitionId: string;\n limit: number;\n offset: number;\n }): Promise<ProcessInstance[]> {\n const graphQlQuery = `{ ProcessInstances(where: {processId: {equal: \"${args.definitionId}\" } }, orderBy: {start:DESC}, pagination: {limit: ${args.limit}, offset: ${args.offset}}) { id, processName, state, start, end } }`;\n\n const result = await this.client.query(graphQlQuery, {});\n\n this.logger.debug(\n `Fetch workflow instances result: ${JSON.stringify(result)}`,\n );\n\n if (result.error) {\n this.logger.error(\n `Error when fetching workflow instances: ${result.error}`,\n );\n throw result.error;\n }\n\n return result.data.ProcessInstances;\n }\n\n public async fetchInstanceVariables(\n instanceId: string,\n ): Promise<object | undefined> {\n const graphQlQuery = `{ ProcessInstances (where: { id: {equal: \"${instanceId}\" } } ) { variables } }`;\n\n const result = await this.client.query(graphQlQuery, {});\n\n this.logger.debug(\n `Fetch process instance variables result: ${JSON.stringify(result)}`,\n );\n\n if (result.error) {\n this.logger.error(\n `Error when fetching process instance variables: ${result.error}`,\n );\n throw result.error;\n }\n\n const processInstances = result.data.ProcessInstances as ProcessInstance[];\n\n if (processInstances.length === 0) {\n return undefined;\n }\n\n return parseWorkflowVariables(processInstances[0].variables as object);\n }\n\n public async fetchDefinitionIdByInstanceId(\n instanceId: string,\n ): Promise<string | undefined> {\n const graphQlQuery = `{ ProcessInstances (where: { id: {equal: \"${instanceId}\" } } ) { processId } }`;\n\n const result = await this.client.query(graphQlQuery, {});\n\n this.logger.debug(\n `Fetch process id from instance result: ${JSON.stringify(result)}`,\n );\n\n if (result.error) {\n this.logger.error(\n `Error when fetching process id from instance: ${result.error}`,\n );\n throw result.error;\n }\n\n const processInstances = result.data.ProcessInstances as ProcessInstance[];\n\n if (processInstances.length === 0) {\n return undefined;\n }\n\n return processInstances[0].processId;\n }\n\n public async fetchInstance(\n instanceId: string,\n ): Promise<ProcessInstance | undefined> {\n const FindProcessInstanceQuery = gql`\n query FindProcessInstanceQuery($instanceId: String!) {\n ProcessInstances(where: { id: { equal: $instanceId } }) {\n id\n processName\n processId\n serviceUrl\n businessKey\n state\n start\n end\n nodes {\n id\n nodeId\n definitionId\n type\n name\n enter\n exit\n }\n variables\n parentProcessInstance {\n id\n processName\n businessKey\n }\n error {\n nodeDefinitionId\n message\n }\n }\n }\n `;\n\n const result = await this.client.query(FindProcessInstanceQuery, {\n instanceId,\n });\n\n this.logger.debug(\n `Fetch process instance result: ${JSON.stringify(result)}`,\n );\n\n if (result.error) {\n this.logger.error(\n `Error when fetching process instances: ${result.error}`,\n );\n throw result.error;\n }\n\n const processInstances = result.data.ProcessInstances as ProcessInstance[];\n\n if (processInstances.length === 0) {\n return undefined;\n }\n\n const instance = processInstances[0];\n\n const workflowInfo = await this.fetchWorkflowInfo(instance.processId);\n if (!workflowInfo?.source) {\n throw new Error(\n `Workflow defintion is required to fetch instance ${instance.id}`,\n );\n }\n const workflowDefinitionSrc: WorkflowDefinition = fromWorkflowSource(\n workflowInfo.source,\n );\n if (workflowInfo) {\n instance.category = getWorkflowCategory(workflowDefinitionSrc);\n instance.description = workflowDefinitionSrc.description;\n }\n return instance;\n }\n}\n"],"names":["ErrorBuilder","Client","fetchExchange","gql","buildFilterCondition","buildGraphQlQuery","FETCH_PROCESS_INSTANCES_SORT_FIELD","fromWorkflowSource","getWorkflowCategory","parseWorkflowVariables"],"mappings":";;;;;;;;;AAoCO,MAAM,gBAAiB,CAAA;AAAA,EAKrB,WAAA,CACY,cACA,MACjB,EAAA;AAFiB,IAAA,IAAA,CAAA,YAAA,GAAA,YAAA,CAAA;AACA,IAAA,IAAA,CAAA,MAAA,GAAA,MAAA,CAAA;AAEjB,IAAI,IAAA,CAAC,aAAa,MAAQ,EAAA;AACxB,MAAA,MAAMA,0BAAa,yBAA0B,EAAA,CAAA;AAAA,KAC/C;AAEA,IAAK,IAAA,CAAA,MAAA,GAAS,KAAK,mBAAoB,EAAA,CAAA;AAAA,GACzC;AAAA,EAbiB,MAAA,CAAA;AAAA,EACV,6BAAmD,EAAC,CAAA;AAAA,EACpD,2BAAiD,EAAC,CAAA;AAAA,EAajD,mBAA8B,GAAA;AACpC,IAAM,MAAA,KAAA,GAAQ,CAAG,EAAA,IAAA,CAAK,YAAY,CAAA,QAAA,CAAA,CAAA;AAClC,IAAA,OAAO,IAAIC,WAAO,CAAA;AAAA,MAChB,GAAK,EAAA,KAAA;AAAA,MACL,SAAA,EAAW,CAACC,kBAAa,CAAA;AAAA,KAC1B,CAAA,CAAA;AAAA,GACH;AAAA,EAEA,MAAa,8BAAgE,GAAA;AAC3E,IAAI,IAAA,IAAA,CAAK,0BAA2B,CAAA,MAAA,KAAW,CAAG,EAAA;AAChD,MAAA,IAAA,CAAK,0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A,EAAA,IAAA,CAAK,SAAU,CAAA,MAAM,CAAC,CAAA,CAAA;AAAA,KAC1D,CAAA;AAEA,IAAA,IAAI,OAAO,KAAO,EAAA;AAChB,MAAA,IAAA,CAAK,MAAO,CAAA,KAAA;AAAA,QACV,CAAA,uCAAA,EAA0C,OAAO,KAAK,CAAA,CAAA;AAAA,OACxD,CAAA;AACA,MAAA,MAAM,MAAO,CAAA,KAAA,CAAA;AAAA,KACf;AAEA,IAAM,MAAA,gBAAA,GAAmB,OAAO,IAAK,CAAA,gBAAA,CAAA;AAErC,IAAI,IAAA,gBAAA,CAAiB,WAAW,CAAG,EAAA;AACjC,MAAO,OAAA,KAAA,CAAA,CAAA;AAAA,KACT;AAEA,IAAM,MAAA,QAAA,GAAW,iBAAiB,CAAC,CAAA,CAAA;AAEnC,IAAA,MAAM,YAAe,GAAA,MAAM,IAAK,CAAA,iBAAA,CAAkB,SAAS,SAAS,CAAA,CAAA;AACpE,IAAI,IAAA,CAAC,cAAc,MAAQ,EAAA;AACzB,MAAA,MAAM,IAAI,KAAA;AAAA,QACR,CAAA,iDAAA,EAAoD,SAAS,EAAE,CAAA,CAAA;AAAA,OACjE,CAAA;AAAA,KACF;AACA,IAAA,MAAM,qBAA4C,GAAAI,oDAAA;AAAA,MAChD,YAAa,CAAA,MAAA;AAAA,KACf,CAAA;AACA,IAAA,IAAI,YAAc,EAAA;AAChB,MAAS,QAAA,CAAA,QAAA,GAAWC,sDAAoB,qBAAqB,CAAA,CAAA;AAC7D,MAAA,QAAA,CAAS,cAAc,qBAAsB,CAAA,WAAA,CAAA;AAAA,KAC/C;AACA,IAAO,OAAA,QAAA,CAAA;AAAA,GACT;AACF;;;;"}
1
+ {"version":3,"file":"DataIndexService.cjs.js","sources":["../../src/service/DataIndexService.ts"],"sourcesContent":["/*\n * Copyright Red Hat, Inc.\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport { LoggerService } from '@backstage/backend-plugin-api';\n\nimport { Client, fetchExchange, gql } from '@urql/core';\n\nimport {\n Filter,\n fromWorkflowSource,\n getWorkflowCategory,\n IntrospectionField,\n parseWorkflowVariables,\n ProcessInstance,\n WorkflowDefinition,\n WorkflowInfo,\n} from '@red-hat-developer-hub/backstage-plugin-orchestrator-common';\n\nimport { ErrorBuilder } from '../helpers/errorBuilder';\nimport { buildFilterCondition } from '../helpers/filterBuilder';\nimport { buildGraphQlQuery } from '../helpers/queryBuilder';\nimport { Pagination } from '../types/pagination';\nimport { FETCH_PROCESS_INSTANCES_SORT_FIELD } from './constants';\n\nexport class DataIndexService {\n private readonly client: Client;\n public processDefinitionArguments: IntrospectionField[] = [];\n public processInstanceArguments: IntrospectionField[] = [];\n\n public constructor(\n private readonly dataIndexUrl: string,\n private readonly logger: LoggerService,\n ) {\n if (!dataIndexUrl.length) {\n throw ErrorBuilder.GET_NO_DATA_INDEX_URL_ERR();\n }\n\n this.client = this.getNewGraphQLClient();\n }\n\n private getNewGraphQLClient(): Client {\n const diURL = `${this.dataIndexUrl}/graphql`;\n return new Client({\n url: diURL,\n exchanges: [fetchExchange],\n });\n }\n\n public async initInputProcessDefinitionArgs(): Promise<IntrospectionField[]> {\n if (this.processDefinitionArguments.length === 0) {\n this.processDefinitionArguments =\n await this.inspectInputArgument('ProcessDefinition');\n }\n return this.processDefinitionArguments; // For testing purposes\n }\n\n public graphQLArgumentQuery(type: string): string {\n return `query ${type}Argument {\n __type(name: \"${type}Argument\") {\n kind\n name\n inputFields {\n name\n type {\n kind\n name\n ofType {\n kind\n name\n ofType {\n kind\n name\n ofType {\n kind\n name\n }\n }\n }\n }\n }\n }\n }`;\n }\n\n public async inspectInputArgument(\n type: string,\n ): Promise<IntrospectionField[]> {\n const result = await this.client.query(this.graphQLArgumentQuery(type), {});\n\n this.logger.debug(`Introspection query result: ${JSON.stringify(result)}`);\n\n this.handleGraphqlClientError(\n 'Error executing introspection query',\n result,\n );\n\n const pairs: IntrospectionField[] = [];\n if (result?.data?.__type?.inputFields) {\n for (const field of result.data.__type.inputFields) {\n if (\n field.name !== 'and' &&\n field.name !== 'or' &&\n field.name !== 'not'\n ) {\n pairs.push({\n name: field.name,\n type: {\n name: field.type.name,\n kind: field.type.kind,\n ofType: field.type.ofType,\n },\n });\n }\n }\n }\n return pairs;\n }\n\n public async fetchWorkflowInfo(\n definitionId: string,\n ): Promise<WorkflowInfo | undefined> {\n const graphQlQuery = `{ ProcessDefinitions ( where: {id: {equal: \"${definitionId}\" } } ) { id, name, version, type, endpoint, serviceUrl, source } }`;\n\n const result = await this.client.query(graphQlQuery, {});\n\n this.logger.debug(\n `Get workflow definition result: ${JSON.stringify(result)}`,\n );\n\n this.handleGraphqlClientError('Error fetching workflow definition', result);\n\n const processDefinitions = result.data.ProcessDefinitions as WorkflowInfo[];\n\n if (processDefinitions.length === 0) {\n this.logger.info(`No workflow definition found for ${definitionId}`);\n return undefined;\n }\n\n return processDefinitions[0];\n }\n\n public async fetchWorkflowServiceUrls(): Promise<Record<string, string>> {\n const graphQlQuery = `{ ProcessDefinitions { id, serviceUrl } }`;\n\n const result = await this.client.query(graphQlQuery, {});\n\n this.logger.debug(\n `Get workflow service urls result: ${JSON.stringify(result)}`,\n );\n\n this.handleGraphqlClientError(\n 'Error fetching workflow service urls',\n result,\n );\n\n const processDefinitions = result.data.ProcessDefinitions as WorkflowInfo[];\n return processDefinitions\n .filter(definition => definition.serviceUrl)\n .map(definition => ({ [definition.id]: definition.serviceUrl! }))\n .reduce((acc, curr) => ({ ...acc, ...curr }), {});\n }\n\n public async fetchWorkflowInfos(args: {\n definitionIds?: string[];\n pagination?: Pagination;\n filter?: Filter;\n }): Promise<WorkflowInfo[]> {\n this.logger.info(`fetchWorkflowInfos() called: ${this.dataIndexUrl}`);\n const { definitionIds, pagination, filter } = args;\n\n const definitionIdsCondition =\n definitionIds !== undefined && definitionIds.length > 0\n ? `id: {in: ${JSON.stringify(definitionIds)}}`\n : undefined;\n\n const filterCondition = filter\n ? buildFilterCondition(\n await this.initInputProcessDefinitionArgs(),\n 'ProcessDefinition',\n filter,\n )\n : undefined;\n\n let whereClause: string | undefined;\n if (definitionIds && filter) {\n whereClause = `and: [{${definitionIdsCondition}}, {${filterCondition}}]`;\n } else if (definitionIdsCondition || filterCondition) {\n whereClause = definitionIdsCondition ?? filterCondition;\n } else {\n whereClause = undefined;\n }\n\n const graphQlQuery = buildGraphQlQuery({\n type: 'ProcessDefinitions',\n queryBody: 'id, name, version, type, endpoint, serviceUrl, source',\n whereClause,\n pagination,\n });\n this.logger.debug(`GraphQL query: ${graphQlQuery}`);\n const result = await this.client.query(graphQlQuery, {});\n this.logger.debug(\n `Get workflow definitions result: ${JSON.stringify(result)}`,\n );\n\n this.handleGraphqlClientError(\n 'Error fetching data index swf results',\n result,\n );\n\n return result.data.ProcessDefinitions;\n }\n\n public async fetchInstances(args: {\n definitionIds?: string[];\n pagination?: Pagination;\n filter?: Filter;\n }): Promise<ProcessInstance[]> {\n const { pagination, definitionIds, filter } = args;\n if (pagination) pagination.sortField ??= FETCH_PROCESS_INSTANCES_SORT_FIELD;\n\n const processIdNotNullCondition = 'processId: {isNull: false}';\n const definitionIdsCondition = definitionIds\n ? `processId: {in: ${JSON.stringify(definitionIds)}}`\n : undefined;\n const type = 'ProcessInstance';\n const filterCondition = filter\n ? buildFilterCondition(\n await this.inspectInputArgument(type),\n type,\n filter,\n )\n : '';\n\n let whereClause = '';\n const conditions = [];\n\n if (processIdNotNullCondition) {\n conditions.push(`{${processIdNotNullCondition}}`);\n }\n\n if (definitionIdsCondition) {\n conditions.push(`{${definitionIdsCondition}}`);\n }\n\n if (filter) {\n conditions.push(`{${filterCondition}}`);\n }\n\n if (conditions.length === 0) {\n whereClause = processIdNotNullCondition;\n } else if (conditions.length === 1) {\n whereClause = conditions[0].slice(1, -1); // Remove the outer braces\n } else if (conditions.length > 1) {\n whereClause = `and: [${conditions.join(', ')}]`;\n }\n\n const graphQlQuery = buildGraphQlQuery({\n type: 'ProcessInstances',\n queryBody:\n 'id, processName, processId, businessKey, state, start, end, nodes { id }, variables, parentProcessInstance {id, processName, businessKey}',\n whereClause,\n pagination,\n });\n\n this.logger.debug(`GraphQL query: ${graphQlQuery}`);\n\n const result = await this.client.query<{\n ProcessInstances: ProcessInstance[];\n }>(graphQlQuery, {});\n this.logger.debug(\n `Fetch process instances result: ${JSON.stringify(result)}`,\n );\n\n this.handleGraphqlClientError('Error when fetching instances', result);\n\n const processInstancesSrc = result.data ? result.data.ProcessInstances : [];\n\n const processInstances = await Promise.all(\n processInstancesSrc.map(async instance => {\n return await this.getWorkflowDefinitionFromInstance(instance);\n }),\n );\n return processInstances;\n }\n\n private async getWorkflowDefinitionFromInstance(instance: ProcessInstance) {\n const workflowInfo = await this.fetchWorkflowInfo(instance.processId);\n if (!workflowInfo?.source) {\n throw new Error(\n `Workflow defintion is required to fetch instance ${instance.id}`,\n );\n }\n const workflowDefinitionSrc: WorkflowDefinition = fromWorkflowSource(\n workflowInfo.source,\n );\n if (workflowInfo) {\n instance.category = getWorkflowCategory(workflowDefinitionSrc);\n instance.description = workflowInfo.description;\n }\n return instance;\n }\n\n public async fetchWorkflowSource(\n definitionId: string,\n ): Promise<string | undefined> {\n const graphQlQuery = `{ ProcessDefinitions ( where: {id: {equal: \"${definitionId}\" } } ) { id, source } }`;\n\n const result = await this.client.query(graphQlQuery, {});\n\n this.logger.debug(\n `Fetch workflow source result: ${JSON.stringify(result)}`,\n );\n\n this.handleGraphqlClientError(\n 'Error when fetching workflow source',\n result,\n );\n\n const processDefinitions = result.data.ProcessDefinitions as WorkflowInfo[];\n\n if (processDefinitions.length === 0) {\n this.logger.info(`No workflow source found for ${definitionId}`);\n return undefined;\n }\n\n return processDefinitions[0].source;\n }\n\n public async fetchInstancesByDefinitionId(args: {\n definitionId: string;\n limit: number;\n offset: number;\n }): Promise<ProcessInstance[]> {\n const graphQlQuery = `{ ProcessInstances(where: {processId: {equal: \"${args.definitionId}\" } }, orderBy: {start:DESC}, pagination: {limit: ${args.limit}, offset: ${args.offset}}) { id, processName, state, start, end } }`;\n\n const result = await this.client.query(graphQlQuery, {});\n\n this.logger.debug(\n `Fetch workflow instances result: ${JSON.stringify(result)}`,\n );\n\n this.handleGraphqlClientError(\n 'Error when fetching workflow instances',\n result,\n );\n\n return result.data.ProcessInstances;\n }\n\n public async fetchInstanceVariables(\n instanceId: string,\n ): Promise<object | undefined> {\n const graphQlQuery = `{ ProcessInstances (where: { id: {equal: \"${instanceId}\" } } ) { variables } }`;\n\n const result = await this.client.query(graphQlQuery, {});\n\n this.logger.debug(\n `Fetch process instance variables result: ${JSON.stringify(result)}`,\n );\n\n this.handleGraphqlClientError(\n 'Error when fetching process instance variables',\n result,\n );\n\n const processInstances = result.data.ProcessInstances as ProcessInstance[];\n\n if (processInstances.length === 0) {\n return undefined;\n }\n\n return parseWorkflowVariables(processInstances[0].variables as object);\n }\n\n public async fetchDefinitionIdByInstanceId(\n instanceId: string,\n ): Promise<string | undefined> {\n const graphQlQuery = `{ ProcessInstances (where: { id: {equal: \"${instanceId}\" } } ) { processId } }`;\n\n const result = await this.client.query(graphQlQuery, {});\n\n this.logger.debug(\n `Fetch process id from instance result: ${JSON.stringify(result)}`,\n );\n\n this.handleGraphqlClientError(\n 'Error when fetching process id from instance',\n result,\n );\n\n const processInstances = result.data.ProcessInstances as ProcessInstance[];\n\n if (processInstances.length === 0) {\n return undefined;\n }\n\n return processInstances[0].processId;\n }\n\n public async fetchInstance(\n instanceId: string,\n ): Promise<ProcessInstance | undefined> {\n const FindProcessInstanceQuery = gql`\n query FindProcessInstanceQuery($instanceId: String!) {\n ProcessInstances(where: { id: { equal: $instanceId } }) {\n id\n processName\n processId\n serviceUrl\n businessKey\n state\n start\n end\n nodes {\n id\n nodeId\n definitionId\n type\n name\n enter\n exit\n }\n variables\n parentProcessInstance {\n id\n processName\n businessKey\n }\n error {\n nodeDefinitionId\n message\n }\n }\n }\n `;\n\n const result = await this.client.query(FindProcessInstanceQuery, {\n instanceId,\n });\n\n this.logger.debug(\n `Fetch process instance result: ${JSON.stringify(result)}`,\n );\n\n this.handleGraphqlClientError(\n 'Error when fetching process instances',\n result,\n );\n\n const processInstances = result.data.ProcessInstances as ProcessInstance[];\n\n if (processInstances.length === 0) {\n return undefined;\n }\n\n const instance = processInstances[0];\n\n const workflowInfo = await this.fetchWorkflowInfo(instance.processId);\n if (!workflowInfo?.source) {\n throw new Error(\n `Workflow defintion is required to fetch instance ${instance.id}`,\n );\n }\n const workflowDefinitionSrc: WorkflowDefinition = fromWorkflowSource(\n workflowInfo.source,\n );\n if (workflowInfo) {\n instance.category = getWorkflowCategory(workflowDefinitionSrc);\n instance.description = workflowDefinitionSrc.description;\n }\n return instance;\n }\n\n private handleGraphqlClientError(scenario: string, result: any) {\n if (!result?.error) {\n return;\n }\n this.logger.error(`${scenario} ${result}`);\n const networkError = result.error.networkError?.cause?.message;\n if (networkError) {\n const toThrow = new Error(`${result.error.message}. ${networkError}`);\n toThrow.name = 'Network Error';\n throw toThrow;\n } else {\n throw result.error;\n }\n }\n}\n"],"names":["ErrorBuilder","Client","fetchExchange","buildFilterCondition","buildGraphQlQuery","FETCH_PROCESS_INSTANCES_SORT_FIELD","fromWorkflowSource","getWorkflowCategory","parseWorkflowVariables","gql"],"mappings":";;;;;;;;;AAqCO,MAAM,gBAAiB,CAAA;AAAA,EAKrB,WAAA,CACY,cACA,MACjB,EAAA;AAFiB,IAAA,IAAA,CAAA,YAAA,GAAA,YAAA,CAAA;AACA,IAAA,IAAA,CAAA,MAAA,GAAA,MAAA,CAAA;AAEjB,IAAI,IAAA,CAAC,aAAa,MAAQ,EAAA;AACxB,MAAA,MAAMA,0BAAa,yBAA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