@backstage/plugin-scaffolder-backend 1.33.1-next.0 → 2.0.0-next.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.
Files changed (65) hide show
  1. package/CHANGELOG.md +171 -0
  2. package/dist/ScaffolderPlugin.cjs.js +7 -19
  3. package/dist/ScaffolderPlugin.cjs.js.map +1 -1
  4. package/dist/alpha.cjs.js +5 -9
  5. package/dist/alpha.cjs.js.map +1 -1
  6. package/dist/alpha.d.ts +1 -5
  7. package/dist/index.cjs.js +0 -28
  8. package/dist/index.cjs.js.map +1 -1
  9. package/dist/index.d.ts +120 -450
  10. package/dist/lib/templating/SecureTemplater.cjs.js.map +1 -1
  11. package/dist/scaffolder/actions/TemplateActionRegistry.cjs.js.map +1 -1
  12. package/dist/scaffolder/actions/builtin/catalog/fetch.cjs.js +5 -11
  13. package/dist/scaffolder/actions/builtin/catalog/fetch.cjs.js.map +1 -1
  14. package/dist/scaffolder/actions/builtin/catalog/register.cjs.js +26 -62
  15. package/dist/scaffolder/actions/builtin/catalog/register.cjs.js.map +1 -1
  16. package/dist/scaffolder/actions/builtin/catalog/write.cjs.js +4 -5
  17. package/dist/scaffolder/actions/builtin/catalog/write.cjs.js.map +1 -1
  18. package/dist/scaffolder/actions/builtin/debug/log.cjs.js +4 -5
  19. package/dist/scaffolder/actions/builtin/debug/log.cjs.js.map +1 -1
  20. package/dist/scaffolder/actions/builtin/debug/wait.cjs.js +9 -15
  21. package/dist/scaffolder/actions/builtin/debug/wait.cjs.js.map +1 -1
  22. package/dist/scaffolder/actions/builtin/fetch/plain.cjs.js +9 -19
  23. package/dist/scaffolder/actions/builtin/fetch/plain.cjs.js.map +1 -1
  24. package/dist/scaffolder/actions/builtin/fetch/plainFile.cjs.js +9 -19
  25. package/dist/scaffolder/actions/builtin/fetch/plainFile.cjs.js.map +1 -1
  26. package/dist/scaffolder/actions/builtin/fetch/template.cjs.js +33 -55
  27. package/dist/scaffolder/actions/builtin/fetch/template.cjs.js.map +1 -1
  28. package/dist/scaffolder/actions/builtin/fetch/templateActionHandler.cjs.js +4 -19
  29. package/dist/scaffolder/actions/builtin/fetch/templateActionHandler.cjs.js.map +1 -1
  30. package/dist/scaffolder/actions/builtin/fetch/templateFile.cjs.js +24 -34
  31. package/dist/scaffolder/actions/builtin/fetch/templateFile.cjs.js.map +1 -1
  32. package/dist/scaffolder/actions/builtin/filesystem/delete.cjs.js +3 -12
  33. package/dist/scaffolder/actions/builtin/filesystem/delete.cjs.js.map +1 -1
  34. package/dist/scaffolder/actions/builtin/filesystem/read.cjs.js +14 -14
  35. package/dist/scaffolder/actions/builtin/filesystem/read.cjs.js.map +1 -1
  36. package/dist/scaffolder/actions/builtin/filesystem/rename.cjs.js +16 -27
  37. package/dist/scaffolder/actions/builtin/filesystem/rename.cjs.js.map +1 -1
  38. package/dist/scaffolder/dryrun/DecoratedActionsRegistry.cjs.js +2 -11
  39. package/dist/scaffolder/dryrun/DecoratedActionsRegistry.cjs.js.map +1 -1
  40. package/dist/scaffolder/dryrun/createDryRunner.cjs.js.map +1 -1
  41. package/dist/scaffolder/tasks/DatabaseTaskStore.cjs.js.map +1 -1
  42. package/dist/scaffolder/tasks/NunjucksWorkflowRunner.cjs.js +8 -15
  43. package/dist/scaffolder/tasks/NunjucksWorkflowRunner.cjs.js.map +1 -1
  44. package/dist/scaffolder/tasks/StorageTaskBroker.cjs.js.map +1 -1
  45. package/dist/scaffolder/tasks/TaskWorker.cjs.js.map +1 -1
  46. package/dist/service/{conditionExports.cjs.js → alpha.cjs.js} +1 -1
  47. package/dist/service/alpha.cjs.js.map +1 -0
  48. package/dist/service/helpers.cjs.js +4 -2
  49. package/dist/service/helpers.cjs.js.map +1 -1
  50. package/dist/service/permissions.cjs.js +14 -0
  51. package/dist/service/permissions.cjs.js.map +1 -0
  52. package/dist/service/router.cjs.js +48 -140
  53. package/dist/service/router.cjs.js.map +1 -1
  54. package/dist/service/rules.cjs.js +11 -11
  55. package/dist/service/rules.cjs.js.map +1 -1
  56. package/dist/util/templating.cjs.js +3 -3
  57. package/dist/util/templating.cjs.js.map +1 -1
  58. package/package.json +24 -27
  59. package/dist/deprecated.cjs.js +0 -15
  60. package/dist/deprecated.cjs.js.map +0 -1
  61. package/dist/scaffolder/actions/builtin/createBuiltinActions.cjs.js +0 -158
  62. package/dist/scaffolder/actions/builtin/createBuiltinActions.cjs.js.map +0 -1
  63. package/dist/scaffolder/actions/deprecated.cjs.js +0 -48
  64. package/dist/scaffolder/actions/deprecated.cjs.js.map +0 -1
  65. package/dist/service/conditionExports.cjs.js.map +0 -1
@@ -1 +1 @@
1
- {"version":3,"file":"SecureTemplater.cjs.js","sources":["../../../src/lib/templating/SecureTemplater.ts"],"sourcesContent":["/*\n * Copyright 2021 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 */\n\nimport { Isolate } from 'isolated-vm';\nimport { resolvePackagePath } from '@backstage/backend-plugin-api';\nimport {\n TemplateFilter as _TemplateFilter,\n TemplateGlobal as _TemplateGlobal,\n} from '@backstage/plugin-scaffolder-node';\nimport fs from 'fs-extra';\nimport { JsonValue } from '@backstage/types';\nimport { getMajorNodeVersion, isNoNodeSnapshotOptionProvided } from './helpers';\n\n// language=JavaScript\nconst mkScript = (nunjucksSource: string) => `\nconst { render, renderCompat } = (() => {\n const module = {};\n const process = { env: {} };\n const require = (pkg) => { if (pkg === 'events') { return function (){}; }};\n\n ${nunjucksSource}\n\n const env = module.exports.configure({\n autoescape: false,\n ...JSON.parse(nunjucksConfigs),\n tags: {\n variableStart: '\\${{',\n variableEnd: '}}',\n },\n });\n\n const compatEnv = module.exports.configure({\n autoescape: false,\n ...JSON.parse(nunjucksConfigs),\n tags: {\n variableStart: '{{',\n variableEnd: '}}',\n },\n });\n compatEnv.addFilter('jsonify', compatEnv.getFilter('dump'));\n\n const handleFunctionResult = (value) => {\n return value === '' ? undefined : JSON.parse(value);\n };\n for (const name of JSON.parse(availableTemplateFilters)) {\n env.addFilter(name, (...args) => handleFunctionResult(callFilter(name, args)));\n }\n for (const [name, value] of Object.entries(JSON.parse(availableTemplateGlobals))) {\n env.addGlobal(name, value);\n }\n for (const name of JSON.parse(availableTemplateCallbacks)) {\n env.addGlobal(name, (...args) => handleFunctionResult(callGlobal(name, args)));\n }\n\n let uninstallCompat = undefined;\n\n function render(str, values) {\n try {\n if (uninstallCompat) {\n uninstallCompat();\n uninstallCompat = undefined;\n }\n return env.renderString(str, JSON.parse(values));\n } catch (error) {\n // Make sure errors don't leak anything\n throw new Error(String(error.message));\n }\n }\n\n function renderCompat(str, values) {\n try {\n if (!uninstallCompat) {\n uninstallCompat = module.exports.installJinjaCompat();\n }\n return compatEnv.renderString(str, JSON.parse(values));\n } catch (error) {\n // Make sure errors don't leak anything\n throw new Error(String(error.message));\n }\n }\n\n return { render, renderCompat };\n})();\n`;\n\n/**\n * @public\n * @deprecated Import from `@backstage/plugin-scaffolder-node` instead.\n */\nexport type TemplateFilter = _TemplateFilter;\n\n/**\n * @public\n * @deprecated Import from `@backstage/plugin-scaffolder-node` instead.\n */\nexport type TemplateGlobal = _TemplateGlobal;\n\ninterface SecureTemplaterOptions {\n /* Enables jinja compatibility and the \"jsonify\" filter */\n cookiecutterCompat?: boolean;\n /* Extra user-provided nunjucks filters */\n templateFilters?: Record<string, TemplateFilter>;\n /* Extra user-provided nunjucks globals */\n templateGlobals?: Record<string, TemplateGlobal>;\n nunjucksConfigs?: { trimBlocks?: boolean; lstripBlocks?: boolean };\n}\n\nexport type SecureTemplateRenderer = (\n template: string,\n values: unknown,\n) => string;\n\nexport class SecureTemplater {\n static async loadRenderer(options: SecureTemplaterOptions = {}) {\n const {\n cookiecutterCompat,\n templateFilters = {},\n templateGlobals = {},\n nunjucksConfigs = {},\n } = options;\n\n const nodeVersion = getMajorNodeVersion();\n if (nodeVersion >= 20 && !isNoNodeSnapshotOptionProvided()) {\n throw new Error(\n `When using Node.js version 20 or newer, the scaffolder backend plugin requires that it be started with the --no-node-snapshot option. \n Please make sure that you have NODE_OPTIONS=--no-node-snapshot in your environment.`,\n );\n }\n\n const isolate = new Isolate({ memoryLimit: 128 });\n const context = await isolate.createContext();\n const contextGlobal = context.global;\n\n const nunjucksSource = await fs.readFile(\n resolvePackagePath(\n '@backstage/plugin-scaffolder-backend',\n 'assets/nunjucks.js.txt',\n ),\n 'utf-8',\n );\n\n const nunjucksScript = await isolate.compileScript(\n mkScript(nunjucksSource),\n );\n\n await contextGlobal.set('nunjucksConfigs', JSON.stringify(nunjucksConfigs));\n\n const availableFilters = Object.keys(templateFilters);\n\n await contextGlobal.set(\n 'availableTemplateFilters',\n JSON.stringify(availableFilters),\n );\n\n const globalCallbacks = [];\n const globalValues: Record<string, unknown> = {};\n for (const [name, value] of Object.entries(templateGlobals)) {\n if (typeof value === 'function') {\n globalCallbacks.push(name);\n } else {\n globalValues[name] = value;\n }\n }\n\n await contextGlobal.set(\n 'availableTemplateGlobals',\n JSON.stringify(globalValues),\n );\n await contextGlobal.set(\n 'availableTemplateCallbacks',\n JSON.stringify(globalCallbacks),\n );\n\n await contextGlobal.set(\n 'callFilter',\n (filterName: string, args: JsonValue[]) => {\n if (!Object.hasOwn(templateFilters, filterName)) {\n return '';\n }\n const [input, ...rest] = args;\n const rz = templateFilters[filterName](input, ...rest);\n return rz === undefined ? '' : JSON.stringify(rz);\n },\n );\n\n await contextGlobal.set(\n 'callGlobal',\n (globalName: string, args: JsonValue[]) => {\n if (!Object.hasOwn(templateGlobals, globalName)) {\n return '';\n }\n const global = templateGlobals[globalName];\n if (typeof global !== 'function') {\n return '';\n }\n const rz = global(...args);\n return rz === undefined ? '' : JSON.stringify(rz);\n },\n );\n\n await nunjucksScript.run(context);\n\n const render: SecureTemplateRenderer = (template, values) => {\n if (!context) {\n throw new Error('SecureTemplater has not been initialized');\n }\n\n contextGlobal.setSync('templateStr', String(template));\n contextGlobal.setSync('templateValues', JSON.stringify(values));\n\n if (cookiecutterCompat) {\n return context.evalSync(`renderCompat(templateStr, templateValues)`);\n }\n\n return context.evalSync(`render(templateStr, templateValues)`);\n };\n return render;\n }\n}\n"],"names":["getMajorNodeVersion","isNoNodeSnapshotOptionProvided","Isolate","fs","resolvePackagePath"],"mappings":";;;;;;;;;;;AA2BA,MAAM,QAAA,GAAW,CAAC,cAA2B,KAAA;AAAA;AAAA;AAAA;AAAA;;AAAA,EAAA,EAMzC,cAAc;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;AAAA;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;AAAA;AAAA;AAAA,CAAA;AA4FX,MAAM,eAAgB,CAAA;AAAA,EAC3B,aAAa,YAAA,CAAa,OAAkC,GAAA,EAAI,EAAA;AAC9D,IAAM,MAAA;AAAA,MACJ,kBAAA;AAAA,MACA,kBAAkB,EAAC;AAAA,MACnB,kBAAkB,EAAC;AAAA,MACnB,kBAAkB;AAAC,KACjB,GAAA,OAAA;AAEJ,IAAA,MAAM,cAAcA,2BAAoB,EAAA;AACxC,IAAA,IAAI,WAAe,IAAA,EAAA,IAAM,CAACC,sCAAA,EAAkC,EAAA;AAC1D,MAAA,MAAM,IAAI,KAAA;AAAA,QACR,CAAA;AAAA,2FAAA;AAAA,OAEF;AAAA;AAGF,IAA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AAQ,CAAA,gBAAA,EAAkB,IAAK,CAAA,SAAA,CAAU,MAAM,CAAC,CAAA;AAE9D,MAAA,IAAI,kBAAoB,EAAA;AACtB,QAAO,OAAA,OAAA,CAAQ,SAAS,CAA2C,yCAAA,CAAA,CAAA;AAAA;AAGrE,MAAO,OAAA,OAAA,CAAQ,SAAS,CAAqC,mCAAA,CAAA,CAAA;AAAA,KAC/D;AACA,IAAO,OAAA,MAAA;AAAA;AAEX;;;;"}
1
+ {"version":3,"file":"SecureTemplater.cjs.js","sources":["../../../src/lib/templating/SecureTemplater.ts"],"sourcesContent":["/*\n * Copyright 2021 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 */\n\nimport { Isolate } from 'isolated-vm';\nimport { resolvePackagePath } from '@backstage/backend-plugin-api';\nimport {\n TemplateFilter,\n TemplateGlobal,\n} from '@backstage/plugin-scaffolder-node';\nimport fs from 'fs-extra';\nimport { JsonValue } from '@backstage/types';\nimport { getMajorNodeVersion, isNoNodeSnapshotOptionProvided } from './helpers';\n\n// language=JavaScript\nconst mkScript = (nunjucksSource: string) => `\nconst { render, renderCompat } = (() => {\n const module = {};\n const process = { env: {} };\n const require = (pkg) => { if (pkg === 'events') { return function (){}; }};\n\n ${nunjucksSource}\n\n const env = module.exports.configure({\n autoescape: false,\n ...JSON.parse(nunjucksConfigs),\n tags: {\n variableStart: '\\${{',\n variableEnd: '}}',\n },\n });\n\n const compatEnv = module.exports.configure({\n autoescape: false,\n ...JSON.parse(nunjucksConfigs),\n tags: {\n variableStart: '{{',\n variableEnd: '}}',\n },\n });\n compatEnv.addFilter('jsonify', compatEnv.getFilter('dump'));\n\n const handleFunctionResult = (value) => {\n return value === '' ? undefined : JSON.parse(value);\n };\n for (const name of JSON.parse(availableTemplateFilters)) {\n env.addFilter(name, (...args) => handleFunctionResult(callFilter(name, args)));\n }\n for (const [name, value] of Object.entries(JSON.parse(availableTemplateGlobals))) {\n env.addGlobal(name, value);\n }\n for (const name of JSON.parse(availableTemplateCallbacks)) {\n env.addGlobal(name, (...args) => handleFunctionResult(callGlobal(name, args)));\n }\n\n let uninstallCompat = undefined;\n\n function render(str, values) {\n try {\n if (uninstallCompat) {\n uninstallCompat();\n uninstallCompat = undefined;\n }\n return env.renderString(str, JSON.parse(values));\n } catch (error) {\n // Make sure errors don't leak anything\n throw new Error(String(error.message));\n }\n }\n\n function renderCompat(str, values) {\n try {\n if (!uninstallCompat) {\n uninstallCompat = module.exports.installJinjaCompat();\n }\n return compatEnv.renderString(str, JSON.parse(values));\n } catch (error) {\n // Make sure errors don't leak anything\n throw new Error(String(error.message));\n }\n }\n\n return { render, renderCompat };\n})();\n`;\n\ninterface SecureTemplaterOptions {\n /* Enables jinja compatibility and the \"jsonify\" filter */\n cookiecutterCompat?: boolean;\n /* Extra user-provided nunjucks filters */\n templateFilters?: Record<string, TemplateFilter>;\n /* Extra user-provided nunjucks globals */\n templateGlobals?: Record<string, TemplateGlobal>;\n nunjucksConfigs?: { trimBlocks?: boolean; lstripBlocks?: boolean };\n}\n\nexport type SecureTemplateRenderer = (\n template: string,\n values: unknown,\n) => string;\n\nexport class SecureTemplater {\n static async loadRenderer(options: SecureTemplaterOptions = {}) {\n const {\n cookiecutterCompat,\n templateFilters = {},\n templateGlobals = {},\n nunjucksConfigs = {},\n } = options;\n\n const nodeVersion = getMajorNodeVersion();\n if (nodeVersion >= 20 && !isNoNodeSnapshotOptionProvided()) {\n throw new Error(\n `When using Node.js version 20 or newer, the scaffolder backend plugin requires that it be started with the --no-node-snapshot option. \n Please make sure that you have NODE_OPTIONS=--no-node-snapshot in your environment.`,\n );\n }\n\n const isolate = new Isolate({ memoryLimit: 128 });\n const context = await isolate.createContext();\n const contextGlobal = context.global;\n\n const nunjucksSource = await fs.readFile(\n resolvePackagePath(\n '@backstage/plugin-scaffolder-backend',\n 'assets/nunjucks.js.txt',\n ),\n 'utf-8',\n );\n\n const nunjucksScript = await isolate.compileScript(\n mkScript(nunjucksSource),\n );\n\n await contextGlobal.set('nunjucksConfigs', JSON.stringify(nunjucksConfigs));\n\n const availableFilters = Object.keys(templateFilters);\n\n await contextGlobal.set(\n 'availableTemplateFilters',\n JSON.stringify(availableFilters),\n );\n\n const globalCallbacks = [];\n const globalValues: Record<string, unknown> = {};\n for (const [name, value] of Object.entries(templateGlobals)) {\n if (typeof value === 'function') {\n globalCallbacks.push(name);\n } else {\n globalValues[name] = value;\n }\n }\n\n await contextGlobal.set(\n 'availableTemplateGlobals',\n JSON.stringify(globalValues),\n );\n await contextGlobal.set(\n 'availableTemplateCallbacks',\n JSON.stringify(globalCallbacks),\n );\n\n await contextGlobal.set(\n 'callFilter',\n (filterName: string, args: JsonValue[]) => {\n if (!Object.hasOwn(templateFilters, filterName)) {\n return '';\n }\n const [input, ...rest] = args;\n const rz = templateFilters[filterName](input, ...rest);\n return rz === undefined ? '' : JSON.stringify(rz);\n },\n );\n\n await contextGlobal.set(\n 'callGlobal',\n (globalName: string, args: JsonValue[]) => {\n if (!Object.hasOwn(templateGlobals, globalName)) {\n return '';\n }\n const global = templateGlobals[globalName];\n if (typeof global !== 'function') {\n return '';\n }\n const rz = global(...args);\n return rz === undefined ? '' : JSON.stringify(rz);\n },\n );\n\n await nunjucksScript.run(context);\n\n const render: SecureTemplateRenderer = (template, values) => {\n if (!context) {\n throw new Error('SecureTemplater has not been initialized');\n }\n\n contextGlobal.setSync('templateStr', String(template));\n contextGlobal.setSync('templateValues', JSON.stringify(values));\n\n if (cookiecutterCompat) {\n return context.evalSync(`renderCompat(templateStr, templateValues)`);\n }\n\n return context.evalSync(`render(templateStr, templateValues)`);\n };\n return render;\n }\n}\n"],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"}
@@ -1 +1 @@
1
- {"version":3,"file":"TemplateActionRegistry.cjs.js","sources":["../../../src/scaffolder/actions/TemplateActionRegistry.ts"],"sourcesContent":["/*\n * Copyright 2021 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 */\n\nimport { ConflictError, NotFoundError } from '@backstage/errors';\nimport { TemplateAction } from '@backstage/plugin-scaffolder-node';\n/**\n * Registry of all registered template actions.\n * @public\n */\nexport class TemplateActionRegistry {\n private readonly actions = new Map<string, TemplateAction>();\n\n register(action: TemplateAction<any, any, any>) {\n if (this.actions.has(action.id)) {\n throw new ConflictError(\n `Template action with ID '${action.id}' has already been registered`,\n );\n }\n\n this.actions.set(action.id, action);\n }\n\n get(actionId: string): TemplateAction<any, any, any> {\n const action = this.actions.get(actionId);\n if (!action) {\n throw new NotFoundError(\n `Template action with ID '${actionId}' is not registered. See https://backstage.io/docs/features/software-templates/builtin-actions/ on how to add a new action module.`,\n );\n }\n return action;\n }\n\n list(): TemplateAction<any, any, any>[] {\n return [...this.actions.values()];\n }\n}\n"],"names":["ConflictError","NotFoundError"],"mappings":";;;;AAsBO,MAAM,sBAAuB,CAAA;AAAA,EACjB,OAAA,uBAAc,GAA4B,EAAA;AAAA,EAE3D,SAAS,MAAuC,EAAA;AAC9C,IAAA,IAAI,IAAK,CAAA,OAAA,CAAQ,GAAI,CAAA,MAAA,CAAO,EAAE,CAAG,EAAA;AAC/B,MAAA,MAAM,IAAIA,oBAAA;AAAA,QACR,CAAA,yBAAA,EAA4B,OAAO,EAAE,CAAA,6BAAA;AAAA,OACvC;AAAA;AAGF,IAAA,IAAA,CAAK,OAAQ,CAAA,GAAA,CAAI,MAAO,CAAA,EAAA,EAAI,MAAM,CAAA;AAAA;AACpC,EAEA,IAAI,QAAiD,EAAA;AACnD,IAAA,MAAM,MAAS,GAAA,IAAA,CAAK,OAAQ,CAAA,GAAA,CAAI,QAAQ,CAAA;AACxC,IAAA,IAAI,CAAC,MAAQ,EAAA;AACX,MAAA,MAAM,IAAIC,oBAAA;AAAA,QACR,4BAA4B,QAAQ,CAAA,kIAAA;AAAA,OACtC;AAAA;AAEF,IAAO,OAAA,MAAA;AAAA;AACT,EAEA,IAAwC,GAAA;AACtC,IAAA,OAAO,CAAC,GAAG,IAAK,CAAA,OAAA,CAAQ,QAAQ,CAAA;AAAA;AAEpC;;;;"}
1
+ {"version":3,"file":"TemplateActionRegistry.cjs.js","sources":["../../../src/scaffolder/actions/TemplateActionRegistry.ts"],"sourcesContent":["/*\n * Copyright 2021 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 */\n\nimport { ConflictError, NotFoundError } from '@backstage/errors';\nimport { TemplateAction } from '@backstage/plugin-scaffolder-node';\n/**\n * Registry of all registered template actions.\n * @public\n * @deprecated this type is deprecated, and there will be a new way to create Workers in the next major version.\n */\nexport class TemplateActionRegistry {\n private readonly actions = new Map<string, TemplateAction>();\n\n register(action: TemplateAction<any, any, any>) {\n if (this.actions.has(action.id)) {\n throw new ConflictError(\n `Template action with ID '${action.id}' has already been registered`,\n );\n }\n\n this.actions.set(action.id, action);\n }\n\n get(actionId: string): TemplateAction<any, any, any> {\n const action = this.actions.get(actionId);\n if (!action) {\n throw new NotFoundError(\n `Template action with ID '${actionId}' is not registered. See https://backstage.io/docs/features/software-templates/builtin-actions/ on how to add a new action module.`,\n );\n }\n return action;\n }\n\n list(): TemplateAction<any, any, any>[] {\n return [...this.actions.values()];\n }\n}\n"],"names":["ConflictError","NotFoundError"],"mappings":";;;;AAuBO,MAAM,sBAAuB,CAAA;AAAA,EACjB,OAAA,uBAAc,GAA4B,EAAA;AAAA,EAE3D,SAAS,MAAuC,EAAA;AAC9C,IAAA,IAAI,IAAK,CAAA,OAAA,CAAQ,GAAI,CAAA,MAAA,CAAO,EAAE,CAAG,EAAA;AAC/B,MAAA,MAAM,IAAIA,oBAAA;AAAA,QACR,CAAA,yBAAA,EAA4B,OAAO,EAAE,CAAA,6BAAA;AAAA,OACvC;AAAA;AAGF,IAAA,IAAA,CAAK,OAAQ,CAAA,GAAA,CAAI,MAAO,CAAA,EAAA,EAAI,MAAM,CAAA;AAAA;AACpC,EAEA,IAAI,QAAiD,EAAA;AACnD,IAAA,MAAM,MAAS,GAAA,IAAA,CAAK,OAAQ,CAAA,GAAA,CAAI,QAAQ,CAAA;AACxC,IAAA,IAAI,CAAC,MAAQ,EAAA;AACX,MAAA,MAAM,IAAIC,oBAAA;AAAA,QACR,4BAA4B,QAAQ,CAAA,kIAAA;AAAA,OACtC;AAAA;AAEF,IAAO,OAAA,MAAA;AAAA;AACT,EAEA,IAAwC,GAAA;AACtC,IAAA,OAAO,CAAC,GAAG,IAAK,CAAA,OAAA,CAAQ,QAAQ,CAAA;AAAA;AAEpC;;;;"}
@@ -6,7 +6,7 @@ var fetch_examples = require('./fetch.examples.cjs.js');
6
6
 
7
7
  const id = "catalog:fetch";
8
8
  function createFetchCatalogEntityAction(options) {
9
- const { catalogClient, auth } = options;
9
+ const { catalog } = options;
10
10
  return pluginScaffolderNode.createTemplateAction({
11
11
  id,
12
12
  description: "Returns entity or entities from the catalog by entity reference(s)",
@@ -45,17 +45,13 @@ function createFetchCatalogEntityAction(options) {
45
45
  }
46
46
  throw new Error("Missing entity reference or references");
47
47
  }
48
- const { token } = await auth?.getPluginRequestToken({
49
- onBehalfOf: await ctx.getInitiatorCredentials(),
50
- targetPluginId: "catalog"
51
- }) ?? { token: ctx.secrets?.backstageToken };
52
48
  if (entityRef) {
53
- const entity = await catalogClient.getEntityByRef(
49
+ const entity = await catalog.getEntityByRef(
54
50
  catalogModel.stringifyEntityRef(
55
51
  catalogModel.parseEntityRef(entityRef, { defaultKind, defaultNamespace })
56
52
  ),
57
53
  {
58
- token
54
+ credentials: await ctx.getInitiatorCredentials()
59
55
  }
60
56
  );
61
57
  if (!entity && !optional) {
@@ -64,7 +60,7 @@ function createFetchCatalogEntityAction(options) {
64
60
  ctx.output("entity", entity ?? null);
65
61
  }
66
62
  if (entityRefs) {
67
- const entities = await catalogClient.getEntitiesByRefs(
63
+ const entities = await catalog.getEntitiesByRefs(
68
64
  {
69
65
  entityRefs: entityRefs.map(
70
66
  (ref) => catalogModel.stringifyEntityRef(
@@ -72,9 +68,7 @@ function createFetchCatalogEntityAction(options) {
72
68
  )
73
69
  )
74
70
  },
75
- {
76
- token
77
- }
71
+ { credentials: await ctx.getInitiatorCredentials() }
78
72
  );
79
73
  const finalEntities = entities.items.map((e, i) => {
80
74
  if (!e && !optional) {
@@ -1 +1 @@
1
- {"version":3,"file":"fetch.cjs.js","sources":["../../../../../src/scaffolder/actions/builtin/catalog/fetch.ts"],"sourcesContent":["/*\n * Copyright 2021 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 */\n\nimport { CatalogApi } from '@backstage/catalog-client';\nimport { createTemplateAction } from '@backstage/plugin-scaffolder-node';\nimport { parseEntityRef, stringifyEntityRef } from '@backstage/catalog-model';\nimport { examples } from './fetch.examples';\nimport { AuthService } from '@backstage/backend-plugin-api';\n\nconst id = 'catalog:fetch';\n\n/**\n * Returns entity or entities from the catalog by entity reference(s).\n *\n * @public\n */\nexport function createFetchCatalogEntityAction(options: {\n catalogClient: CatalogApi;\n auth?: AuthService;\n}) {\n const { catalogClient, auth } = options;\n\n return createTemplateAction({\n id,\n description:\n 'Returns entity or entities from the catalog by entity reference(s)',\n examples,\n supportsDryRun: true,\n schema: {\n input: {\n entityRef: z =>\n z\n .string({\n description: 'Entity reference of the entity to get',\n })\n .optional(),\n entityRefs: z =>\n z\n .array(z.string(), {\n description: 'Entity references of the entities to get',\n })\n .optional(),\n optional: z =>\n z\n .boolean({\n description:\n 'Allow the entity or entities to optionally exist. Default: false',\n })\n .optional(),\n defaultKind: z =>\n z.string({ description: 'The default kind' }).optional(),\n defaultNamespace: z =>\n z.string({ description: 'The default namespace' }).optional(),\n },\n output: {\n entity: z =>\n z\n .any({\n description:\n 'Object containing same values used in the Entity schema. Only when used with `entityRef` parameter.',\n })\n .optional(),\n entities: z =>\n z\n .array(\n z.any({\n description:\n 'Array containing objects with same values used in the Entity schema. Only when used with `entityRefs` parameter.',\n }),\n )\n .optional(),\n },\n },\n async handler(ctx) {\n const { entityRef, entityRefs, optional, defaultKind, defaultNamespace } =\n ctx.input;\n\n if (!entityRef && !entityRefs) {\n if (optional) {\n return;\n }\n throw new Error('Missing entity reference or references');\n }\n\n const { token } = (await auth?.getPluginRequestToken({\n onBehalfOf: await ctx.getInitiatorCredentials(),\n targetPluginId: 'catalog',\n })) ?? { token: ctx.secrets?.backstageToken };\n\n if (entityRef) {\n const entity = await catalogClient.getEntityByRef(\n stringifyEntityRef(\n parseEntityRef(entityRef, { defaultKind, defaultNamespace }),\n ),\n {\n token,\n },\n );\n\n if (!entity && !optional) {\n throw new Error(`Entity ${entityRef} not found`);\n }\n ctx.output('entity', entity ?? null);\n }\n\n if (entityRefs) {\n const entities = await catalogClient.getEntitiesByRefs(\n {\n entityRefs: entityRefs.map(ref =>\n stringifyEntityRef(\n parseEntityRef(ref, { defaultKind, defaultNamespace }),\n ),\n ),\n },\n {\n token,\n },\n );\n\n const finalEntities = entities.items.map((e, i) => {\n if (!e && !optional) {\n throw new Error(`Entity ${entityRefs[i]} not found`);\n }\n return e ?? null;\n });\n\n ctx.output('entities', finalEntities);\n }\n },\n });\n}\n"],"names":["createTemplateAction","examples","stringifyEntityRef","parseEntityRef"],"mappings":";;;;;;AAsBA,MAAM,EAAK,GAAA,eAAA;AAOJ,SAAS,+BAA+B,OAG5C,EAAA;AACD,EAAM,MAAA,EAAE,aAAe,EAAA,IAAA,EAAS,GAAA,OAAA;AAEhC,EAAA,OAAOA,yCAAqB,CAAA;AAAA,IAC1B,EAAA;AAAA,IACA,WACE,EAAA,oEAAA;AAAA,cACFC,uBAAA;AAAA,IACA,cAAgB,EAAA,IAAA;AAAA,IAChB,MAAQ,EAAA;AAAA,MACN,KAAO,EAAA;AAAA,QACL,SAAA,EAAW,CACT,CAAA,KAAA,CAAA,CACG,MAAO,CAAA;AAAA,UACN,WAAa,EAAA;AAAA,SACd,EACA,QAAS,EAAA;AAAA,QACd,YAAY,CACV,CAAA,KAAA,CAAA,CACG,KAAM,CAAA,CAAA,CAAE,QAAU,EAAA;AAAA,UACjB,WAAa,EAAA;AAAA,SACd,EACA,QAAS,EAAA;AAAA,QACd,QAAA,EAAU,CACR,CAAA,KAAA,CAAA,CACG,OAAQ,CAAA;AAAA,UACP,WACE,EAAA;AAAA,SACH,EACA,QAAS,EAAA;AAAA,QACd,WAAA,EAAa,OACX,CAAE,CAAA,MAAA,CAAO,EAAE,WAAa,EAAA,kBAAA,EAAoB,CAAA,CAAE,QAAS,EAAA;AAAA,QACzD,gBAAA,EAAkB,OAChB,CAAE,CAAA,MAAA,CAAO,EAAE,WAAa,EAAA,uBAAA,EAAyB,CAAA,CAAE,QAAS;AAAA,OAChE;AAAA,MACA,MAAQ,EAAA;AAAA,QACN,MAAA,EAA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MAAA,QAAA,GAAW,MAAM,aAAc,CAAA,iBAAA;AAAA,UACnC;AAAA,YACE,YAAY,UAAW,CAAA,GAAA;AAAA,cAAI,CACzB,GAAA,KAAAD,+BAAA;AAAA,gBACEC,2BAAe,CAAA,GAAA,EAAK,EAAE,WAAA,EAAa,kBAAkB;AAAA;AACvD;AACF,WACF;AAAA,UACA;AAAA,YACE;AAAA;AACF,SACF;AAEA,QAAA,MAAM,gBAAgB,QAAS,CAAA,KAAA,CAAM,GAAI,CAAA,CAAC,GAAG,CAAM,KAAA;AACjD,UAAI,IAAA,CAAC,CAAK,IAAA,CAAC,QAAU,EAAA;AACnB,YAAA,MAAM,IAAI,KAAM,CAAA,CAAA,OAAA,EAAU,UAAW,CAAA,CAAC,CAAC,CAAY,UAAA,CAAA,CAAA;AAAA;AAErD,UAAA,OAAO,CAAK,IAAA,IAAA;AAAA,SACb,CAAA;AAED,QAAI,GAAA,CAAA,MAAA,CAAO,YAAY,aAAa,CAAA;AAAA;AACtC;AACF,GACD,CAAA;AACH;;;;"}
1
+ {"version":3,"file":"fetch.cjs.js","sources":["../../../../../src/scaffolder/actions/builtin/catalog/fetch.ts"],"sourcesContent":["/*\n * Copyright 2021 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 */\n\nimport { createTemplateAction } from '@backstage/plugin-scaffolder-node';\nimport { parseEntityRef, stringifyEntityRef } from '@backstage/catalog-model';\nimport { examples } from './fetch.examples';\nimport { CatalogService } from '@backstage/plugin-catalog-node';\n\nconst id = 'catalog:fetch';\n\n/**\n * Returns entity or entities from the catalog by entity reference(s).\n *\n * @public\n */\nexport function createFetchCatalogEntityAction(options: {\n catalog: CatalogService;\n}) {\n const { catalog } = options;\n\n return createTemplateAction({\n id,\n description:\n 'Returns entity or entities from the catalog by entity reference(s)',\n examples,\n supportsDryRun: true,\n schema: {\n input: {\n entityRef: z =>\n z\n .string({\n description: 'Entity reference of the entity to get',\n })\n .optional(),\n entityRefs: z =>\n z\n .array(z.string(), {\n description: 'Entity references of the entities to get',\n })\n .optional(),\n optional: z =>\n z\n .boolean({\n description:\n 'Allow the entity or entities to optionally exist. Default: false',\n })\n .optional(),\n defaultKind: z =>\n z.string({ description: 'The default kind' }).optional(),\n defaultNamespace: z =>\n z.string({ description: 'The default namespace' }).optional(),\n },\n output: {\n entity: z =>\n z\n .any({\n description:\n 'Object containing same values used in the Entity schema. Only when used with `entityRef` parameter.',\n })\n .optional(),\n entities: z =>\n z\n .array(\n z.any({\n description:\n 'Array containing objects with same values used in the Entity schema. Only when used with `entityRefs` parameter.',\n }),\n )\n .optional(),\n },\n },\n async handler(ctx) {\n const { entityRef, entityRefs, optional, defaultKind, defaultNamespace } =\n ctx.input;\n\n if (!entityRef && !entityRefs) {\n if (optional) {\n return;\n }\n throw new Error('Missing entity reference or references');\n }\n\n if (entityRef) {\n const entity = await catalog.getEntityByRef(\n stringifyEntityRef(\n parseEntityRef(entityRef, { defaultKind, defaultNamespace }),\n ),\n {\n credentials: await ctx.getInitiatorCredentials(),\n },\n );\n\n if (!entity && !optional) {\n throw new Error(`Entity ${entityRef} not found`);\n }\n ctx.output('entity', entity ?? null);\n }\n\n if (entityRefs) {\n const entities = await catalog.getEntitiesByRefs(\n {\n entityRefs: entityRefs.map(ref =>\n stringifyEntityRef(\n parseEntityRef(ref, { defaultKind, defaultNamespace }),\n ),\n ),\n },\n { credentials: await ctx.getInitiatorCredentials() },\n );\n\n const finalEntities = entities.items.map((e, i) => {\n if (!e && !optional) {\n throw new Error(`Entity ${entityRefs[i]} not found`);\n }\n return e ?? null;\n });\n\n ctx.output('entities', finalEntities);\n }\n },\n });\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A,MAAM,IAAI,KAAM,CAAA,CAAA,OAAA,EAAU,UAAW,CAAA,CAAC,CAAC,CAAY,UAAA,CAAA,CAAA;AAAA;AAErD,UAAA,OAAO,CAAK,IAAA,IAAA;AAAA,SACb,CAAA;AAED,QAAI,GAAA,CAAA,MAAA,CAAO,YAAY,aAAa,CAAA;AAAA;AACtC;AACF,GACD,CAAA;AACH;;;;"}
@@ -7,65 +7,33 @@ var register_examples = require('./register.examples.cjs.js');
7
7
 
8
8
  const id = "catalog:register";
9
9
  function createCatalogRegisterAction(options) {
10
- const { catalogClient, integrations, auth } = options;
10
+ const { catalog, integrations } = options;
11
11
  return pluginScaffolderNode.createTemplateAction({
12
12
  id,
13
13
  description: "Registers entities from a catalog descriptor file in the workspace into the software catalog.",
14
14
  examples: register_examples.examples,
15
15
  schema: {
16
- input: {
17
- oneOf: [
18
- {
19
- type: "object",
20
- required: ["catalogInfoUrl"],
21
- properties: {
22
- catalogInfoUrl: {
23
- title: "Catalog Info URL",
24
- description: "An absolute URL pointing to the catalog info file location",
25
- type: "string"
26
- },
27
- optional: {
28
- title: "Optional",
29
- description: "Permit the registered location to optionally exist. Default: false",
30
- type: "boolean"
31
- }
32
- }
33
- },
34
- {
35
- type: "object",
36
- required: ["repoContentsUrl"],
37
- properties: {
38
- repoContentsUrl: {
39
- title: "Repository Contents URL",
40
- description: "An absolute URL pointing to the root of a repository directory tree",
41
- type: "string"
42
- },
43
- catalogInfoPath: {
44
- title: "Fetch URL",
45
- description: "A relative path from the repo root pointing to the catalog info file, defaults to /catalog-info.yaml",
46
- type: "string"
47
- },
48
- optional: {
49
- title: "Optional",
50
- description: "Permit the registered location to optionally exist. Default: false",
51
- type: "boolean"
52
- }
53
- }
54
- }
55
- ]
56
- },
57
- output: {
58
- type: "object",
59
- required: ["catalogInfoUrl"],
60
- properties: {
61
- entityRef: {
62
- type: "string"
63
- },
64
- catalogInfoUrl: {
65
- type: "string"
66
- }
67
- }
68
- }
16
+ input: (z) => z.union([
17
+ z.object({
18
+ catalogInfoUrl: z.string({
19
+ description: "An absolute URL pointing to the catalog info file location"
20
+ }),
21
+ optional: z.boolean({
22
+ description: "Permit the registered location to optionally exist. Default: false"
23
+ }).optional()
24
+ }),
25
+ z.object({
26
+ repoContentsUrl: z.string({
27
+ description: "An absolute URL pointing to the root of a repository directory tree"
28
+ }),
29
+ catalogInfoPath: z.string({
30
+ description: "A relative path from the repo root pointing to the catalog info file, defaults to /catalog-info.yaml"
31
+ }).optional(),
32
+ optional: z.boolean({
33
+ description: "Permit the registered location to optionally exist. Default: false"
34
+ }).optional()
35
+ })
36
+ ])
69
37
  },
70
38
  async handler(ctx) {
71
39
  const { input } = ctx;
@@ -86,17 +54,13 @@ function createCatalogRegisterAction(options) {
86
54
  });
87
55
  }
88
56
  ctx.logger.info(`Registering ${catalogInfoUrl} in the catalog`);
89
- const { token } = await auth?.getPluginRequestToken({
90
- onBehalfOf: await ctx.getInitiatorCredentials(),
91
- targetPluginId: "catalog"
92
- }) ?? { token: ctx.secrets?.backstageToken };
93
57
  try {
94
- await catalogClient.addLocation(
58
+ await catalog.addLocation(
95
59
  {
96
60
  type: "url",
97
61
  target: catalogInfoUrl
98
62
  },
99
- token ? { token } : {}
63
+ { credentials: await ctx.getInitiatorCredentials() }
100
64
  );
101
65
  } catch (e) {
102
66
  if (!input.optional) {
@@ -104,13 +68,13 @@ function createCatalogRegisterAction(options) {
104
68
  }
105
69
  }
106
70
  try {
107
- const result = await catalogClient.addLocation(
71
+ const result = await catalog.addLocation(
108
72
  {
109
73
  dryRun: true,
110
74
  type: "url",
111
75
  target: catalogInfoUrl
112
76
  },
113
- token ? { token } : {}
77
+ { credentials: await ctx.getInitiatorCredentials() }
114
78
  );
115
79
  if (result.entities.length) {
116
80
  const { entities } = result;
@@ -1 +1 @@
1
- {"version":3,"file":"register.cjs.js","sources":["../../../../../src/scaffolder/actions/builtin/catalog/register.ts"],"sourcesContent":["/*\n * Copyright 2021 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 */\n\nimport { InputError } from '@backstage/errors';\nimport { ScmIntegrations } from '@backstage/integration';\nimport { CatalogApi } from '@backstage/catalog-client';\nimport { stringifyEntityRef, Entity } from '@backstage/catalog-model';\nimport { createTemplateAction } from '@backstage/plugin-scaffolder-node';\nimport { examples } from './register.examples';\nimport { AuthService } from '@backstage/backend-plugin-api';\n\nconst id = 'catalog:register';\n\n/**\n * Registers entities from a catalog descriptor file in the workspace into the software catalog.\n * @public\n */\nexport function createCatalogRegisterAction(options: {\n catalogClient: CatalogApi;\n integrations: ScmIntegrations;\n auth?: AuthService;\n}) {\n const { catalogClient, integrations, auth } = options;\n\n return createTemplateAction<\n | { catalogInfoUrl: string; optional?: boolean }\n | { repoContentsUrl: string; catalogInfoPath?: string; optional?: boolean }\n >({\n id,\n description:\n 'Registers entities from a catalog descriptor file in the workspace into the software catalog.',\n examples,\n schema: {\n input: {\n oneOf: [\n {\n type: 'object',\n required: ['catalogInfoUrl'],\n properties: {\n catalogInfoUrl: {\n title: 'Catalog Info URL',\n description:\n 'An absolute URL pointing to the catalog info file location',\n type: 'string',\n },\n optional: {\n title: 'Optional',\n description:\n 'Permit the registered location to optionally exist. Default: false',\n type: 'boolean',\n },\n },\n },\n {\n type: 'object',\n required: ['repoContentsUrl'],\n properties: {\n repoContentsUrl: {\n title: 'Repository Contents URL',\n description:\n 'An absolute URL pointing to the root of a repository directory tree',\n type: 'string',\n },\n catalogInfoPath: {\n title: 'Fetch URL',\n description:\n 'A relative path from the repo root pointing to the catalog info file, defaults to /catalog-info.yaml',\n type: 'string',\n },\n optional: {\n title: 'Optional',\n description:\n 'Permit the registered location to optionally exist. Default: false',\n type: 'boolean',\n },\n },\n },\n ],\n },\n output: {\n type: 'object',\n required: ['catalogInfoUrl'],\n properties: {\n entityRef: {\n type: 'string',\n },\n catalogInfoUrl: {\n type: 'string',\n },\n },\n },\n },\n async handler(ctx) {\n const { input } = ctx;\n\n let catalogInfoUrl;\n if ('catalogInfoUrl' in input) {\n catalogInfoUrl = input.catalogInfoUrl;\n } else {\n const { repoContentsUrl, catalogInfoPath = '/catalog-info.yaml' } =\n input;\n const integration = integrations.byUrl(repoContentsUrl);\n if (!integration) {\n throw new InputError(\n `No integration found for host ${repoContentsUrl}`,\n );\n }\n\n catalogInfoUrl = integration.resolveUrl({\n base: repoContentsUrl,\n url: catalogInfoPath,\n });\n }\n\n ctx.logger.info(`Registering ${catalogInfoUrl} in the catalog`);\n\n const { token } = (await auth?.getPluginRequestToken({\n onBehalfOf: await ctx.getInitiatorCredentials(),\n targetPluginId: 'catalog',\n })) ?? { token: ctx.secrets?.backstageToken };\n\n try {\n // 1st try to register the location, this will throw an error if the location already exists (see catch)\n await catalogClient.addLocation(\n {\n type: 'url',\n target: catalogInfoUrl,\n },\n token ? { token } : {},\n );\n } catch (e) {\n if (!input.optional) {\n // if optional is false or unset, it is not allowed to register the same location twice, we rethrow the error\n throw e;\n }\n }\n\n try {\n // 2nd retry the registration as a dry run, this will not throw an error if the location already exists\n const result = await catalogClient.addLocation(\n {\n dryRun: true,\n type: 'url',\n target: catalogInfoUrl,\n },\n token ? { token } : {},\n );\n\n if (result.entities.length) {\n const { entities } = result;\n let entity: Entity | undefined;\n // prioritise 'Component' type as it is the most central kind of entity\n entity = entities.find(\n e =>\n !e.metadata.name.startsWith('generated-') &&\n e.kind === 'Component',\n );\n if (!entity) {\n entity = entities.find(\n e => !e.metadata.name.startsWith('generated-'),\n );\n }\n if (!entity) {\n entity = entities[0];\n }\n\n ctx.output('entityRef', stringifyEntityRef(entity));\n }\n } catch (e) {\n if (!input.optional) {\n throw e;\n }\n }\n\n ctx.output('catalogInfoUrl', catalogInfoUrl);\n },\n });\n}\n"],"names":["createTemplateAction","examples","InputError","stringifyEntityRef"],"mappings":";;;;;;;AAwBA,MAAM,EAAK,GAAA,kBAAA;AAMJ,SAAS,4BAA4B,OAIzC,EAAA;AACD,EAAA,MAAM,EAAE,aAAA,EAAe,YAAc,EAAA,IAAA,EAAS,GAAA,OAAA;AAE9C,EAAA,OAAOA,yCAGL,CAAA;AAAA,IACA,EAAA;AAAA,IACA,WACE,EAAA,+FAAA;AAAA,cACFC,0BAAA;AAAA,IACA,MAAQ,EAAA;AAAA,MACN,KAAO,EAAA;AAAA,QACL,KAAO,EAAA;AAAA,UACL;AAAA,YACE,IAAM,EAAA,QAAA;AAAA,YACN,QAAA,EAAU,CAAC,gBAAgB,CAAA;AAAA,YAC3B,UAAY,EAAA;AAAA,cACV,cAAgB,EAAA;AAAA,gBACd,KAAO,EAAA,kBAAA;AAAA,gBACP,WACE,EAAA,4DAAA;AAAA,gBACF,IAAM,EAAA;AAAA,eACR;AAAA,cACA,QAAU,EAAA;AAAA,gBACR,KAAO,EAAA,UAAA;AAAA,gBACP,WACE,EAAA,oEAAA;AAAA,gBACF,IAAM,EAAA;AAAA;AACR;AACF,WACF;AAAA,UACA;AAAA,YACE,IAAM,EAAA,QAAA;AAAA,YACN,QAAA,EAAU,CAAC,iBAAiB,CAAA;AAAA,YAC5B,UAAY,EAAA;AAAA,cACV,eAAiB,EAAA;AAAA,gBACf,KAAO,EAAA,yBAAA;AAAA,gBACP,WACE,EAAA,qEAAA;AAAA,gBACF,IAAM,EAAA;AAAA,eACR;AAAA,cACA,eAAiB,EAAA;AAAA,gBACf,KAAO,EAAA,WAAA;AAAA,gBACP,WACE,EAAA,sGAAA;AAAA,gBACF,IAAM,EAAA;AAAA,eACR;AAAA,cACA,QAAU,EAAA;AAAA,gBACR,KAAO,EAAA,UAAA;AAAA,gBACP,WACE,EAAA,oEAAA;AAAA,gBACF,IAAM,EAAA;AAAA;AACR;AACF;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BAAkB,cAAc,CAAA;AAAA;AAC7C,GACD,CAAA;AACH;;;;"}
1
+ {"version":3,"file":"register.cjs.js","sources":["../../../../../src/scaffolder/actions/builtin/catalog/register.ts"],"sourcesContent":["/*\n * Copyright 2021 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 */\n\nimport { InputError } from '@backstage/errors';\nimport { ScmIntegrations } from '@backstage/integration';\nimport { stringifyEntityRef, Entity } from '@backstage/catalog-model';\nimport { createTemplateAction } from '@backstage/plugin-scaffolder-node';\nimport { examples } from './register.examples';\nimport { CatalogService } from '@backstage/plugin-catalog-node';\n\nconst id = 'catalog:register';\n\n/**\n * Registers entities from a catalog descriptor file in the workspace into the software catalog.\n * @public\n */\nexport function createCatalogRegisterAction(options: {\n catalog: CatalogService;\n integrations: ScmIntegrations;\n}) {\n const { catalog, integrations } = options;\n\n return createTemplateAction({\n id,\n description:\n 'Registers entities from a catalog descriptor file in the workspace into the software catalog.',\n examples,\n schema: {\n input: z =>\n z.union([\n z.object({\n catalogInfoUrl: z.string({\n description:\n 'An absolute URL pointing to the catalog info file location',\n }),\n optional: z\n .boolean({\n description:\n 'Permit the registered location to optionally exist. Default: false',\n })\n .optional(),\n }),\n z.object({\n repoContentsUrl: z.string({\n description:\n 'An absolute URL pointing to the root of a repository directory tree',\n }),\n catalogInfoPath: z\n .string({\n description:\n 'A relative path from the repo root pointing to the catalog info file, defaults to /catalog-info.yaml',\n })\n .optional(),\n optional: z\n .boolean({\n description:\n 'Permit the registered location to optionally exist. Default: false',\n })\n .optional(),\n }),\n ]),\n },\n async handler(ctx) {\n const { input } = ctx;\n\n let catalogInfoUrl;\n if ('catalogInfoUrl' in input) {\n catalogInfoUrl = input.catalogInfoUrl;\n } else {\n const { repoContentsUrl, catalogInfoPath = '/catalog-info.yaml' } =\n input;\n const integration = integrations.byUrl(repoContentsUrl);\n if (!integration) {\n throw new InputError(\n `No integration found for host ${repoContentsUrl}`,\n );\n }\n\n catalogInfoUrl = integration.resolveUrl({\n base: repoContentsUrl,\n url: catalogInfoPath,\n });\n }\n\n ctx.logger.info(`Registering ${catalogInfoUrl} in the catalog`);\n\n try {\n // 1st try to register the location, this will throw an error if the location already exists (see catch)\n await catalog.addLocation(\n {\n type: 'url',\n target: catalogInfoUrl,\n },\n { credentials: await ctx.getInitiatorCredentials() },\n );\n } catch (e) {\n if (!input.optional) {\n // if optional is false or unset, it is not allowed to register the same location twice, we rethrow the error\n throw e;\n }\n }\n\n try {\n // 2nd retry the registration as a dry run, this will not throw an error if the location already exists\n const result = await catalog.addLocation(\n {\n dryRun: true,\n type: 'url',\n target: catalogInfoUrl,\n },\n { credentials: await ctx.getInitiatorCredentials() },\n );\n\n if (result.entities.length) {\n const { entities } = result;\n let entity: Entity | undefined;\n // prioritise 'Component' type as it is the most central kind of entity\n entity = entities.find(\n e =>\n !e.metadata.name.startsWith('generated-') &&\n e.kind === 'Component',\n );\n if (!entity) {\n entity = entities.find(\n e => !e.metadata.name.startsWith('generated-'),\n );\n }\n if (!entity) {\n entity = entities[0];\n }\n\n ctx.output('entityRef', stringifyEntityRef(entity));\n }\n } catch (e) {\n if (!input.optional) {\n throw e;\n }\n }\n\n ctx.output('catalogInfoUrl', catalogInfoUrl);\n },\n });\n}\n"],"names":["createTemplateAction","examples","InputError","stringifyEntityRef"],"mappings":";;;;;;;AAuBA,MAAM,EAAK,GAAA,kBAAA;AAMJ,SAAS,4BAA4B,OAGzC,EAAA;AACD,EAAM,MAAA,EAAE,OAAS,EAAA,YAAA,EAAiB,GAAA,OAAA;AAElC,EAAA,OAAOA,yCAAqB,CAAA;AAAA,IAC1B,EAAA;A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CAAA,WAAA,EAAaC,+BAAmB,CAAA,MAAM,CAAC,CAAA;AAAA;AACpD,eACO,CAAG,EAAA;AACV,QAAI,IAAA,CAAC,MAAM,QAAU,EAAA;AACnB,UAAM,MAAA,CAAA;AAAA;AACR;AAGF,MAAI,GAAA,CAAA,MAAA,CAAO,kBAAkB,cAAc,CAAA;AAAA;AAC7C,GACD,CAAA;AACH;;;;"}
@@ -4,7 +4,6 @@ var fs = require('fs-extra');
4
4
  var pluginScaffolderNode = require('@backstage/plugin-scaffolder-node');
5
5
  var yaml = require('yaml');
6
6
  var backendPluginApi = require('@backstage/backend-plugin-api');
7
- var z = require('zod');
8
7
  var write_examples = require('./write.examples.cjs.js');
9
8
 
10
9
  function _interopDefaultCompat (e) { return e && typeof e === 'object' && 'default' in e ? e : { default: e }; }
@@ -36,13 +35,13 @@ function createCatalogWriteAction() {
36
35
  id,
37
36
  description: "Writes the catalog-info.yaml for your template",
38
37
  schema: {
39
- input: z.z.object({
40
- filePath: z.z.string().optional().describe("Defaults to catalog-info.yaml"),
38
+ input: {
39
+ filePath: (z) => z.string().optional().describe("Defaults to catalog-info.yaml"),
41
40
  // TODO: this should reference an zod entity validator if it existed.
42
- entity: z.z.record(z.z.any()).describe(
41
+ entity: (z) => z.record(z.any()).describe(
43
42
  "You can provide the same values used in the Entity schema."
44
43
  )
45
- })
44
+ }
46
45
  },
47
46
  examples: write_examples.examples,
48
47
  supportsDryRun: true,
@@ -1 +1 @@
1
- {"version":3,"file":"write.cjs.js","sources":["../../../../../src/scaffolder/actions/builtin/catalog/write.ts"],"sourcesContent":["/*\n * Copyright 2021 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 */\n\nimport fs from 'fs-extra';\nimport { createTemplateAction } from '@backstage/plugin-scaffolder-node';\nimport * as yaml from 'yaml';\nimport { resolveSafeChildPath } from '@backstage/backend-plugin-api';\nimport { z } from 'zod';\nimport { examples } from './write.examples';\n\nconst id = 'catalog:write';\n\n/**\n * Writes a catalog descriptor file containing the provided entity to a path in the workspace.\n * @public\n */\n\nexport function createCatalogWriteAction() {\n return createTemplateAction({\n id,\n description: 'Writes the catalog-info.yaml for your template',\n schema: {\n input: z.object({\n filePath: z\n .string()\n .optional()\n .describe('Defaults to catalog-info.yaml'),\n // TODO: this should reference an zod entity validator if it existed.\n entity: z\n .record(z.any())\n .describe(\n 'You can provide the same values used in the Entity schema.',\n ),\n }),\n },\n examples,\n supportsDryRun: true,\n async handler(ctx) {\n const { filePath, entity } = ctx.input;\n const entityRef = ctx.templateInfo?.entityRef;\n const path = filePath ?? 'catalog-info.yaml';\n ctx.logger.info(`Writing ${path}`);\n\n await fs.outputFile(\n resolveSafeChildPath(ctx.workspacePath, path),\n yaml.stringify({\n ...entity,\n metadata: {\n ...entity.metadata,\n ...(entityRef\n ? {\n annotations: {\n ...entity.metadata.annotations,\n 'backstage.io/source-template': entityRef,\n },\n }\n : undefined),\n },\n }),\n );\n },\n });\n}\n"],"names":["createTemplateAction","z","examples","fs","resolveSafeChildPath","yaml"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAuBA,MAAM,EAAK,GAAA,eAAA;AAOJ,SAAS,wBAA2B,GAAA;AACzC,EAAA,OAAOA,yCAAqB,CAAA;AAAA,IAC1B,EAAA;AAAA,IACA,WAAa,EAAA,gDAAA;AAAA,IACb,MAAQ,EAAA;AAAA,MACN,KAAA,EAAOC,IAAE,MAAO,CAAA;AAAA,QACd,UAAUA,GACP,CAAA,MAAA,GACA,QAAS,EAAA,CACT,SAAS,+BAA+B,CAAA;AAAA;AAAA,QAE3C,QAAQA,GACL,CAAA,MAAA,CAAOA,GAAE,CAAA,GAAA,EAAK,CACd,CAAA,QAAA;AAAA,UACC;AAAA;AACF,OACH;AAAA,KACH;AAAA,cACAC,uBAAA;AAAA,IACA,cAAgB,EAAA,IAAA;AAAA,IAChB,MAAM,QAAQ,GAAK,EAAA;AACjB,MAAA,MAAM,EAAE,QAAA,EAAU,MAAO,EAAA,GAAI,GAAI,CAAA,KAAA;AACjC,MAAM,MAAA,SAAA,GAAY,IAAI,YAAc,EAAA,SAAA;AACpC,MAAA,MAAM,OAAO,QAAY,IAAA,mBAAA;AACzB,MAAA,GAAA,CAAI,MAAO,CAAA,IAAA,CAAK,CAAW,QAAA,EAAA,IAAI,CAAE,CAAA,CAAA;AAEjC,MAAA,MAAMC,mBAAG,CAAA,UAAA;AAAA,QACPC,qCAAA,CAAqB,GAAI,CAAA,aAAA,EAAe,IAAI,CAAA;AAAA,QAC5CC,gBAAK,SAAU,CAAA;AAAA,UACb,GAAG,MAAA;AAAA,UACH,QAAU,EAAA;AAAA,YACR,GAAG,MAAO,CAAA,QAAA;AAAA,YACV,GAAI,SACA,GAAA;AAAA,cACE,WAAa,EAAA;AAAA,gBACX,GAAG,OAAO,QAAS,CAAA,WAAA;AAAA,gBACnB,8BAAgC,EAAA;AAAA;AAClC,aAEF,GAAA,KAAA;AAAA;AACN,SACD;AAAA,OACH;AAAA;AACF,GACD,CAAA;AACH;;;;"}
1
+ {"version":3,"file":"write.cjs.js","sources":["../../../../../src/scaffolder/actions/builtin/catalog/write.ts"],"sourcesContent":["/*\n * Copyright 2021 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 */\n\nimport fs from 'fs-extra';\nimport { createTemplateAction } from '@backstage/plugin-scaffolder-node';\nimport * as yaml from 'yaml';\nimport { resolveSafeChildPath } from '@backstage/backend-plugin-api';\nimport { examples } from './write.examples';\n\nconst id = 'catalog:write';\n\n/**\n * Writes a catalog descriptor file containing the provided entity to a path in the workspace.\n * @public\n */\n\nexport function createCatalogWriteAction() {\n return createTemplateAction({\n id,\n description: 'Writes the catalog-info.yaml for your template',\n schema: {\n input: {\n filePath: z =>\n z.string().optional().describe('Defaults to catalog-info.yaml'),\n // TODO: this should reference an zod entity validator if it existed.\n entity: z =>\n z\n .record(z.any())\n .describe(\n 'You can provide the same values used in the Entity schema.',\n ),\n },\n },\n examples,\n supportsDryRun: true,\n async handler(ctx) {\n const { filePath, entity } = ctx.input;\n const entityRef = ctx.templateInfo?.entityRef;\n const path = filePath ?? 'catalog-info.yaml';\n ctx.logger.info(`Writing ${path}`);\n\n await fs.outputFile(\n resolveSafeChildPath(ctx.workspacePath, path),\n yaml.stringify({\n ...entity,\n metadata: {\n ...entity.metadata,\n ...(entityRef\n ? {\n annotations: {\n ...entity.metadata.annotations,\n 'backstage.io/source-template': entityRef,\n },\n }\n : undefined),\n },\n }),\n );\n },\n });\n}\n"],"names":["createTemplateAction","examples","fs","resolveSafeChildPath","yaml"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAsBA,MAAM,EAAK,GAAA,eAAA;AAOJ,SAAS,wBAA2B,GAAA;AACzC,EAAA,OAAOA,yCAAqB,CAAA;AAAA,IAC1B,EAAA;AAAA,IACA,WAAa,EAAA,gDAAA;AAAA,IACb,MAAQ,EAAA;AAAA,MACN,KAAO,EAAA;AAAA,QACL,QAAA,EAAU,OACR,CAAE,CAAA,MAAA,GAAS,QAAS,EAAA,CAAE,SAAS,+BAA+B,CAAA;AAAA;AAAA,QAEhE,QAAQ,CACN,CAAA,KAAA,CAAA,CACG,OAAO,CAAE,CAAA,GAAA,EAAK,CACd,CAAA,QAAA;AAAA,UACC;AAAA;AACF;AACN,KACF;AAAA,cACAC,uBAAA;AAAA,IACA,cAAgB,EAAA,IAAA;AAAA,IAChB,MAAM,QAAQ,GAAK,EAAA;AACjB,MAAA,MAAM,EAAE,QAAA,EAAU,MAAO,EAAA,GAAI,GAAI,CAAA,KAAA;AACjC,MAAM,MAAA,SAAA,GAAY,IAAI,YAAc,EAAA,SAAA;AACpC,MAAA,MAAM,OAAO,QAAY,IAAA,mBAAA;AACzB,MAAA,GAAA,CAAI,MAAO,CAAA,IAAA,CAAK,CAAW,QAAA,EAAA,IAAI,CAAE,CAAA,CAAA;AAEjC,MAAA,MAAMC,mBAAG,CAAA,UAAA;AAAA,QACPC,qCAAA,CAAqB,GAAI,CAAA,aAAA,EAAe,IAAI,CAAA;AAAA,QAC5CC,gBAAK,SAAU,CAAA;AAAA,UACb,GAAG,MAAA;AAAA,UACH,QAAU,EAAA;AAAA,YACR,GAAG,MAAO,CAAA,QAAA;AAAA,YACV,GAAI,SACA,GAAA;AAAA,cACE,WAAa,EAAA;AAAA,gBACX,GAAG,OAAO,QAAS,CAAA,WAAA;AAAA,gBACnB,8BAAgC,EAAA;AAAA;AAClC,aAEF,GAAA,KAAA;AAAA;AACN,SACD;AAAA,OACH;AAAA;AACF,GACD,CAAA;AACH;;;;"}
@@ -5,7 +5,6 @@ var path = require('path');
5
5
  var pluginScaffolderNode = require('@backstage/plugin-scaffolder-node');
6
6
  var log_examples = require('./log.examples.cjs.js');
7
7
  var fs = require('fs');
8
- var z = require('zod');
9
8
 
10
9
  function _interopDefaultCompat (e) { return e && typeof e === 'object' && 'default' in e ? e : { default: e }; }
11
10
 
@@ -18,12 +17,12 @@ function createDebugLogAction() {
18
17
  description: "Writes a message into the log and/or lists all files in the workspace.",
19
18
  examples: log_examples.examples,
20
19
  schema: {
21
- input: z.z.object({
22
- message: z.z.string({ description: "Message to output." }).optional(),
23
- listWorkspace: z.z.union([z.z.boolean(), z.z.enum(["with-filenames", "with-contents"])], {
20
+ input: {
21
+ message: (z) => z.string({ description: "Message to output." }).optional(),
22
+ listWorkspace: (z) => z.union([z.boolean(), z.enum(["with-filenames", "with-contents"])], {
24
23
  description: 'List all files in the workspace. If used with "with-contents", also the file contents are listed.'
25
24
  }).optional()
26
- })
25
+ }
27
26
  },
28
27
  supportsDryRun: true,
29
28
  async handler(ctx) {
@@ -1 +1 @@
1
- {"version":3,"file":"log.cjs.js","sources":["../../../../../src/scaffolder/actions/builtin/debug/log.ts"],"sourcesContent":["/*\n * Copyright 2021 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 */\n\nimport { readdir, stat } from 'fs-extra';\nimport { join, relative } from 'path';\nimport { createTemplateAction } from '@backstage/plugin-scaffolder-node';\nimport { examples } from './log.examples';\nimport fs from 'fs';\nimport { z } from 'zod';\n\nconst id = 'debug:log';\n\n/**\n * Writes a message into the log or lists all files in the workspace\n *\n * @remarks\n *\n * This task is useful for local development and testing of both the scaffolder\n * and scaffolder templates.\n *\n * @public\n */\nexport function createDebugLogAction() {\n return createTemplateAction<{\n message?: string;\n listWorkspace?: boolean | 'with-filenames' | 'with-contents';\n }>({\n id,\n description:\n 'Writes a message into the log and/or lists all files in the workspace.',\n examples,\n schema: {\n input: z.object({\n message: z.string({ description: 'Message to output.' }).optional(),\n listWorkspace: z\n .union([z.boolean(), z.enum(['with-filenames', 'with-contents'])], {\n description:\n 'List all files in the workspace. If used with \"with-contents\", also the file contents are listed.',\n })\n .optional(),\n }),\n },\n supportsDryRun: true,\n async handler(ctx) {\n ctx.logger.info(JSON.stringify(ctx.input, null, 2));\n\n if (ctx.input?.message) {\n ctx.logger.info(ctx.input.message);\n }\n\n if (ctx.input?.listWorkspace) {\n const files = await recursiveReadDir(ctx.workspacePath);\n ctx.logger.info(\n `Workspace:\\n${files\n .map(f => {\n const relativePath = relative(ctx.workspacePath, f);\n if (ctx.input?.listWorkspace === 'with-contents') {\n const content = fs.readFileSync(f, 'utf-8');\n return ` - ${relativePath}:\\n\\n ${content}`;\n }\n return ` - ${relativePath}`;\n })\n .join('\\n')}`,\n );\n }\n },\n });\n}\n\nexport async function recursiveReadDir(dir: string): Promise<string[]> {\n const subdirs = await readdir(dir);\n const files = await Promise.all(\n subdirs.map(async subdir => {\n const res = join(dir, subdir);\n return (await stat(res)).isDirectory() ? recursiveReadDir(res) : [res];\n }),\n );\n return files.reduce((a, f) => a.concat(f), []);\n}\n"],"names":["createTemplateAction","examples","z","relative","fs","readdir","join","stat"],"mappings":";;;;;;;;;;;;;AAuBA,MAAM,EAAK,GAAA,WAAA;AAYJ,SAAS,oBAAuB,GAAA;AACrC,EAAA,OAAOA,yCAGJ,CAAA;AAAA,IACD,EAAA;AAAA,IACA,WACE,EAAA,wEAAA;AAAA,cACFC,qBAAA;AAAA,IACA,MAAQ,EAAA;AAAA,MACN,KAAA,EAAOC,IAAE,MAAO,CAAA;AAAA,QACd,OAAA,EAASA,IAAE,MAAO,CAAA,EAAE,aAAa,oBAAqB,EAAC,EAAE,QAAS,EAAA;AAAA,QAClE,aAAe,EAAAA,GAAA,CACZ,KAAM,CAAA,CAACA,IAAE,OAAQ,EAAA,EAAGA,GAAE,CAAA,IAAA,CAAK,CAAC,gBAAA,EAAkB,eAAe,CAAC,CAAC,CAAG,EAAA;AAAA,UACjE,WACE,EAAA;AAAA,SACH,EACA,QAAS;AAAA,OACb;AAAA,KACH;AAAA,IACA,cAAgB,EAAA,IAAA;AAAA,IAChB,MAAM,QAAQ,GAAK,EAAA;AACjB,MAAI,GAAA,CAAA,MAAA,CAAO,KAAK,IAAK,CAAA,SAAA,CAAU,IAAI,KAAO,EAAA,IAAA,EAAM,CAAC,CAA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A;AAAA,KACtE;AAAA,GACH;AACA,EAAO,OAAA,KAAA,CAAM,MAAO,CAAA,CAAC,CAAG,EAAA,CAAA,KAAM,EAAE,MAAO,CAAA,CAAC,CAAG,EAAA,EAAE,CAAA;AAC/C;;;;;"}
1
+ {"version":3,"file":"log.cjs.js","sources":["../../../../../src/scaffolder/actions/builtin/debug/log.ts"],"sourcesContent":["/*\n * Copyright 2021 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 */\n\nimport { readdir, stat } from 'fs-extra';\nimport { join, relative } from 'path';\nimport { createTemplateAction } from '@backstage/plugin-scaffolder-node';\nimport { examples } from './log.examples';\nimport fs from 'fs';\n\nconst id = 'debug:log';\n\n/**\n * Writes a message into the log or lists all files in the workspace\n *\n * @remarks\n *\n * This task is useful for local development and testing of both the scaffolder\n * and scaffolder templates.\n *\n * @public\n */\nexport function createDebugLogAction() {\n return createTemplateAction({\n id,\n description:\n 'Writes a message into the log and/or lists all files in the workspace.',\n examples,\n schema: {\n input: {\n message: z =>\n z.string({ description: 'Message to output.' }).optional(),\n listWorkspace: z =>\n z\n .union([z.boolean(), z.enum(['with-filenames', 'with-contents'])], {\n description:\n 'List all files in the workspace. If used with \"with-contents\", also the file contents are listed.',\n })\n .optional(),\n },\n },\n supportsDryRun: true,\n async handler(ctx) {\n ctx.logger.info(JSON.stringify(ctx.input, null, 2));\n\n if (ctx.input?.message) {\n ctx.logger.info(ctx.input.message);\n }\n\n if (ctx.input?.listWorkspace) {\n const files = await recursiveReadDir(ctx.workspacePath);\n ctx.logger.info(\n `Workspace:\\n${files\n .map(f => {\n const relativePath = relative(ctx.workspacePath, f);\n if (ctx.input?.listWorkspace === 'with-contents') {\n const content = fs.readFileSync(f, 'utf-8');\n return ` - ${relativePath}:\\n\\n ${content}`;\n }\n return ` - ${relativePath}`;\n })\n .join('\\n')}`,\n );\n }\n },\n });\n}\n\nexport async function recursiveReadDir(dir: string): Promise<string[]> {\n const subdirs = await readdir(dir);\n const files = await Promise.all(\n subdirs.map(async subdir => {\n const res = join(dir, subdir);\n return (await stat(res)).isDirectory() ? recursiveReadDir(res) : [res];\n }),\n );\n return files.reduce((a, f) => a.concat(f), []);\n}\n"],"names":["createTemplateAction","examples","relative","fs","readdir","join","stat"],"mappings":";;;;;;;;;;;;AAsBA,MAAM,EAAK,GAAA,WAAA;AAYJ,SAAS,oBAAuB,GAAA;AACrC,EAAA,OAAOA,yCAAqB,CAAA;AAAA,IAC1B,EAAA;AAAA,IACA,WACE,EAAA,wEAAA;AAAA,cACFC,qBAAA;AAAA,IACA,MAAQ,EAAA;AAAA,MACN,KAAO,EAAA;AAAA,QACL,OAAA,EAAS,OACP,CAAE,CAAA,MAAA,CAAO,EAAE,WAAa,EAAA,oBAAA,EAAsB,CAAA,CAAE,QAAS,EAAA;AAAA,QAC3D,aAAe,EAAA,CAAA,CAAA,KACb,CACG,CAAA,KAAA,CAAM,CAAC,CAAE,CAAA,OAAA,EAAW,EAAA,CAAA,CAAE,KAAK,CAAC,gBAAA,EAAkB,eAAe,CAAC,CAAC,CAAG,EAAA;AAAA,UACjE,WACE,EAAA;AAAA,SACH,EACA,QAAS;AAAA;AAChB,KACF;AAAA,IACA,cAAgB,EAAA,IAAA;AAAA,IAChB,MAAM,QAAQ,GAAK,EAAA;AACjB,MAAI,GAAA,CAAA,MAAA,CAAO,KAAK,IAAK,CAAA,SAAA,CAAU,IAAI,KAAO,EAAA,IAAA,EAAM,CAAC,CAAC,CAAA;AAElD,MAAI,IAAA,GAAA,CAAI,OAAO,OAAS,EAAA;AACtB,QAAA,GAAA,CAAI,MAAO,CAAA,IAAA,CAAK,GA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,CAAA,CAAC,CAAG,EAAA,EAAE,CAAA;AAC/C;;;;;"}
@@ -22,21 +22,15 @@ function createWaitAction(options) {
22
22
  examples: wait_examples.examples,
23
23
  schema: {
24
24
  input: {
25
- type: "object",
26
- properties: {
27
- minutes: {
28
- title: "Waiting period in minutes.",
29
- type: "number"
30
- },
31
- seconds: {
32
- title: "Waiting period in seconds.",
33
- type: "number"
34
- },
35
- milliseconds: {
36
- title: "Waiting period in milliseconds.",
37
- type: "number"
38
- }
39
- }
25
+ minutes: (z) => z.number({
26
+ description: "Waiting period in minutes."
27
+ }).optional(),
28
+ seconds: (z) => z.number({
29
+ description: "Waiting period in seconds."
30
+ }).optional(),
31
+ milliseconds: (z) => z.number({
32
+ description: "Waiting period in milliseconds."
33
+ }).optional()
40
34
  }
41
35
  },
42
36
  async handler(ctx) {
@@ -1 +1 @@
1
- {"version":3,"file":"wait.cjs.js","sources":["../../../../../src/scaffolder/actions/builtin/debug/wait.ts"],"sourcesContent":["/*\n * Copyright 2021 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 */\n\nimport { createTemplateAction } from '@backstage/plugin-scaffolder-node';\nimport { HumanDuration } from '@backstage/types';\nimport { Duration } from 'luxon';\nimport { examples } from './wait.examples';\n\nconst id = 'debug:wait';\n\nconst MAX_WAIT_TIME_IN_ISO = 'T00:10:00';\n\n/**\n * Waits for a certain period of time.\n *\n * @remarks\n *\n * This task is useful to give some waiting time for manual intervention.\n * Has to be used in a combination with other actions.\n *\n * @public\n */\nexport function createWaitAction(options?: {\n maxWaitTime?: Duration | HumanDuration;\n}) {\n const toDuration = (\n maxWaitTime: Duration | HumanDuration | undefined,\n ): Duration => {\n if (maxWaitTime) {\n if (maxWaitTime instanceof Duration) {\n return maxWaitTime;\n }\n return Duration.fromObject(maxWaitTime);\n }\n return Duration.fromISOTime(MAX_WAIT_TIME_IN_ISO);\n };\n\n return createTemplateAction<HumanDuration>({\n id,\n description: 'Waits for a certain period of time.',\n examples,\n schema: {\n input: {\n type: 'object',\n properties: {\n minutes: {\n title: 'Waiting period in minutes.',\n type: 'number',\n },\n seconds: {\n title: 'Waiting period in seconds.',\n type: 'number',\n },\n milliseconds: {\n title: 'Waiting period in milliseconds.',\n type: 'number',\n },\n },\n },\n },\n async handler(ctx) {\n const delayTime = Duration.fromObject(ctx.input);\n const maxWait = toDuration(options?.maxWaitTime);\n\n if (delayTime.minus(maxWait).toMillis() > 0) {\n throw new Error(\n `Waiting duration is longer than the maximum threshold of ${maxWait.toHuman()}`,\n );\n }\n\n await new Promise(resolve => {\n const controller = new AbortController();\n const timeoutHandle = setTimeout(abort, delayTime.toMillis());\n ctx.signal?.addEventListener('abort', abort);\n\n function abort() {\n ctx.signal?.removeEventListener('abort', abort);\n clearTimeout(timeoutHandle!);\n controller.abort();\n resolve('finished');\n }\n });\n },\n });\n}\n"],"names":["Duration","createTemplateAction","examples"],"mappings":";;;;;;AAqBA,MAAM,EAAK,GAAA,YAAA;AAEX,MAAM,oBAAuB,GAAA,WAAA;AAYtB,SAAS,iBAAiB,OAE9B,EAAA;AACD,EAAM,MAAA,UAAA,GAAa,CACjB,WACa,KAAA;AACb,IAAA,IAAI,WAAa,EAAA;AACf,MAAA,IAAI,uBAAuBA,cAAU,EAAA;AACnC,QAAO,OAAA,WAAA;AAAA;AAET,MAAO,OAAAA,cAAA,CAAS,WAAW,WAAW,CAAA;AAAA;AAExC,IAAO,OAAAA,cAAA,CAAS,YAAY,oBAAoB,CAAA;AAAA,GAClD;AAEA,EAAA,OAAOC,yCAAoC,CAAA;AAAA,IACzC,EAAA;AAAA,IACA,WAAa,EAAA,qCAAA;AA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AU,CAAA;AAAA;AACpB,OACD,CAAA;AAAA;AACH,GACD,CAAA;AACH;;;;"}
1
+ {"version":3,"file":"wait.cjs.js","sources":["../../../../../src/scaffolder/actions/builtin/debug/wait.ts"],"sourcesContent":["/*\n * Copyright 2021 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 */\n\nimport { createTemplateAction } from '@backstage/plugin-scaffolder-node';\nimport { HumanDuration } from '@backstage/types';\nimport { Duration } from 'luxon';\nimport { examples } from './wait.examples';\n\nconst id = 'debug:wait';\n\nconst MAX_WAIT_TIME_IN_ISO = 'T00:10:00';\n\n/**\n * Waits for a certain period of time.\n *\n * @remarks\n *\n * This task is useful to give some waiting time for manual intervention.\n * Has to be used in a combination with other actions.\n *\n * @public\n */\nexport function createWaitAction(options?: {\n maxWaitTime?: Duration | HumanDuration;\n}) {\n const toDuration = (\n maxWaitTime: Duration | HumanDuration | undefined,\n ): Duration => {\n if (maxWaitTime) {\n if (maxWaitTime instanceof Duration) {\n return maxWaitTime;\n }\n return Duration.fromObject(maxWaitTime);\n }\n return Duration.fromISOTime(MAX_WAIT_TIME_IN_ISO);\n };\n\n return createTemplateAction({\n id,\n description: 'Waits for a certain period of time.',\n examples,\n schema: {\n input: {\n minutes: z =>\n z\n .number({\n description: 'Waiting period in minutes.',\n })\n .optional(),\n seconds: z =>\n z\n .number({\n description: 'Waiting period in seconds.',\n })\n .optional(),\n milliseconds: z =>\n z\n .number({\n description: 'Waiting period in milliseconds.',\n })\n .optional(),\n },\n },\n async handler(ctx) {\n const delayTime = Duration.fromObject(ctx.input);\n const maxWait = toDuration(options?.maxWaitTime);\n\n if (delayTime.minus(maxWait).toMillis() > 0) {\n throw new Error(\n `Waiting duration is longer than the maximum threshold of ${maxWait.toHuman()}`,\n );\n }\n\n await new Promise(resolve => {\n const controller = new AbortController();\n const timeoutHandle = setTimeout(abort, delayTime.toMillis());\n ctx.signal?.addEventListener('abort', abort);\n\n function abort() {\n ctx.signal?.removeEventListener('abort', abort);\n clearTimeout(timeoutHandle!);\n controller.abort();\n resolve('finished');\n }\n });\n },\n });\n}\n"],"names":["Duration","createTemplateAction","examples"],"mappings":";;;;;;AAqBA,MAAM,EAAK,GAAA,YAAA;AAEX,MAAM,oBAAuB,GAAA,WAAA;AAYtB,SAAS,iBAAiB,OAE9B,EAAA;AACD,EAAM,MAAA,UAAA,GAAa,CACjB,WACa,KAAA;AACb,IAAA,IAAI,WAAa,EAAA;AACf,MAAA,IAAI,uBAAuBA,cAAU,EAAA;AACnC,QAAO,OAAA,WAAA;AAAA;AAET,MAAO,OAAAA,cAAA,CAAS,WAAW,WAAW,CAAA;AAAA;AAExC,IAAO,OAAAA,cAAA,CAAS,YAAY,oBAAoB,CAAA;AAAA,GAClD;AAEA,EAAA,OAAOC,yCAAqB,CAAA;AAAA,IAC1B,EAAA;AAAA,IACA,WAAa,EAAA,qCAAA;AAAA,cACbC,sBAAA;AAAA,IACA,MAAQ,EAAA;AAAA,MACN,KAAO,EAAA;AAAA,QACL,OAAA,EAAS,CACP,CAAA,KAAA,CAAA,CACG,MAAO,CAAA;AAAA,UACN,WAAa,EAAA;AAAA,SACd,EACA,QAAS,EAAA;AAAA,QACd,OAAA,EAAS,CACP,CAAA,KAAA,CAAA,CACG,MAAO,CAAA;AAAA,UACN,WAAa,EAAA;AAAA,SACd,EACA,QAAS,EAAA;AAAA,QACd,YAAA,EAAc,CACZ,CAAA,KAAA,CAAA,CACG,MAAO,CAAA;AAAA,UACN,WAAa,EAAA;AAAA,SACd,EACA,QAAS;AAAA;AAChB,KACF;AAAA,IACA,MAAM,QAAQ,GAAK,EAAA;AACjB,MAAA,MAAM,SAAY,GAAAF,cAAA,CAAS,UAAW,CAAA,GAAA,CAAI,KAAK,CAAA;AAC/C,MAAM,MAAA,OAAA,GAAU,UAAW,CAAA,OAAA,EAAS,WAAW,CAAA;AAE/C,MAAA,IAAI,UAAU,KAAM,CAAA,OAAO,CAAE,CAAA,QAAA,KAAa,CAAG,EAAA;AAC3C,QAAA,MAAM,IAAI,KAAA;AAAA,UACR,CAAA,yDAAA,EAA4D,OAAQ,CAAA,OAAA,EAAS,CAAA;AAAA,SAC/E;AAAA;AAGF,MAAM,MAAA,IAAI,QAAQ,CAAW,OAAA,KAAA;AAC3B,QAAM,MAAA,UAAA,GAAa,IAAI,eAAgB,EAAA;AACvC,QAAA,MAAM,aAAgB,GAAA,UAAA,CAAW,KAAO,EAAA,SAAA,CAAU,UAAU,CAAA;AAC5D,QAAI,GAAA,CAAA,MAAA,EAAQ,gBAAiB,CAAA,OAAA,EAAS,KAAK,CAAA;AAE3C,QAAA,SAAS,KAAQ,GAAA;AACf,UAAI,GAAA,CAAA,MAAA,EAAQ,mBAAoB,CAAA,OAAA,EAAS,KAAK,CAAA;AAC9C,UAAA,YAAA,CAAa,aAAc,CAAA;AAC3B,UAAA,UAAA,CAAW,KAAM,EAAA;AACjB,UAAA,OAAA,CAAQ,UAAU,CAAA;AAAA;AACpB,OACD,CAAA;AAAA;AACH,GACD,CAAA;AACH;;;;"}
@@ -13,25 +13,15 @@ function createFetchPlainAction(options) {
13
13
  description: "Downloads content and places it in the workspace, or optionally in a subdirectory specified by the `targetPath` input option.",
14
14
  schema: {
15
15
  input: {
16
- type: "object",
17
- required: ["url"],
18
- properties: {
19
- url: {
20
- title: "Fetch URL",
21
- description: "Relative path or absolute URL pointing to the directory tree to fetch",
22
- type: "string"
23
- },
24
- targetPath: {
25
- title: "Target Path",
26
- description: "Target path within the working directory to download the contents to.",
27
- type: "string"
28
- },
29
- token: {
30
- title: "Token",
31
- description: "An optional token to use for authentication when reading the resources.",
32
- type: "string"
33
- }
34
- }
16
+ url: (z) => z.string({
17
+ description: "Relative path or absolute URL pointing to the directory tree to fetch"
18
+ }),
19
+ targetPath: (z) => z.string({
20
+ description: "Target path within the working directory to download the contents to."
21
+ }).optional(),
22
+ token: (z) => z.string({
23
+ description: "An optional token to use for authentication when reading the resources."
24
+ }).optional()
35
25
  }
36
26
  },
37
27
  supportsDryRun: true,
@@ -1 +1 @@
1
- {"version":3,"file":"plain.cjs.js","sources":["../../../../../src/scaffolder/actions/builtin/fetch/plain.ts"],"sourcesContent":["/*\n * Copyright 2021 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 */\n\nimport {\n resolveSafeChildPath,\n UrlReaderService,\n} from '@backstage/backend-plugin-api';\nimport { ScmIntegrations } from '@backstage/integration';\nimport { examples } from './plain.examples';\n\nimport {\n createTemplateAction,\n fetchContents,\n} from '@backstage/plugin-scaffolder-node';\n\nexport const ACTION_ID = 'fetch:plain';\n\n/**\n * Downloads content and places it in the workspace, or optionally\n * in a subdirectory specified by the 'targetPath' input option.\n * @public\n */\nexport function createFetchPlainAction(options: {\n reader: UrlReaderService;\n integrations: ScmIntegrations;\n}) {\n const { reader, integrations } = options;\n\n return createTemplateAction<{\n url: string;\n targetPath?: string;\n token?: string;\n }>({\n id: ACTION_ID,\n examples,\n description:\n 'Downloads content and places it in the workspace, or optionally in a subdirectory specified by the `targetPath` input option.',\n schema: {\n input: {\n type: 'object',\n required: ['url'],\n properties: {\n url: {\n title: 'Fetch URL',\n description:\n 'Relative path or absolute URL pointing to the directory tree to fetch',\n type: 'string',\n },\n targetPath: {\n title: 'Target Path',\n description:\n 'Target path within the working directory to download the contents to.',\n type: 'string',\n },\n token: {\n title: 'Token',\n description:\n 'An optional token to use for authentication when reading the resources.',\n type: 'string',\n },\n },\n },\n },\n supportsDryRun: true,\n async handler(ctx) {\n ctx.logger.info('Fetching plain content from remote URL');\n\n // Finally move the template result into the task workspace\n const targetPath = ctx.input.targetPath ?? './';\n const outputPath = resolveSafeChildPath(ctx.workspacePath, targetPath);\n\n await fetchContents({\n reader,\n integrations,\n baseUrl: ctx.templateInfo?.baseUrl,\n fetchUrl: ctx.input.url,\n outputPath,\n token: ctx.input.token,\n });\n },\n });\n}\n"],"names":["createTemplateAction","examples","resolveSafeChildPath","fetchContents"],"mappings":";;;;;;AA4BO,MAAM,SAAY,GAAA;AAOlB,SAAS,uBAAuB,OAGpC,EAAA;AACD,EAAM,MAAA,EAAE,MAAQ,EAAA,YAAA,EAAiB,GAAA,OAAA;AAEjC,EAAA,OAAOA,yCAIJ,CAAA;AAAA,IACD,EAAI,EAAA,SAAA;AAAA,cACJC,uBAAA;AAAA,IACA,WACE,EAAA,+HAAA;AAAA,IACF,MAAQ,EAAA;AAAA,MACN,KAAO,EAAA;AAAA,QACL,IAAM,EAAA,QAAA;AAAA,QACN,QAAA,EAAU,CAAC,KAAK,CAAA;AAAA,QAChB,UAAY,EAAA;AAAA,UACV,GAAK,EAAA;AAAA,YACH,KAAO,EAAA,WAAA;AAAA,YACP,WACE,EAAA,uEAAA;AAAA,YACF,IAAM,EAAA;AAAA,WACR;AAAA,UACA,UAAY,EAAA;AAAA,YACV,KAAO,EAAA,aAAA;AAAA,YACP,WACE,EAAA,uEAAA;AAAA,YACF,IAAM,EAAA;AAAA,WACR;AAAA,UACA,KAAO,EAAA;AAAA,YACL,KAAO,EAAA,OAAA;AAAA,YACP,WACE,EAAA,yEAAA;AAAA,YACF,IAAM,EAAA;AAAA;AACR;AACF;AACF,KACF;AAAA,IACA,cAAgB,EAAA,IAAA;AAAA,IAChB,MAAM,QAAQ,GAAK,EAAA;AACjB,MAAI,GAAA,CAAA,MAAA,CAAO,KAAK,wCAAwC,CAAA;AAGxD,MAAM,MAAA,UAAA,GAAa,GAAI,CAAA,KAAA,CAAM,UAAc,IAAA,IAAA;AAC3C,MAAA,MAAM,UAAa,GAAAC,qCAAA,CAAqB,GAAI,CAAA,aAAA,EAAe,UAAU,CAAA;AAErE,MAAA,MAAMC,kCAAc,CAAA;AAAA,QAClB,MAAA;AAAA,QACA,YAAA;AAAA,QACA,OAAA,EAAS,IAAI,YAAc,EAAA,OAAA;AAAA,QAC3B,QAAA,EAAU,IAAI,KAAM,CAAA,GAAA;AAAA,QACpB,UAAA;AAAA,QACA,KAAA,EAAO,IAAI,KAAM,CAAA;AAAA,OAClB,CAAA;AAAA;AACH,GACD,CAAA;AACH;;;;;"}
1
+ {"version":3,"file":"plain.cjs.js","sources":["../../../../../src/scaffolder/actions/builtin/fetch/plain.ts"],"sourcesContent":["/*\n * Copyright 2021 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 */\n\nimport {\n resolveSafeChildPath,\n UrlReaderService,\n} from '@backstage/backend-plugin-api';\nimport { ScmIntegrations } from '@backstage/integration';\nimport { examples } from './plain.examples';\n\nimport {\n createTemplateAction,\n fetchContents,\n} from '@backstage/plugin-scaffolder-node';\n\nexport const ACTION_ID = 'fetch:plain';\n\n/**\n * Downloads content and places it in the workspace, or optionally\n * in a subdirectory specified by the 'targetPath' input option.\n * @public\n */\nexport function createFetchPlainAction(options: {\n reader: UrlReaderService;\n integrations: ScmIntegrations;\n}) {\n const { reader, integrations } = options;\n\n return createTemplateAction({\n id: ACTION_ID,\n examples,\n description:\n 'Downloads content and places it in the workspace, or optionally in a subdirectory specified by the `targetPath` input option.',\n schema: {\n input: {\n url: z =>\n z.string({\n description:\n 'Relative path or absolute URL pointing to the directory tree to fetch',\n }),\n targetPath: z =>\n z\n .string({\n description:\n 'Target path within the working directory to download the contents to.',\n })\n .optional(),\n token: z =>\n z\n .string({\n description:\n 'An optional token to use for authentication when reading the resources.',\n })\n .optional(),\n },\n },\n supportsDryRun: true,\n async handler(ctx) {\n ctx.logger.info('Fetching plain content from remote URL');\n\n // Finally move the template result into the task workspace\n const targetPath = ctx.input.targetPath ?? './';\n const outputPath = resolveSafeChildPath(ctx.workspacePath, targetPath);\n\n await fetchContents({\n reader,\n integrations,\n baseUrl: ctx.templateInfo?.baseUrl,\n fetchUrl: ctx.input.url,\n outputPath,\n token: ctx.input.token,\n });\n },\n });\n}\n"],"names":["createTemplateAction","examples","resolveSafeChildPath","fetchContents"],"mappings":";;;;;;AA4BO,MAAM,SAAY,GAAA;AAOlB,SAAS,uBAAuB,OAGpC,EAAA;AACD,EAAM,MAAA,EAAE,MAAQ,EAAA,YAAA,EAAiB,GAAA,OAAA;AAEjC,EAAA,OAAOA,yCAAqB,CAAA;AAAA,IAC1B,EAAI,EAAA,SAAA;AAAA,cACJC,uBAAA;AAAA,IACA,WACE,EAAA,+HAAA;AAAA,IACF,MAAQ,EAAA;AAAA,MACN,KAAO,EAAA;AAAA,QACL,GAAA,EAAK,CACH,CAAA,KAAA,CAAA,CAAE,MAAO,CAAA;AAAA,UACP,WACE,EAAA;AAAA,SACH,CAAA;AAAA,QACH,UAAA,EAAY,CACV,CAAA,KAAA,CAAA,CACG,MAAO,CAAA;AAAA,UACN,WACE,EAAA;AAAA,SACH,EACA,QAAS,EAAA;AAAA,QACd,KAAA,EAAO,CACL,CAAA,KAAA,CAAA,CACG,MAAO,CAAA;AAAA,UACN,WACE,EAAA;AAAA,SACH,EACA,QAAS;AAAA;AAChB,KACF;AAAA,IACA,cAAgB,EAAA,IAAA;AAAA,IAChB,MAAM,QAAQ,GAAK,EAAA;AACjB,MAAI,GAAA,CAAA,MAAA,CAAO,KAAK,wCAAwC,CAAA;AAGxD,MAAM,MAAA,UAAA,GAAa,GAAI,CAAA,KAAA,CAAM,UAAc,IAAA,IAAA;AAC3C,MAAA,MAAM,UAAa,GAAAC,qCAAA,CAAqB,GAAI,CAAA,aAAA,EAAe,UAAU,CAAA;AAErE,MAAA,MAAMC,kCAAc,CAAA;AAAA,QAClB,MAAA;AAAA,QACA,YAAA;AAAA,QACA,OAAA,EAAS,IAAI,YAAc,EAAA,OAAA;AAAA,QAC3B,QAAA,EAAU,IAAI,KAAM,CAAA,GAAA;AAAA,QACpB,UAAA;AAAA,QACA,KAAA,EAAO,IAAI,KAAM,CAAA;AAAA,OAClB,CAAA;AAAA;AACH,GACD,CAAA;AACH;;;;;"}
@@ -12,25 +12,15 @@ function createFetchPlainFileAction(options) {
12
12
  examples: plainFile_examples.examples,
13
13
  schema: {
14
14
  input: {
15
- type: "object",
16
- required: ["url", "targetPath"],
17
- properties: {
18
- url: {
19
- title: "Fetch URL",
20
- description: "Relative path or absolute URL pointing to the single file to fetch.",
21
- type: "string"
22
- },
23
- targetPath: {
24
- title: "Target Path",
25
- description: "Target path within the working directory to download the file as.",
26
- type: "string"
27
- },
28
- token: {
29
- title: "Token",
30
- description: "An optional token to use for authentication when reading the resources.",
31
- type: "string"
32
- }
33
- }
15
+ url: (z) => z.string({
16
+ description: "Relative path or absolute URL pointing to the single file to fetch."
17
+ }),
18
+ targetPath: (z) => z.string({
19
+ description: "Target path within the working directory to download the file as."
20
+ }),
21
+ token: (z) => z.string({
22
+ description: "An optional token to use for authentication when reading the resources."
23
+ }).optional()
34
24
  }
35
25
  },
36
26
  supportsDryRun: true,