@red-hat-developer-hub/backstage-plugin-scaffolder-backend-module-orchestrator 1.0.1 → 1.0.2

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,13 @@
1
1
  # @red-hat-developer-hub/backstage-plugin-scaffolder-backend-module-orchestrator
2
2
 
3
+ ## 1.0.2
4
+
5
+ ### Patch Changes
6
+
7
+ - 26e602a: add workflows tab to catalog entities
8
+ - Updated dependencies [26e602a]
9
+ - @red-hat-developer-hub/backstage-plugin-orchestrator-common@3.0.2
10
+
3
11
  ## 1.0.1
4
12
 
5
13
  ### Patch Changes
@@ -18,40 +18,58 @@ const createRunWorkflowAction = (discoveryService, authService) => pluginScaffol
18
18
  supportsDryRun: true,
19
19
  schema: {
20
20
  input: {
21
- required: ["parameters"],
21
+ required: ["workflow_id", "parameters"],
22
22
  type: "object",
23
23
  properties: {
24
+ workflow_id: {
25
+ type: "string",
26
+ title: "Workflow ID",
27
+ description: "The workflow identifier from the workflow definition."
28
+ },
29
+ target_entity: {
30
+ type: "string",
31
+ title: "Target Entity",
32
+ description: "The target entity to run the workflow on."
33
+ },
24
34
  parameters: {
25
35
  type: "object",
26
- title: "Parameters",
27
- description: "The workflow parameters."
36
+ title: "Workflow Inputs",
37
+ description: "The workflow inputs."
28
38
  }
29
39
  }
30
40
  }
31
41
  },
32
42
  async handler(ctx) {
33
- const entity = ctx.templateInfo?.entityRef;
34
- if (!entity) {
43
+ const template_entity = ctx.templateInfo?.entityRef;
44
+ if (!template_entity) {
35
45
  throw new Error("No template entity");
36
46
  }
47
+ const targetEntity = ctx.input.target_entity?.toString() ?? template_entity?.toString();
48
+ const [targetEntityKind, targetEntityNamespace, targetEntityName] = targetEntity?.split(/[:\/]/) || [];
49
+ if (!ctx.input.workflow_id) {
50
+ throw new Error(
51
+ "Missing required 'workflow_id' input. Ensure that the step invoking the 'orchestrator:workflow:run' action includes an explicit 'workflow_id' field in its input."
52
+ );
53
+ }
37
54
  const api = await utils.getOrchestratorApi(discoveryService);
38
55
  const reqConfigOption = await utils.getRequestConfigOption(authService, ctx);
39
56
  if (ctx.isDryRun) {
40
57
  ctx.logger.info(`Dry run complete`);
41
58
  return;
42
59
  }
43
- if (!ctx.input.workflow_id) {
44
- throw new Error(
45
- "Missing required 'workflow_id' input. Ensure that the step invoking the 'orchestrator:workflow:run' action includes an explicit 'workflow_id' field in its input."
46
- );
47
- }
48
60
  try {
49
61
  const { data } = await api.executeWorkflow(
50
62
  ctx.input.workflow_id,
51
- { inputData: ctx.input.parameters },
63
+ {
64
+ inputData: ctx.input.parameters,
65
+ targetEntity
66
+ },
52
67
  reqConfigOption
53
68
  );
54
- ctx.output("instanceUrl", `/orchestrator/instances/${data.id}`);
69
+ ctx.output(
70
+ "instanceUrl",
71
+ `/orchestrator/entity/${targetEntityNamespace}/${targetEntityKind}/${targetEntityName}/${ctx.input.workflow_id}/${data.id}`
72
+ );
55
73
  } catch (err) {
56
74
  throw getError(err);
57
75
  }
@@ -1 +1 @@
1
- {"version":3,"file":"runWorkflow.cjs.js","sources":["../../src/actions/runWorkflow.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 */\nimport { AuthService } from '@backstage/backend-plugin-api';\nimport { DiscoveryApi } from '@backstage/plugin-permission-common';\nimport { createTemplateAction } from '@backstage/plugin-scaffolder-node';\nimport { JsonObject } from '@backstage/types';\n\nimport { isAxiosError } from 'axios';\n\nimport { getOrchestratorApi, getRequestConfigOption } from './utils';\n\ntype RunWorkflowTemplateActionInput = {\n parameters: JsonObject;\n workflow_id: string;\n};\ntype RunWorkflowTemplateActionOutput = { instanceUrl: string };\n\nconst getError = (err: unknown): Error => {\n if (\n isAxiosError<{ error: { message: string; name: string } }>(err) &&\n err.response?.data?.error?.message\n ) {\n const error = new Error(err.response?.data?.error?.message);\n error.name = err.response?.data?.error?.name || 'Error';\n return error;\n }\n return err as Error;\n};\n\nexport const createRunWorkflowAction = (\n discoveryService: DiscoveryApi,\n authService: AuthService,\n) =>\n createTemplateAction<\n RunWorkflowTemplateActionInput,\n RunWorkflowTemplateActionOutput\n >({\n id: 'orchestrator:workflow:run',\n description: 'Run a SonataFlow workflow.',\n supportsDryRun: true,\n schema: {\n input: {\n required: ['parameters'],\n type: 'object',\n properties: {\n parameters: {\n type: 'object',\n title: 'Parameters',\n description: 'The workflow parameters.',\n },\n },\n },\n },\n async handler(ctx) {\n const entity = ctx.templateInfo?.entityRef;\n if (!entity) {\n throw new Error('No template entity');\n }\n\n const api = await getOrchestratorApi(discoveryService);\n const reqConfigOption = await getRequestConfigOption(authService, ctx);\n\n // If this is a dry run, log and return\n if (ctx.isDryRun) {\n ctx.logger.info(`Dry run complete`);\n return;\n }\n\n if (!ctx.input.workflow_id) {\n throw new Error(\n \"Missing required 'workflow_id' input. Ensure that the step invoking the 'orchestrator:workflow:run' action includes an explicit 'workflow_id' field in its input.\",\n );\n }\n\n try {\n const { data } = await api.executeWorkflow(\n ctx.input.workflow_id,\n { inputData: ctx.input.parameters },\n reqConfigOption,\n );\n ctx.output('instanceUrl', `/orchestrator/instances/${data.id}`);\n } catch (err) {\n throw getError(err);\n }\n },\n });\n"],"names":["isAxiosError","createTemplateAction","getOrchestratorApi","getRequestConfigOption"],"mappings":";;;;;;AA8BA,MAAM,QAAA,GAAW,CAAC,GAAA,KAAwB;AACxC,EAAA,IACEA,mBAA2D,GAAG,CAAA,IAC9D,IAAI,QAAA,EAAU,IAAA,EAAM,OAAO,OAAA,EAC3B;AACA,IAAA,MAAM,QAAQ,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F;AAAA,IACF;AAEA,IAAA,IAAI;AACF,MAAA,MAAM,EAAE,IAAA,EAAK,GAAI,MAAM,GAAA,CAAI,eAAA;AAAA,QACzB,IAAI,KAAA,CAAM,WAAA;AAAA,QACV,EAAE,SAAA,EAAW,GAAA,CAAI,KAAA,CAAM,UAAA,EAAW;AAAA,QAClC;AAAA,OACF;AACA,MAAA,GAAA,CAAI,MAAA,CAAO,aAAA,EAAe,CAAA,wBAAA,EAA2B,IAAA,CAAK,EAAE,CAAA,CAAE,CAAA;AAAA,IAChE,SAAS,GAAA,EAAK;AACZ,MAAA,MAAM,SAAS,GAAG,CAAA;AAAA,IACpB;AAAA,EACF;AACF,CAAC;;;;"}
1
+ {"version":3,"file":"runWorkflow.cjs.js","sources":["../../src/actions/runWorkflow.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 */\nimport { AuthService } from '@backstage/backend-plugin-api';\nimport { DiscoveryApi } from '@backstage/plugin-permission-common';\nimport { createTemplateAction } from '@backstage/plugin-scaffolder-node';\nimport { JsonObject } from '@backstage/types';\n\nimport { isAxiosError } from 'axios';\n\nimport { getOrchestratorApi, getRequestConfigOption } from './utils';\n\ntype RunWorkflowTemplateActionInput = {\n workflow_id: string;\n target_entity: any;\n parameters: JsonObject;\n};\ntype RunWorkflowTemplateActionOutput = { instanceUrl: string };\n\nconst getError = (err: unknown): Error => {\n if (\n isAxiosError<{ error: { message: string; name: string } }>(err) &&\n err.response?.data?.error?.message\n ) {\n const error = new Error(err.response?.data?.error?.message);\n error.name = err.response?.data?.error?.name || 'Error';\n return error;\n }\n return err as Error;\n};\n\nexport const createRunWorkflowAction = (\n discoveryService: DiscoveryApi,\n authService: AuthService,\n) =>\n createTemplateAction<\n RunWorkflowTemplateActionInput,\n RunWorkflowTemplateActionOutput\n >({\n id: 'orchestrator:workflow:run',\n description: 'Run a SonataFlow workflow.',\n supportsDryRun: true,\n schema: {\n input: {\n required: ['workflow_id', 'parameters'],\n type: 'object',\n properties: {\n workflow_id: {\n type: 'string',\n title: 'Workflow ID',\n description:\n 'The workflow identifier from the workflow definition.',\n },\n target_entity: {\n type: 'string',\n title: 'Target Entity',\n description: 'The target entity to run the workflow on.',\n },\n parameters: {\n type: 'object',\n title: 'Workflow Inputs',\n description: 'The workflow inputs.',\n },\n },\n },\n },\n async handler(ctx) {\n const template_entity = ctx.templateInfo?.entityRef;\n if (!template_entity) {\n throw new Error('No template entity');\n }\n const targetEntity =\n ctx.input.target_entity?.toString() ?? template_entity?.toString();\n\n const [targetEntityKind, targetEntityNamespace, targetEntityName] =\n targetEntity?.split(/[:\\/]/) || [];\n\n if (!ctx.input.workflow_id) {\n throw new Error(\n \"Missing required 'workflow_id' input. Ensure that the step invoking the 'orchestrator:workflow:run' action includes an explicit 'workflow_id' field in its input.\",\n );\n }\n\n const api = await getOrchestratorApi(discoveryService);\n const reqConfigOption = await getRequestConfigOption(authService, ctx);\n\n // If this is a dry run, log and return\n if (ctx.isDryRun) {\n ctx.logger.info(`Dry run complete`);\n return;\n }\n\n try {\n const { data } = await api.executeWorkflow(\n ctx.input.workflow_id,\n {\n inputData: ctx.input.parameters,\n targetEntity,\n },\n reqConfigOption,\n );\n ctx.output(\n 'instanceUrl',\n `/orchestrator/entity/${targetEntityNamespace}/${targetEntityKind}/${targetEntityName}/${ctx.input.workflow_id}/${data.id}`,\n );\n } catch (err) {\n throw getError(err);\n }\n },\n });\n"],"names":["isAxiosError","createTemplateAction","getOrchestratorApi","getRequestConfigOption"],"mappings":";;;;;;AA+BA,MAAM,QAAA,GAAW,CAAC,GAAA,KAAwB;AAC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backend-module-orchestrator",
3
3
  "description": "The orchestrator module for @backstage/plugin-scaffolder-backend",
4
- "version": "1.0.1",
4
+ "version": "1.0.2",
5
5
  "main": "./dist/index.cjs.js",
6
6
  "types": "./dist/index.d.ts",
7
7
  "license": "Apache-2.0",
@@ -71,7 +71,7 @@
71
71
  "@backstage/plugin-permission-common": "^0.9.0",
72
72
  "@backstage/plugin-scaffolder-node": "^0.8.2",
73
73
  "@backstage/types": "^1.2.1",
74
- "@red-hat-developer-hub/backstage-plugin-orchestrator-common": "^3.0.1",
74
+ "@red-hat-developer-hub/backstage-plugin-orchestrator-common": "^3.0.2",
75
75
  "axios": "^1.11.0",
76
76
  "js-yaml": "^4.1.0"
77
77
  },