@red-hat-developer-hub/backstage-plugin-scaffolder-backend-module-orchestrator 1.0.6 → 1.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 +22 -0
- package/dist/actions/getWorkflowParams.cjs.js +49 -52
- package/dist/actions/getWorkflowParams.cjs.js.map +1 -1
- package/dist/actions/runWorkflow.cjs.js +47 -61
- package/dist/actions/runWorkflow.cjs.js.map +1 -1
- package/dist/module.cjs.js +2 -2
- package/dist/module.cjs.js.map +1 -1
- package/package.json +9 -9
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,27 @@
|
|
|
1
1
|
# @red-hat-developer-hub/backstage-plugin-scaffolder-backend-module-orchestrator
|
|
2
2
|
|
|
3
|
+
## 1.2.0
|
|
4
|
+
|
|
5
|
+
### Minor Changes
|
|
6
|
+
|
|
7
|
+
- fba1136: Backstage version bump to v1.44.1
|
|
8
|
+
|
|
9
|
+
### Patch Changes
|
|
10
|
+
|
|
11
|
+
- Updated dependencies [fba1136]
|
|
12
|
+
- @red-hat-developer-hub/backstage-plugin-orchestrator-common@3.2.0
|
|
13
|
+
|
|
14
|
+
## 1.1.0
|
|
15
|
+
|
|
16
|
+
### Minor Changes
|
|
17
|
+
|
|
18
|
+
- de5ced6: Backstage version bump to v1.42.5
|
|
19
|
+
|
|
20
|
+
### Patch Changes
|
|
21
|
+
|
|
22
|
+
- Updated dependencies [de5ced6]
|
|
23
|
+
- @red-hat-developer-hub/backstage-plugin-orchestrator-common@3.1.0
|
|
24
|
+
|
|
3
25
|
## 1.0.6
|
|
4
26
|
|
|
5
27
|
### Patch Changes
|
|
@@ -14,64 +14,61 @@ const getError = (err) => {
|
|
|
14
14
|
return err;
|
|
15
15
|
};
|
|
16
16
|
const indentString = (str, indent) => indent ? str.replace(/^/gm, " ".repeat(indent)) : str;
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
workflow_id: {
|
|
27
|
-
type: "string"
|
|
28
|
-
}
|
|
17
|
+
function createGetWorkflowParamsAction(discoveryService, authService) {
|
|
18
|
+
return pluginScaffolderNode.createTemplateAction({
|
|
19
|
+
id: "orchestrator:workflow:get_params",
|
|
20
|
+
description: "Collect parameters of a SonataFlow workflow.",
|
|
21
|
+
supportsDryRun: false,
|
|
22
|
+
schema: {
|
|
23
|
+
input: {
|
|
24
|
+
workflow_id: (z) => z.string().describe("Workflow Id"),
|
|
25
|
+
indent: (z) => z.number().optional().describe("Number of indents")
|
|
29
26
|
}
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
throw new Error("Missing workflow_id required input parameter.");
|
|
36
|
-
}
|
|
37
|
-
const api = await utils.getOrchestratorApi(discoveryService);
|
|
38
|
-
const reqConfigOption = await utils.getRequestConfigOption(authService, ctx);
|
|
39
|
-
try {
|
|
40
|
-
const { data: workflow } = await api.getWorkflowOverviewById(
|
|
41
|
-
workflowId,
|
|
42
|
-
reqConfigOption
|
|
43
|
-
);
|
|
44
|
-
if (!workflow) {
|
|
45
|
-
throw new Error(`Can not find workflow ${workflowId}`);
|
|
27
|
+
},
|
|
28
|
+
async handler(ctx) {
|
|
29
|
+
const workflowId = ctx.input?.workflow_id;
|
|
30
|
+
if (!workflowId) {
|
|
31
|
+
throw new Error("Missing workflow_id required input parameter.");
|
|
46
32
|
}
|
|
47
|
-
const
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
ctx.output("title", workflow.name || workflowId);
|
|
54
|
-
ctx.output("description", workflow.description || "");
|
|
55
|
-
if (inputSchema?.properties) {
|
|
56
|
-
let parametersYaml = jsYaml.dump(
|
|
57
|
-
[
|
|
58
|
-
// scaffolder expects an array on the top-level
|
|
59
|
-
inputSchema
|
|
60
|
-
],
|
|
61
|
-
{ indent: 2 }
|
|
33
|
+
const api = await utils.getOrchestratorApi(discoveryService);
|
|
34
|
+
const reqConfigOption = await utils.getRequestConfigOption(authService, ctx);
|
|
35
|
+
try {
|
|
36
|
+
const { data: workflow } = await api.getWorkflowOverviewById(
|
|
37
|
+
workflowId,
|
|
38
|
+
reqConfigOption
|
|
62
39
|
);
|
|
63
|
-
|
|
64
|
-
|
|
40
|
+
if (!workflow) {
|
|
41
|
+
throw new Error(`Can not find workflow ${workflowId}`);
|
|
42
|
+
}
|
|
43
|
+
const { data: inputSchemaWrapper } = await api.getWorkflowInputSchemaById(
|
|
44
|
+
workflowId,
|
|
45
|
+
void 0,
|
|
46
|
+
reqConfigOption
|
|
47
|
+
);
|
|
48
|
+
const inputSchema = inputSchemaWrapper.inputSchema;
|
|
49
|
+
ctx.output("title", workflow.name || workflowId);
|
|
50
|
+
ctx.output("description", workflow.description || "");
|
|
51
|
+
if (inputSchema?.properties) {
|
|
52
|
+
let parametersYaml = jsYaml.dump(
|
|
53
|
+
[
|
|
54
|
+
// scaffolder expects an array on the top-level
|
|
55
|
+
inputSchema
|
|
56
|
+
],
|
|
57
|
+
{ indent: 2 }
|
|
58
|
+
);
|
|
59
|
+
parametersYaml = indentString(parametersYaml, ctx.input?.indent || 0);
|
|
60
|
+
parametersYaml = `
|
|
65
61
|
${parametersYaml}`;
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
62
|
+
ctx.output("parameters", parametersYaml);
|
|
63
|
+
} else {
|
|
64
|
+
ctx.output("parameters", "{}");
|
|
65
|
+
}
|
|
66
|
+
} catch (err) {
|
|
67
|
+
throw getError(err);
|
|
69
68
|
}
|
|
70
|
-
} catch (err) {
|
|
71
|
-
throw getError(err);
|
|
72
69
|
}
|
|
73
|
-
}
|
|
74
|
-
}
|
|
70
|
+
});
|
|
71
|
+
}
|
|
75
72
|
|
|
76
73
|
exports.createGetWorkflowParamsAction = createGetWorkflowParamsAction;
|
|
77
74
|
//# sourceMappingURL=getWorkflowParams.cjs.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"getWorkflowParams.cjs.js","sources":["../../src/actions/getWorkflowParams.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/index';\n\nimport { isAxiosError } from 'axios';\nimport { dump } from 'js-yaml';\n\nimport { getOrchestratorApi, getRequestConfigOption } from './utils';\n\
|
|
1
|
+
{"version":3,"file":"getWorkflowParams.cjs.js","sources":["../../src/actions/getWorkflowParams.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/index';\n\nimport { isAxiosError } from 'axios';\nimport { dump } from 'js-yaml';\n\nimport { getOrchestratorApi, getRequestConfigOption } from './utils';\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\nconst indentString = (str: string, indent: number) =>\n indent ? str.replace(/^/gm, ' '.repeat(indent)) : str;\n\nexport function createGetWorkflowParamsAction(\n discoveryService: DiscoveryApi,\n authService: AuthService,\n) {\n return createTemplateAction({\n id: 'orchestrator:workflow:get_params',\n description: 'Collect parameters of a SonataFlow workflow.',\n supportsDryRun: false,\n schema: {\n input: {\n workflow_id: z => z.string().describe('Workflow Id'),\n indent: z => z.number().optional().describe('Number of indents'),\n },\n },\n async handler(ctx) {\n const workflowId = ctx.input?.workflow_id;\n if (!workflowId) {\n throw new Error('Missing workflow_id required input parameter.');\n }\n\n const api = await getOrchestratorApi(discoveryService);\n const reqConfigOption = await getRequestConfigOption(authService, ctx);\n\n try {\n const { data: workflow } = await api.getWorkflowOverviewById(\n workflowId,\n reqConfigOption,\n );\n if (!workflow) {\n throw new Error(`Can not find workflow ${workflowId}`);\n }\n\n const { data: inputSchemaWrapper } =\n await api.getWorkflowInputSchemaById(\n workflowId,\n undefined,\n reqConfigOption,\n );\n const inputSchema: JsonObject | undefined =\n inputSchemaWrapper.inputSchema;\n\n ctx.output('title', workflow.name || workflowId);\n ctx.output('description', workflow.description || '');\n\n if (inputSchema?.properties) {\n let parametersYaml = dump(\n [\n // scaffolder expects an array on the top-level\n inputSchema,\n ],\n { indent: 2 },\n );\n parametersYaml = indentString(parametersYaml, ctx.input?.indent || 0);\n parametersYaml = `\\n${parametersYaml}`;\n\n ctx.output('parameters', parametersYaml);\n } else {\n ctx.output('parameters', '{}');\n }\n } catch (err) {\n throw getError(err);\n }\n },\n });\n}\n"],"names":["isAxiosError","createTemplateAction","getOrchestratorApi","getRequestConfigOption","dump"],"mappings":";;;;;;;AAyBA,MAAM,QAAA,GAAW,CAAC,GAAA,KAAwB;AACxC,EAA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
12
|
}
|
|
13
13
|
return err;
|
|
14
14
|
};
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
15
|
+
function createRunWorkflowAction(discoveryService, authService) {
|
|
16
|
+
return pluginScaffolderNode.createTemplateAction({
|
|
17
|
+
id: "orchestrator:workflow:run",
|
|
18
|
+
description: "Run a SonataFlow workflow.",
|
|
19
|
+
supportsDryRun: true,
|
|
20
|
+
schema: {
|
|
21
|
+
input: {
|
|
22
|
+
workflow_id: (z) => z.string().describe("The workflow identifier from the workflow definition."),
|
|
23
|
+
target_entity: (z) => z.string().optional().describe("The target entity to run the workflow on."),
|
|
24
|
+
parameters: (z) => z.record(z.string(), z.any()).describe("The workflow inputs.")
|
|
25
|
+
}
|
|
26
|
+
},
|
|
27
|
+
async handler(ctx) {
|
|
28
|
+
const template_entity = ctx.templateInfo?.entityRef;
|
|
29
|
+
if (!template_entity) {
|
|
30
|
+
throw new Error("No template entity");
|
|
31
|
+
}
|
|
32
|
+
const targetEntity = ctx.input.target_entity?.toString() ?? template_entity?.toString();
|
|
33
|
+
const [targetEntityKind, targetEntityNamespace, targetEntityName] = targetEntity?.split(/[:\/]/) || [];
|
|
34
|
+
if (!ctx.input.workflow_id) {
|
|
35
|
+
throw new Error(
|
|
36
|
+
"Missing required 'workflow_id' input. Ensure that the step invoking the 'orchestrator:workflow:run' action includes an explicit 'workflow_id' field in its input."
|
|
37
|
+
);
|
|
38
|
+
}
|
|
39
|
+
const api = await utils.getOrchestratorApi(discoveryService);
|
|
40
|
+
const reqConfigOption = await utils.getRequestConfigOption(authService, ctx);
|
|
41
|
+
if (ctx.isDryRun) {
|
|
42
|
+
ctx.logger.info(`Dry run complete`);
|
|
43
|
+
return;
|
|
44
|
+
}
|
|
45
|
+
try {
|
|
46
|
+
const { data } = await api.executeWorkflow(
|
|
47
|
+
ctx.input.workflow_id,
|
|
48
|
+
{
|
|
49
|
+
inputData: ctx.input.parameters,
|
|
50
|
+
targetEntity
|
|
51
|
+
},
|
|
52
|
+
reqConfigOption
|
|
53
|
+
);
|
|
54
|
+
ctx.output(
|
|
55
|
+
"instanceUrl",
|
|
56
|
+
`/orchestrator/entity/${targetEntityNamespace}/${targetEntityKind}/${targetEntityName}/${ctx.input.workflow_id}/${data.id}`
|
|
57
|
+
);
|
|
58
|
+
} catch (err) {
|
|
59
|
+
throw getError(err);
|
|
39
60
|
}
|
|
40
61
|
}
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
const template_entity = ctx.templateInfo?.entityRef;
|
|
44
|
-
if (!template_entity) {
|
|
45
|
-
throw new Error("No template entity");
|
|
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
|
-
}
|
|
54
|
-
const api = await utils.getOrchestratorApi(discoveryService);
|
|
55
|
-
const reqConfigOption = await utils.getRequestConfigOption(authService, ctx);
|
|
56
|
-
if (ctx.isDryRun) {
|
|
57
|
-
ctx.logger.info(`Dry run complete`);
|
|
58
|
-
return;
|
|
59
|
-
}
|
|
60
|
-
try {
|
|
61
|
-
const { data } = await api.executeWorkflow(
|
|
62
|
-
ctx.input.workflow_id,
|
|
63
|
-
{
|
|
64
|
-
inputData: ctx.input.parameters,
|
|
65
|
-
targetEntity
|
|
66
|
-
},
|
|
67
|
-
reqConfigOption
|
|
68
|
-
);
|
|
69
|
-
ctx.output(
|
|
70
|
-
"instanceUrl",
|
|
71
|
-
`/orchestrator/entity/${targetEntityNamespace}/${targetEntityKind}/${targetEntityName}/${ctx.input.workflow_id}/${data.id}`
|
|
72
|
-
);
|
|
73
|
-
} catch (err) {
|
|
74
|
-
throw getError(err);
|
|
75
|
-
}
|
|
76
|
-
}
|
|
77
|
-
});
|
|
62
|
+
});
|
|
63
|
+
}
|
|
78
64
|
|
|
79
65
|
exports.createRunWorkflowAction = createRunWorkflowAction;
|
|
80
66
|
//# sourceMappingURL=runWorkflow.cjs.js.map
|
|
@@ -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';\
|
|
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';\n\nimport { isAxiosError } from 'axios';\n\nimport { getOrchestratorApi, getRequestConfigOption } from './utils';\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 function createRunWorkflowAction(\n discoveryService: DiscoveryApi,\n authService: AuthService,\n) {\n return createTemplateAction({\n id: 'orchestrator:workflow:run',\n description: 'Run a SonataFlow workflow.',\n supportsDryRun: true,\n schema: {\n input: {\n workflow_id: z =>\n z\n .string()\n .describe('The workflow identifier from the workflow definition.'),\n target_entity: z =>\n z\n .string()\n .optional()\n .describe('The target entity to run the workflow on.'),\n parameters: z =>\n z.record(z.string(), z.any()).describe('The workflow inputs.'),\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}\n"],"names":["isAxiosError","createTemplateAction","getOrchestratorApi","getRequestConfigOption"],"mappings":";;;;;;AAuBA,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,IAAI,KAAA,CAAM,IAAI,QAAA,EAAU,IAAA,EAAM,OAAO,OAAO,CAAA;AAC1D,IAAA,KAAA,CAAM,IAAA,GAAO,GAAA,CAAI,QAAA,EAAU,IAAA,EAAM,OAAO,IAAA,IAAQ,OAAA;AAChD,IAAA,OAAO,KAAA;AAAA,EACT;AACA,EAAA,OAAO,GAAA;AACT,CAAA;AAEO,SAAS,uBAAA,CACd,kBACA,WAAA,EACA;AACA,EAAA,OAAOC,yCAAA,CAAqB;AAAA,IAC1B,EAAA,EAAI,2BAAA;AAAA,IACJ,WAAA,EAAa,4BAAA;AAAA,IACb,cAAA,EAAgB,IAAA;AAAA,IAChB,MAAA,EAAQ;AAAA,MACN,KAAA,EAAO;AAAA,QACL,aAAa,CAAA,CAAA,KACX,CAAA,CACG,MAAA,EAAO,CACP,SAAS,uDAAuD,CAAA;AAAA,QACrE,aAAA,EAAe,OACb,CAAA,CACG,MAAA,GACA,QAAA,EAAS,CACT,SAAS,2CAA2C,CAAA;AAAA,QACzD,UAAA,EAAY,CAAA,CAAA,KACV,CAAA,CAAE,MAAA,CAAO,CAAA,CAAE,MAAA,EAAO,EAAG,CAAA,CAAE,GAAA,EAAK,CAAA,CAAE,QAAA,CAAS,sBAAsB;AAAA;AACjE,KACF;AAAA,IACA,MAAM,QAAQ,GAAA,EAAK;AACjB,MAAA,MAAM,eAAA,GAAkB,IAAI,YAAA,EAAc,SAAA;AAC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AAAA,IACF;AAAA,GACD,CAAA;AACH;;;;"}
|
package/dist/module.cjs.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
3
|
var backendPluginApi = require('@backstage/backend-plugin-api');
|
|
4
|
-
var
|
|
4
|
+
var pluginScaffolderNode = require('@backstage/plugin-scaffolder-node');
|
|
5
5
|
var runWorkflow = require('./actions/runWorkflow.cjs.js');
|
|
6
6
|
var getWorkflowParams = require('./actions/getWorkflowParams.cjs.js');
|
|
7
7
|
|
|
@@ -11,7 +11,7 @@ const scaffolderModule = backendPluginApi.createBackendModule({
|
|
|
11
11
|
register({ registerInit }) {
|
|
12
12
|
registerInit({
|
|
13
13
|
deps: {
|
|
14
|
-
scaffolderActions:
|
|
14
|
+
scaffolderActions: pluginScaffolderNode.scaffolderActionsExtensionPoint,
|
|
15
15
|
discoveryService: backendPluginApi.coreServices.discovery,
|
|
16
16
|
authService: backendPluginApi.coreServices.auth
|
|
17
17
|
},
|
package/dist/module.cjs.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"module.cjs.js","sources":["../src/module.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 {\n coreServices,\n createBackendModule,\n} from '@backstage/backend-plugin-api';\nimport { scaffolderActionsExtensionPoint } from '@backstage/plugin-scaffolder-node
|
|
1
|
+
{"version":3,"file":"module.cjs.js","sources":["../src/module.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 {\n coreServices,\n createBackendModule,\n} from '@backstage/backend-plugin-api';\nimport { scaffolderActionsExtensionPoint } from '@backstage/plugin-scaffolder-node';\n\nimport {\n createGetWorkflowParamsAction,\n createRunWorkflowAction,\n} from './actions';\n\n/**\n * A backend module that registers the action into the scaffolder\n */\nexport const scaffolderModule = createBackendModule({\n moduleId: 'orchestrator',\n pluginId: 'scaffolder',\n register({ registerInit }) {\n registerInit({\n deps: {\n scaffolderActions: scaffolderActionsExtensionPoint,\n discoveryService: coreServices.discovery,\n authService: coreServices.auth,\n },\n async init({ scaffolderActions, discoveryService, authService }) {\n scaffolderActions.addActions(\n createRunWorkflowAction(discoveryService, authService),\n );\n scaffolderActions.addActions(\n createGetWorkflowParamsAction(discoveryService, authService),\n );\n },\n });\n },\n});\n"],"names":["createBackendModule","scaffolderActionsExtensionPoint","coreServices","createRunWorkflowAction","createGetWorkflowParamsAction"],"mappings":";;;;;;;AA6BO,MAAM,mBAAmBA,oCAAA,CAAoB;AAAA,EAClD,QAAA,EAAU,cAAA;AAAA,EACV,QAAA,EAAU,YAAA;AAAA,EACV,QAAA,CAAS,EAAE,YAAA,EAAa,EAAG;AACzB,IAAA,YAAA,CAAa;AAAA,MACX,IAAA,EAAM;AAAA,QACJ,iBAAA,EAAmBC,oDAAA;AAAA,QACnB,kBAAkBC,6BAAA,CAAa,SAAA;AAAA,QAC/B,aAAaA,6BAAA,CAAa;AAAA,OAC5B;AAAA,MACA,MAAM,IAAA,CAAK,EAAE,iBAAA,EAAmB,gBAAA,EAAkB,aAAY,EAAG;AAC/D,QAAA,iBAAA,CAAkB,UAAA;AAAA,UAChBC,mCAAA,CAAwB,kBAAkB,WAAW;AAAA,SACvD;AACA,QAAA,iBAAA,CAAkB,UAAA;AAAA,UAChBC,+CAAA,CAA8B,kBAAkB,WAAW;AAAA,SAC7D;AAAA,MACF;AAAA,KACD,CAAA;AAAA,EACH;AACF,CAAC;;;;"}
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@red-hat-developer-hub/backstage-plugin-scaffolder-backend-module-orchestrator",
|
|
3
3
|
"description": "The orchestrator module for @backstage/plugin-scaffolder-backend",
|
|
4
|
-
"version": "1.0
|
|
4
|
+
"version": "1.2.0",
|
|
5
5
|
"main": "./dist/index.cjs.js",
|
|
6
6
|
"types": "./dist/index.d.ts",
|
|
7
7
|
"license": "Apache-2.0",
|
|
@@ -66,18 +66,18 @@
|
|
|
66
66
|
"export-dynamic": "janus-cli package export-dynamic-plugin --embed-package '@red-hat-developer-hub/backstage-plugin-orchestrator-common'"
|
|
67
67
|
},
|
|
68
68
|
"dependencies": {
|
|
69
|
-
"@backstage/backend-plugin-api": "^1.
|
|
70
|
-
"@backstage/catalog-model": "^1.7.
|
|
71
|
-
"@backstage/plugin-permission-common": "^0.9.
|
|
72
|
-
"@backstage/plugin-scaffolder-node": "^0.
|
|
73
|
-
"@backstage/types": "^1.2.
|
|
74
|
-
"@red-hat-developer-hub/backstage-plugin-orchestrator-common": "^3.0
|
|
69
|
+
"@backstage/backend-plugin-api": "^1.4.4",
|
|
70
|
+
"@backstage/catalog-model": "^1.7.5",
|
|
71
|
+
"@backstage/plugin-permission-common": "^0.9.2",
|
|
72
|
+
"@backstage/plugin-scaffolder-node": "^0.12.0",
|
|
73
|
+
"@backstage/types": "^1.2.2",
|
|
74
|
+
"@red-hat-developer-hub/backstage-plugin-orchestrator-common": "^3.2.0",
|
|
75
75
|
"axios": "^1.11.0",
|
|
76
76
|
"js-yaml": "^4.1.0"
|
|
77
77
|
},
|
|
78
78
|
"devDependencies": {
|
|
79
|
-
"@backstage/cli": "^0.
|
|
80
|
-
"@backstage/plugin-scaffolder-node-test-utils": "^0.
|
|
79
|
+
"@backstage/cli": "^0.34.4",
|
|
80
|
+
"@backstage/plugin-scaffolder-node-test-utils": "^0.3.4",
|
|
81
81
|
"@janus-idp/cli": "3.6.1",
|
|
82
82
|
"@spotify/prettier-config": "^15.0.0"
|
|
83
83
|
},
|