@formigio/fazemos-cli 0.10.53 → 0.10.54

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.js CHANGED
@@ -3814,6 +3814,30 @@ function findPhaseById(definition, phaseId) {
3814
3814
  return (definition?.phases || []).find((p) => p.id === phaseId);
3815
3815
  }
3816
3816
  const VALID_STEP_TYPES = ['human', 'agent', 'script', 'gate', 'human_approval'];
3817
+ /**
3818
+ * G15 — resolve a template identifier that may be a UUID *or* a template name
3819
+ * to a UUID. The template-by-id endpoints (`GET/PUT/PATCH /api/pipeline-templates/:id`)
3820
+ * require a UUID param (`requireUuidParam` middleware — a non-UUID arg returns
3821
+ * "id must be a valid UUID" with empty stdout), so a name like "aiv-full-auto"
3822
+ * must first be resolved via the project-scoped list. UUIDs pass through
3823
+ * untouched (no extra API call). Names are matched within the active project
3824
+ * (or `--project <slug>`); slug is also matched for forward-compatibility if the
3825
+ * API ever adds one.
3826
+ */
3827
+ async function resolveTemplateId(idOrName, opts = {}) {
3828
+ if (UUID_RE.test(idOrName))
3829
+ return idOrName;
3830
+ const data = await api('GET', '/api/pipeline-templates', undefined, projectOpts(opts));
3831
+ const matches = (data.templates ?? []).filter((t) => t.name === idOrName || t.slug === idOrName);
3832
+ if (matches.length === 1)
3833
+ return matches[0].id;
3834
+ if (matches.length === 0) {
3835
+ throw new Error(`No template named "${idOrName}" in the active project. ` +
3836
+ `Run "tpl list" to see names/IDs, pass --project <slug> to look in another project, or use the template UUID.`);
3837
+ }
3838
+ throw new Error(`Multiple templates named "${idOrName}" (${matches.map((t) => t.id).join(', ')}). ` +
3839
+ `Use the template UUID to disambiguate.`);
3840
+ }
3817
3841
  // ── Templates ──────────────────────────────────────────────
3818
3842
  const templates = program.command('templates').alias('tpl').description('Pipeline template commands.\n\n' +
3819
3843
  ' Templates define multi-step workflows: template → phases → steps → I/O.\n' +
@@ -3856,12 +3880,14 @@ templates
3856
3880
  templates
3857
3881
  .command('show')
3858
3882
  .description('Show template detail including phases, steps, I/O declarations, pipeline inputs, and revision number. Use this to inspect the full structure of a template and discover phase/step IDs needed by other commands.')
3859
- .argument('<id>', 'Template ID (use "tpl list" to find IDs)')
3883
+ .argument('<id>', 'Template ID or name (use "tpl list" to find them)')
3860
3884
  .option('--json', 'Output the template definition as JSON (same as tpl export). Useful for piping/inspecting without a temp file.')
3861
3885
  .option('--show-sections', 'Print full sections content for all steps (default: truncated at 200 chars)')
3886
+ .option('--project <slug>', 'Override active project when resolving a template name')
3862
3887
  .action(async (id, opts) => {
3863
3888
  try {
3864
- const data = await api('GET', `/api/pipeline-templates/${id}`);
3889
+ const resolvedId = await resolveTemplateId(id, opts);
3890
+ const data = await api('GET', `/api/pipeline-templates/${resolvedId}`);
3865
3891
  const t = data.template;
3866
3892
  // --json mode: emit definition JSON (same as tpl export)
3867
3893
  if (opts.json) {
@@ -3982,11 +4008,13 @@ templates
3982
4008
  templates
3983
4009
  .command('export')
3984
4010
  .description('Export a template\'s full definition JSON to stdout or a file. Includes all phases, steps, sections, verification, uat, agent_config, I/O wires, and pipeline inputs. The exported JSON is the canonical input to "tpl update-definition". Round-trip: tpl export <id> > def.json && tpl update-definition <id> def.json is a no-op.')
3985
- .argument('<id>', 'Template ID (use "tpl list" to find IDs)')
4011
+ .argument('<id>', 'Template ID or name (use "tpl list" to find them)')
3986
4012
  .option('--out <file>', 'Write output to file instead of stdout')
4013
+ .option('--project <slug>', 'Override active project when resolving a template name')
3987
4014
  .action(async (id, opts) => {
3988
4015
  try {
3989
- const data = await api('GET', `/api/pipeline-templates/${id}`);
4016
+ const resolvedId = await resolveTemplateId(id, opts);
4017
+ const data = await api('GET', `/api/pipeline-templates/${resolvedId}`);
3990
4018
  const t = data.template;
3991
4019
  const json = JSON.stringify(t.definition, null, 2);
3992
4020
  if (opts.out) {