@formigio/fazemos-cli 0.10.97 → 0.11.1

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
@@ -8,7 +8,7 @@ getActiveProjectId, setActiveProjectId, clearActiveProjectId, findProjectBySlug,
8
8
  // Directory-scoped context override (.fazemos.json)
9
9
  setOrgOverride, setProjectOverride, setDirContextSource, getDirContextSource, } from './config.js';
10
10
  import { findDirContextFile, readDirContextFile, writeDirContextFile, removeDirContextFile, DIR_CONFIG_FILENAME, applyDirContext, } from './dircontext.js';
11
- import { exitForError } from './exitCodes.js';
11
+ import { EXIT, exitForError } from './exitCodes.js';
12
12
  import { loginWithBrowser, hostedLogoutUrl, signup, confirmSignup, adminLogin } from './auth.js';
13
13
  import { fetchAuthConfig } from './authConfig.js';
14
14
  import { api, ApiError, refreshAuthMeCache, invalidateAuthMeCache, resolveOrgIdMaybeSlug, resolveProjectIdBySlug, resolveProjectBySlug, patchProjectDocsRepo, patchOrgWorkspace, isAgentCredential, fetchCredentialScope } from './api.js';
@@ -2297,15 +2297,49 @@ connections
2297
2297
  /**
2298
2298
  * `fazemos connections install` — print-URL + confirmation-code flow per
2299
2299
  * Sage UX §8.1. Two API calls: mint URL → exchange code.
2300
+ *
2301
+ * VCS-GUARD-1 / G-C (v0.11.0 — BREAKING): `--org <slug>` is now required.
2302
+ * The command no longer falls back to the active/sticky org — a missing
2303
+ * `--org` exits 1 with a usage hint before any API call, and an
2304
+ * unresolvable org slug exits 2 (EXIT.USAGE).
2300
2305
  */
2301
2306
  connections
2302
2307
  .command('install')
2303
- .description('Add a VCS Connection (GitHub or BitBucket). Prints an install URL and (for GitHub) waits for a confirmation code.')
2308
+ .description('Add a VCS Connection (GitHub or BitBucket) to a specific org (--org is required). Prints an install URL and (for GitHub) waits for a confirmation code.')
2304
2309
  .option('--provider <provider>', 'VCS provider: github | bitbucket')
2310
+ .option('--org <slug>', 'Org (slug or UUID) to install the Connection into. Required — does NOT fall back to the active/sticky org.')
2305
2311
  .action(async (opts) => {
2306
2312
  try {
2307
- const orgId = requireActiveOrgOrExit();
2308
- const orgName = findOrgById(orgId)?.name ?? orgId;
2313
+ // VCS-GUARD-1 / G-C (ED-11-10a Ruling 1, v0.11.0 — BREAKING):
2314
+ // --org is now required and deliberately does NOT fall back to the
2315
+ // sticky active org (requireActiveOrgOrExit(), the pre-existing
2316
+ // behavior) — installing a VCS Connection into the wrong org silently
2317
+ // is the exact failure mode this closes. Checked before any API call,
2318
+ // so a missing --org never reaches the network. See CHANGELOG.md.
2319
+ if (!opts.org) {
2320
+ console.error(chalk.red('Missing required --org <slug>.'));
2321
+ console.log(chalk.gray('Usage: fazemos connections install --org <org-slug> --provider <github|bitbucket>'));
2322
+ process.exit(1);
2323
+ // VCS-GUARD-1 / G-C (Niko review 803c3432 pt.3): explicit `return`
2324
+ // alongside process.exit — `process.exit`'s type is `never`, which
2325
+ // satisfies tsc's control-flow analysis (so `orgId` below type-checks
2326
+ // as definitely-assigned), but under a *mocked* process.exit (as in
2327
+ // this command's own unit test) execution would otherwise fall
2328
+ // through to resolveOrgIdMaybeSlug and its auth-cache refresh fetch.
2329
+ // The `return` makes "no API call on a missing --org" true at
2330
+ // runtime too, not just true in production because the real OS
2331
+ // process happens to die first.
2332
+ return;
2333
+ }
2334
+ let orgId;
2335
+ try {
2336
+ orgId = await resolveOrgIdMaybeSlug(opts.org);
2337
+ }
2338
+ catch (err) {
2339
+ console.error(chalk.red(err.message));
2340
+ process.exit(EXIT.USAGE);
2341
+ return;
2342
+ }
2309
2343
  // F22 §8.3 item 3 — provider selection matrix.
2310
2344
  // 1) `--provider github|bitbucket` supplied: use directly.
2311
2345
  // 2) No flag: prompt the user interactively (provider-picker).
@@ -2325,6 +2359,24 @@ connections
2325
2359
  // expects `provider` in the body. The github-only endpoint is kept
2326
2360
  // alive but not used here so all new connections flow through one path.
2327
2361
  const mintData = await api('POST', `/api/organizations/${orgId}/vcs/connections/install-url`, { provider, source: 'cli', returnTo: null }, { noProjectHeader: true });
2362
+ // VCS-GUARD-1 / G-C (ED-11-10a Ruling 1, Dex review C-R2): fail
2363
+ // closed when the server didn't resolve an org for this install.
2364
+ // The merge order is api → (cli, web) (ED-11-10i), so the API
2365
+ // always ships `org` first — a missing `org.slug` here means the
2366
+ // response is malformed, not "older server, tolerate it". Printing
2367
+ // the install URL with no confirmed target org is exactly the
2368
+ // ambiguity this vehicle exists to close, so stop before the URL
2369
+ // is ever shown, on stderr, non-zero exit.
2370
+ if (!mintData.org?.slug) {
2371
+ console.error(chalk.red("Couldn't confirm the target org. Install not started."));
2372
+ process.exit(1);
2373
+ return;
2374
+ }
2375
+ // VCS-GUARD-1 / G-C (ED-11-10a Ruling 1): print the org the install
2376
+ // URL actually targets, from the API response (server-resolved,
2377
+ // never the local --org input echoed back or the findOrgById
2378
+ // cache) — on BOTH provider branches, before the URL.
2379
+ console.log(`Installing into org: ${chalk.cyan(mintData.org.name)} (${mintData.org.slug})`);
2328
2380
  // F22 §8.3 item 8 — BitBucket install is browser-only in v1 (no CLI
2329
2381
  // confirmation-code exchange counterpart). Print the literal copy
2330
2382
  // block specified in the spec verbatim, then exit successfully.
@@ -2350,7 +2402,7 @@ connections
2350
2402
  return;
2351
2403
  }
2352
2404
  console.log('');
2353
- console.log(`To add a GitHub connection to ${chalk.cyan(orgName)}:`);
2405
+ console.log(`To add a GitHub connection to ${chalk.cyan(mintData.org.name)}:`);
2354
2406
  console.log('');
2355
2407
  console.log(' 1. Open this URL in your browser (expires in 10 minutes):');
2356
2408
  console.log(` ${chalk.cyan(mintData.url)}`);
@@ -6817,8 +6869,15 @@ program
6817
6869
  agentMemberId = agent.id;
6818
6870
  }
6819
6871
  // Build rich context from agent config and source resource
6820
- const agentName = opts.agent.toLowerCase();
6872
+ // [CLI-EXEC-AGENTNAME-UUID / ED-11-28y] The GET must run BEFORE
6873
+ // agentName is derived: agentName is sourced from the resolved
6874
+ // member's display_name, never from the raw --agent value (which may
6875
+ // be a UUID on the UUID-shaped-agent path). If display_name is
6876
+ // missing, agentName is omitted entirely — no UUID fallback — so the
6877
+ // API's resolveLaunchPrincipal binds on agentMemberId alone.
6821
6878
  const memberDetail = await api('GET', `/api/members/${agentMemberId}`);
6879
+ const displayName = memberDetail.member?.display_name;
6880
+ const agentName = displayName ? String(displayName).toLowerCase() : undefined;
6822
6881
  const agentConfig = memberDetail.member?.agent_config || {};
6823
6882
  const repoNames = opts.repos || agentConfig.repos || [];
6824
6883
  const context = {
@@ -6924,9 +6983,14 @@ program
6924
6983
  sourceType: opts.sourceType,
6925
6984
  sourceId,
6926
6985
  agentMemberId,
6927
- agentName,
6928
6986
  context,
6929
6987
  };
6988
+ // Omit agentName entirely when the member has no display_name — do
6989
+ // NOT fall back to the UUID (ED-11-28y). An explicit undefined-valued
6990
+ // key would still satisfy `'agentName' in body`, so this is a
6991
+ // conditional assignment, not `agentName: agentName`.
6992
+ if (agentName)
6993
+ body.agentName = agentName;
6930
6994
  const data = await api('POST', '/api/executions', body);
6931
6995
  const exec = data.execution;
6932
6996
  console.log(chalk.green(`Execution created: ${exec.id}`));