@formigio/fazemos-cli 0.10.84 → 0.10.85
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/api.d.ts +43 -0
- package/dist/api.js +83 -0
- package/dist/api.js.map +1 -1
- package/dist/config.d.ts +24 -10
- package/dist/config.js +0 -8
- package/dist/config.js.map +1 -1
- package/dist/dircontext.d.ts +69 -0
- package/dist/dircontext.js +239 -0
- package/dist/dircontext.js.map +1 -1
- package/dist/exitCodes.d.ts +18 -0
- package/dist/exitCodes.js +18 -0
- package/dist/exitCodes.js.map +1 -0
- package/dist/index.js +70 -78
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* BUG231 (C1) — single source of truth for CLI process exit codes.
|
|
3
|
+
*
|
|
4
|
+
* `0` ok · `1` API/generic failure · `2` usage/context error · `3` auth ·
|
|
5
|
+
* `4` partial success (some operations in a batch failed).
|
|
6
|
+
*
|
|
7
|
+
* C1 only wires the `USAGE` exit (unresolvable/malformed `.fazemos.json`
|
|
8
|
+
* pin). The rest of the mapping (missing-project-context, dispatch error
|
|
9
|
+
* classes, partial-failure loops, `--help` rendering) is BUG231-b.
|
|
10
|
+
*/
|
|
11
|
+
export const EXIT = {
|
|
12
|
+
OK: 0,
|
|
13
|
+
API: 1,
|
|
14
|
+
USAGE: 2,
|
|
15
|
+
AUTH: 3,
|
|
16
|
+
PARTIAL: 4,
|
|
17
|
+
};
|
|
18
|
+
//# sourceMappingURL=exitCodes.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"exitCodes.js","sourceRoot":"","sources":["../src/exitCodes.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AACH,MAAM,CAAC,MAAM,IAAI,GAAG;IAClB,EAAE,EAAE,CAAC;IACL,GAAG,EAAE,CAAC;IACN,KAAK,EAAE,CAAC;IACR,IAAI,EAAE,CAAC;IACP,OAAO,EAAE,CAAC;CACF,CAAC"}
|
package/dist/index.js
CHANGED
|
@@ -6,10 +6,10 @@ import { config, getEnv, getToken, getActiveEnvName, getActiveEnvSource, setEnvO
|
|
|
6
6
|
getActiveProjectId, setActiveProjectId, clearActiveProjectId, findProjectBySlug, findProjectById, findOrgById,
|
|
7
7
|
// Directory-scoped context override (.fazemos.json)
|
|
8
8
|
setOrgOverride, setProjectOverride, setDirContextSource, getDirContextSource, } from './config.js';
|
|
9
|
-
import { findDirContextFile, readDirContextFile, writeDirContextFile, removeDirContextFile, DIR_CONFIG_FILENAME, } from './dircontext.js';
|
|
9
|
+
import { findDirContextFile, readDirContextFile, writeDirContextFile, removeDirContextFile, DIR_CONFIG_FILENAME, applyDirContext, } from './dircontext.js';
|
|
10
10
|
import { loginWithBrowser, hostedLogoutUrl, signup, confirmSignup, adminLogin } from './auth.js';
|
|
11
11
|
import { fetchAuthConfig } from './authConfig.js';
|
|
12
|
-
import { api, ApiError, refreshAuthMeCache, invalidateAuthMeCache, resolveOrgIdMaybeSlug, resolveProjectIdBySlug, patchProjectDocsRepo, patchOrgWorkspace } from './api.js';
|
|
12
|
+
import { api, ApiError, refreshAuthMeCache, invalidateAuthMeCache, resolveOrgIdMaybeSlug, resolveProjectIdBySlug, patchProjectDocsRepo, patchOrgWorkspace, isAgentCredential, fetchCredentialScope } from './api.js';
|
|
13
13
|
import { isProjectConnectionUnavailable, renderProjectConnectionUnavailableCopy, } from './connectionErrorCopy.js';
|
|
14
14
|
import { loadYaml, summarize } from './yaml/load.js';
|
|
15
15
|
import { printFindings, printJson } from './yaml/format.js';
|
|
@@ -232,6 +232,8 @@ program
|
|
|
232
232
|
// copyInheritedSettings(), which copies _allowExcessArguments, so every
|
|
233
233
|
// subcommand registered after this line inherits the strict behavior.
|
|
234
234
|
.allowExcessArguments(false);
|
|
235
|
+
/** UUID v4 pattern — used by resolveTemplateId (G15) and elsewhere to detect a pre-resolved id vs. a name/slug. */
|
|
236
|
+
const UUID_RE = /^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i;
|
|
235
237
|
// ── Directory-scoped default org/project (.fazemos.json) ─────
|
|
236
238
|
//
|
|
237
239
|
// Before any command action runs, discover the nearest `.fazemos.json`
|
|
@@ -239,80 +241,14 @@ program
|
|
|
239
241
|
// them as in-memory overrides for the process. This scopes every call to the
|
|
240
242
|
// pinned org/project without a manual `orgs switch` / `projects switch`.
|
|
241
243
|
//
|
|
242
|
-
//
|
|
243
|
-
//
|
|
244
|
-
//
|
|
245
|
-
//
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
244
|
+
// BUG231-C1: resolution is no longer best-effort. An unresolvable or
|
|
245
|
+
// malformed pin hard-errors (exit 2, no API call) instead of silently
|
|
246
|
+
// falling back to the machine-global active org/project — see
|
|
247
|
+
// `applyDirContext` in `src/dircontext.ts` for the resolution/bypass order.
|
|
248
|
+
// This wrapper owns the only piece of state involved: the once-per-process
|
|
249
|
+
// latch (so a second `preAction` firing in the same process, e.g. a
|
|
250
|
+
// subcommand dispatch, doesn't re-resolve).
|
|
249
251
|
let dirContextApplied = false;
|
|
250
|
-
async function applyDirContext(topCommand) {
|
|
251
|
-
if (dirContextApplied)
|
|
252
|
-
return;
|
|
253
|
-
dirContextApplied = true;
|
|
254
|
-
let found;
|
|
255
|
-
try {
|
|
256
|
-
found = findDirContextFile();
|
|
257
|
-
}
|
|
258
|
-
catch (err) {
|
|
259
|
-
// Malformed .fazemos.json — surface it for normal commands, but don't
|
|
260
|
-
// abort. The bootstrap commands (notably `use`) report it themselves, so
|
|
261
|
-
// stay silent for them to avoid a double warning.
|
|
262
|
-
if (!DIR_CONTEXT_SKIP.has(topCommand))
|
|
263
|
-
console.error(chalk.yellow(err.message));
|
|
264
|
-
return;
|
|
265
|
-
}
|
|
266
|
-
if (!found)
|
|
267
|
-
return;
|
|
268
|
-
// Record the source so whoami/config can show where the scope came from.
|
|
269
|
-
setDirContextSource({ path: found.path, ...found.context });
|
|
270
|
-
// Bootstrap commands (auth/env/init/use) operate without a resolved scope.
|
|
271
|
-
if (DIR_CONTEXT_SKIP.has(topCommand))
|
|
272
|
-
return;
|
|
273
|
-
const { org, project } = found.context;
|
|
274
|
-
if (org) {
|
|
275
|
-
try {
|
|
276
|
-
setOrgOverride(await resolveOrgIdMaybeSlug(org));
|
|
277
|
-
}
|
|
278
|
-
catch {
|
|
279
|
-
// Do NOT fail silently. Leaving the override unset means the command
|
|
280
|
-
// runs against whatever `orgs switch` last persisted machine-globally —
|
|
281
|
-
// for a READ the API error eventually hints at it, but for a WRITE the
|
|
282
|
-
// command simply SUCCEEDS IN THE WRONG ORG. Say so, on stderr, so the
|
|
283
|
-
// operator can see the scope they think they pinned was not applied.
|
|
284
|
-
console.error(chalk.yellow(`Warning: .fazemos.json pins org '${org}' but it could not be resolved ` +
|
|
285
|
-
`(offline, wrong --env, stale cache, or a typo'd slug). ` +
|
|
286
|
-
`Falling back to the machine-global active org — verify with 'fazemos whoami' before writing.`));
|
|
287
|
-
}
|
|
288
|
-
}
|
|
289
|
-
if (project) {
|
|
290
|
-
try {
|
|
291
|
-
if (UUID_RE.test(project)) {
|
|
292
|
-
setProjectOverride(project);
|
|
293
|
-
}
|
|
294
|
-
else {
|
|
295
|
-
// Resolves against the active org, which now reflects the org override.
|
|
296
|
-
const projectId = await resolveProjectIdBySlug(project);
|
|
297
|
-
if (projectId) {
|
|
298
|
-
setProjectOverride(projectId);
|
|
299
|
-
}
|
|
300
|
-
else {
|
|
301
|
-
// Resolver MISS, not a throw — the old code fell through here in
|
|
302
|
-
// silence, which is how a pinned scope quietly became the global one.
|
|
303
|
-
console.error(chalk.yellow(`Warning: .fazemos.json pins project '${project}' but no such project ` +
|
|
304
|
-
`exists in the active org. Falling back to the machine-global active project.`));
|
|
305
|
-
}
|
|
306
|
-
}
|
|
307
|
-
}
|
|
308
|
-
catch {
|
|
309
|
-
// Same hazard as the org branch above — warn rather than silently
|
|
310
|
-
// inheriting the machine-global project.
|
|
311
|
-
console.error(chalk.yellow(`Warning: .fazemos.json pins project '${project}' but it could not be resolved. ` +
|
|
312
|
-
`Falling back to the machine-global active project — verify with 'fazemos whoami' before writing.`));
|
|
313
|
-
}
|
|
314
|
-
}
|
|
315
|
-
}
|
|
316
252
|
program.hook('preAction', async (_thisCommand, actionCommand) => {
|
|
317
253
|
// Apply the global `--env` flag first so every downstream resolution (dir
|
|
318
254
|
// context slug lookups, auth, API calls) sees the right environment.
|
|
@@ -326,7 +262,26 @@ program.hook('preAction', async (_thisCommand, actionCommand) => {
|
|
|
326
262
|
c = c.parent;
|
|
327
263
|
top = c.name();
|
|
328
264
|
}
|
|
329
|
-
|
|
265
|
+
if (dirContextApplied)
|
|
266
|
+
return;
|
|
267
|
+
dirContextApplied = true;
|
|
268
|
+
// Deps are wrapped in closures (not passed by reference) so that a test's
|
|
269
|
+
// `./api.js`/`./config.js` mock only needs to provide the specific
|
|
270
|
+
// resolver a given command path actually exercises — same laziness the
|
|
271
|
+
// pre-extraction code had, since these named imports are otherwise
|
|
272
|
+
// referenced all over index.ts for unrelated commands.
|
|
273
|
+
await applyDirContext(top ?? '', actionCommand.opts(), {
|
|
274
|
+
resolveOrgIdMaybeSlug: (value) => resolveOrgIdMaybeSlug(value),
|
|
275
|
+
resolveProjectIdBySlug: (slug) => resolveProjectIdBySlug(slug),
|
|
276
|
+
setOrgOverride: (orgId) => setOrgOverride(orgId),
|
|
277
|
+
setProjectOverride: (projectId) => setProjectOverride(projectId),
|
|
278
|
+
setDirContextSource: (source) => setDirContextSource(source),
|
|
279
|
+
exit: (code) => process.exit(code),
|
|
280
|
+
env: process.env,
|
|
281
|
+
stderr: (message) => console.error(chalk.red(message)),
|
|
282
|
+
isAgentCredential: () => isAgentCredential(),
|
|
283
|
+
fetchCredentialScope: () => fetchCredentialScope(),
|
|
284
|
+
});
|
|
330
285
|
});
|
|
331
286
|
// ── Init ────────────────────────────────────────────────────
|
|
332
287
|
program
|
|
@@ -544,9 +499,39 @@ auth
|
|
|
544
499
|
// ── Whoami ──────────────────────────────────────────────────
|
|
545
500
|
program
|
|
546
501
|
.command('whoami')
|
|
547
|
-
.description('Show current user, org, and project context.
|
|
502
|
+
.description('Show current user, org, and project context. Human callers use their Cognito identity (JWT); agent callers (FAZEMOS_API_KEY set) use `/api/members/me` instead, since `/auth/me` 403s for them.')
|
|
548
503
|
.action(async () => {
|
|
549
504
|
try {
|
|
505
|
+
// BUG231-C1a S6: agent credentials 403 on /auth/me
|
|
506
|
+
// (WRONG_ENDPOINT_FOR_AGENT) — use /api/members/me instead, and show
|
|
507
|
+
// the dirContextSource `verified` marker so an operator can tell a
|
|
508
|
+
// credential-confirmed pin from one the CLI merely proceeded on.
|
|
509
|
+
if (isAgentCredential()) {
|
|
510
|
+
const me = (await api('GET', '/api/members/me', undefined, { noProjectHeader: true }));
|
|
511
|
+
console.log(` Member: ${chalk.cyan(me.member.display_name)} (${me.member.role}) [agent credential]`);
|
|
512
|
+
console.log(` Env: ${chalk.cyan(getActiveEnvName())}`);
|
|
513
|
+
console.log(` Org: ${me.member.org_id}`);
|
|
514
|
+
if (me.project) {
|
|
515
|
+
console.log(` Project: ${chalk.cyan(me.project.name)} (${me.project.slug})`);
|
|
516
|
+
}
|
|
517
|
+
else {
|
|
518
|
+
console.log(` Project: ${chalk.gray('(org-level credential — no project scope)')}`);
|
|
519
|
+
}
|
|
520
|
+
const dirSource = getDirContextSource();
|
|
521
|
+
if (dirSource) {
|
|
522
|
+
const rel = relative(process.cwd(), dirSource.path) || dirSource.path;
|
|
523
|
+
if (dirSource.ignored) {
|
|
524
|
+
console.log(chalk.gray(` Scope: pin at ${rel} IGNORED (FAZEMOS_IGNORE_DIR_CONTEXT=1)`));
|
|
525
|
+
}
|
|
526
|
+
else {
|
|
527
|
+
const verifiedLabel = dirSource.verified
|
|
528
|
+
? chalk.gray(` [verified: ${dirSource.verified}]`)
|
|
529
|
+
: '';
|
|
530
|
+
console.log(chalk.gray(` Scope: from ${rel} (fazemos use)`) + verifiedLabel);
|
|
531
|
+
}
|
|
532
|
+
}
|
|
533
|
+
return;
|
|
534
|
+
}
|
|
550
535
|
// Force-refresh the /auth/me cache on whoami so subsequent slug
|
|
551
536
|
// resolutions (e.g., `projects switch vahmos`) see the fresh state
|
|
552
537
|
// without a second round-trip.
|
|
@@ -594,10 +579,17 @@ program
|
|
|
594
579
|
}
|
|
595
580
|
// Note when the org/project scope is coming from a directory .fazemos.json
|
|
596
581
|
// rather than the persisted active selection, so the source is obvious.
|
|
582
|
+
// BUG231-C1 S4: FAZEMOS_IGNORE_DIR_CONTEXT=1 sees the pin but doesn't
|
|
583
|
+
// apply it — say so explicitly rather than implying it was applied.
|
|
597
584
|
const dirSource = getDirContextSource();
|
|
598
585
|
if (dirSource) {
|
|
599
586
|
const rel = relative(process.cwd(), dirSource.path) || dirSource.path;
|
|
600
|
-
|
|
587
|
+
if (dirSource.ignored) {
|
|
588
|
+
console.log(chalk.gray(` Scope: pin at ${rel} IGNORED (FAZEMOS_IGNORE_DIR_CONTEXT=1)`));
|
|
589
|
+
}
|
|
590
|
+
else {
|
|
591
|
+
console.log(chalk.gray(` Scope: from ${rel} (fazemos use)`));
|
|
592
|
+
}
|
|
601
593
|
}
|
|
602
594
|
}
|
|
603
595
|
catch (err) {
|