@formigio/fazemos-cli 0.10.93 → 0.10.94

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
@@ -4134,7 +4134,7 @@ const templates = program.command('templates').alias('tpl').description('Pipelin
4134
4134
  ' 3. tpl add-step <id> --phase ... Add steps to phases\n' +
4135
4135
  ' 4. tpl add-output / add-input Wire I/O between steps\n' +
4136
4136
  ' 5. tpl validate <id> Check for errors\n' +
4137
- ' 6. tpl activate <id> Make available for instances\n\n' +
4137
+ ' 6. tpl activate <id> Make available for instances (privileged templates need --expected-version)\n\n' +
4138
4138
  ' Use "tpl phases <id>" to list phase IDs needed by --phase options.\n' +
4139
4139
  ' Use "tpl steps <id>" to list step IDs needed by --step options.\n' +
4140
4140
  ' Use "tpl show <id>" to see full structure with I/O declarations.');
@@ -4489,14 +4489,59 @@ templates
4489
4489
  });
4490
4490
  templates
4491
4491
  .command('activate')
4492
- .description('Activate a draft template (required before creating pipeline instances). Template must have at least one phase with at least one step. Status changes from draft → active.')
4492
+ .description('Activate a draft template (required before creating pipeline instances). ' +
4493
+ 'Template must have at least one phase with at least one step. Status changes from draft → active.\n\n' +
4494
+ ' Privileged templates require --expected-version <n> (the revision from "tpl show <id>"). ' +
4495
+ 'This is a compare-and-swap guard: the version you reviewed must still match the server\'s, ' +
4496
+ 'so a concurrent edit cannot be silently activated. Non-privileged templates ignore this flag.')
4493
4497
  .argument('<id>', 'Template ID')
4494
- .action(async (id) => {
4498
+ .option('--expected-version <n>', 'Expected current revision, from "tpl show <id>" (required for privileged templates)')
4499
+ .action(async (id, opts) => {
4500
+ const body = { status: 'active' };
4501
+ let expectedVersion;
4502
+ if (opts.expectedVersion !== undefined) {
4503
+ expectedVersion = Number(opts.expectedVersion);
4504
+ if (!Number.isInteger(expectedVersion) || expectedVersion < 1) {
4505
+ console.error(chalk.red(`Invalid --expected-version: "${opts.expectedVersion}" (must be an integer >= 1)`));
4506
+ process.exit(1);
4507
+ return;
4508
+ }
4509
+ body.expected_version = expectedVersion;
4510
+ }
4495
4511
  try {
4496
- await api('PATCH', `/api/pipeline-templates/${id}/status`, { status: 'active' });
4512
+ await api('PATCH', `/api/pipeline-templates/${id}/status`, body);
4497
4513
  console.log(chalk.green('Template activated'));
4498
4514
  }
4499
4515
  catch (err) {
4516
+ // D-3 (BUG292): print ApiError code+message verbatim, no retry, no GET
4517
+ // on 403/409. RULE-CAS-PIN-IS-THE-CALLERS: this CLI never fills the
4518
+ // expected_version pin from its own read on the caller's behalf.
4519
+ if (err instanceof ApiError) {
4520
+ console.error(chalk.red(err.code ? `${err.code}: ${err.message}` : err.message));
4521
+ // D-2: only on the H3 "expected_version is required" 400
4522
+ // VALIDATION_ERROR, surface the current version as a hint (not an
4523
+ // auto-filled retry). The activate path has two OTHER 400
4524
+ // VALIDATION_ERRORs ("no phases" / phase "has no steps") that are
4525
+ // evaluated before the H3 gate and have nothing to do with
4526
+ // privilege — gating on err.code alone (Dex C-1) fired this hint on
4527
+ // those too and sent the caller on a pointless --expected-version
4528
+ // retry that fails the same way.
4529
+ if (err.code === 'VALIDATION_ERROR' &&
4530
+ expectedVersion === undefined &&
4531
+ /expected_version is required/.test(err.message)) {
4532
+ try {
4533
+ const data = await api('GET', `/api/pipeline-templates/${id}`);
4534
+ const version = data?.template?.version;
4535
+ if (version != null) {
4536
+ console.error(chalk.yellow(`Privileged template — current version is ${version}. Review with "fazemos tpl show ${id}", then re-run: fazemos tpl activate ${id} --expected-version ${version}`));
4537
+ }
4538
+ }
4539
+ catch {
4540
+ // GET failed — the verbatim error above already printed.
4541
+ }
4542
+ }
4543
+ process.exit(1);
4544
+ }
4500
4545
  console.error(chalk.red(err.message));
4501
4546
  process.exit(1);
4502
4547
  }