@formigio/fazemos-cli 0.10.84 → 0.10.86
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/dispatch.d.ts +26 -41
- package/dist/dispatch.js +78 -118
- package/dist/dispatch.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 +248 -226
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/api.d.ts
CHANGED
|
@@ -95,6 +95,49 @@ export declare function refreshAuthMeCache(): Promise<AuthMeResponse | null>;
|
|
|
95
95
|
* NEVER writes anything to disk — reads process.env only (BD-2 hard property).
|
|
96
96
|
*/
|
|
97
97
|
export declare function resolveBearerToken(activeOrgId: string | null): string | null;
|
|
98
|
+
/**
|
|
99
|
+
* BUG231-C1a — true when this process is authenticating as an agent (an
|
|
100
|
+
* injected `FAZEMOS_API_KEY`) rather than a human Cognito session. This is
|
|
101
|
+
* the same discriminator `resolveBearerToken` already uses; exposed here so
|
|
102
|
+
* `applyDirContext` (`dircontext.ts`) can pick the credential-scope path
|
|
103
|
+
* instead of the /auth/me-backed slug resolvers, which 403 for agents.
|
|
104
|
+
*/
|
|
105
|
+
export declare function isAgentCredential(): boolean;
|
|
106
|
+
/** The agent credential's own scope, per `GET /api/members/me`. */
|
|
107
|
+
export interface CredentialScope {
|
|
108
|
+
orgId: string;
|
|
109
|
+
project: {
|
|
110
|
+
id: string;
|
|
111
|
+
slug: string;
|
|
112
|
+
} | null;
|
|
113
|
+
}
|
|
114
|
+
/**
|
|
115
|
+
* BUG231-C1a — fetch the agent credential's authoritative scope.
|
|
116
|
+
*
|
|
117
|
+
* `/auth/me` 403s for agent callers (`WRONG_ENDPOINT_FOR_AGENT`), so an
|
|
118
|
+
* agent-credential run of `applyDirContext` calls `GET /api/members/me`
|
|
119
|
+
* once instead. The credential is the source of truth: `member.org_id` is
|
|
120
|
+
* the org the key is bound to server-side, and `project` (nullable) is the
|
|
121
|
+
* project the credential is scoped to (null for an org-level key).
|
|
122
|
+
*
|
|
123
|
+
* BUG231-C1a security re-review (niko, web-security-ops, M1): this
|
|
124
|
+
* deliberately does NOT go through `api()` / `resolveBearerToken`. That
|
|
125
|
+
* path picks the bearer from `getActiveOrgId()` and can swap to a
|
|
126
|
+
* `FAZEMOS_API_KEY__{SLUG}` cross-org key whenever the (possibly stale,
|
|
127
|
+
* possibly machine-global-persisted) active org differs from
|
|
128
|
+
* `FAZEMOS_ORG_ID` — see `resolveBearerToken` above. That's exactly
|
|
129
|
+
* backwards for this call: `fetchCredentialScope` exists to *establish*
|
|
130
|
+
* the credential's scope before any org override is decided, so it must
|
|
131
|
+
* always authenticate with the raw primary `FAZEMOS_API_KEY` and never
|
|
132
|
+
* send `X-Org-Id`. Sending the wrong key here would make a cross-org
|
|
133
|
+
* write look like a verified same-org pin.
|
|
134
|
+
*
|
|
135
|
+
* On failure, throws an `Error` with an `.exitCode` of `EXIT.AUTH` (401) or
|
|
136
|
+
* `EXIT.API` (anything else — 5xx, network). Per the C1a ruling this is an
|
|
137
|
+
* API-failure signal, never `EXIT.USAGE` — a `/members/me` outage is not the
|
|
138
|
+
* same thing as an unresolvable pin.
|
|
139
|
+
*/
|
|
140
|
+
export declare function fetchCredentialScope(): Promise<CredentialScope>;
|
|
98
141
|
/**
|
|
99
142
|
* Core API helper. Always authenticates, always sends X-Org-Id when one is
|
|
100
143
|
* active, and sends X-Fazemos-Project-Id when a project is active (or one
|
package/dist/api.js
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { getEnv, getToken, getActiveOrgId, getActiveProjectId, findProjectBySlug, findOrgBySlug, findOrgById, setAuthMeCache, clearAuthMeCache, } from './config.js';
|
|
2
2
|
import { refreshSession } from './auth.js';
|
|
3
|
+
import { EXIT } from './exitCodes.js';
|
|
3
4
|
/**
|
|
4
5
|
* Error thrown when an API request returns a non-2xx response. Carries the
|
|
5
6
|
* `code` field from the API's error envelope (when present) so command
|
|
@@ -148,6 +149,88 @@ export function resolveBearerToken(activeOrgId) {
|
|
|
148
149
|
// Primary org call, or cross-org slug unresolvable → use primary API key
|
|
149
150
|
return primaryApiKey;
|
|
150
151
|
}
|
|
152
|
+
/**
|
|
153
|
+
* BUG231-C1a — true when this process is authenticating as an agent (an
|
|
154
|
+
* injected `FAZEMOS_API_KEY`) rather than a human Cognito session. This is
|
|
155
|
+
* the same discriminator `resolveBearerToken` already uses; exposed here so
|
|
156
|
+
* `applyDirContext` (`dircontext.ts`) can pick the credential-scope path
|
|
157
|
+
* instead of the /auth/me-backed slug resolvers, which 403 for agents.
|
|
158
|
+
*/
|
|
159
|
+
export function isAgentCredential() {
|
|
160
|
+
return Boolean(process.env.FAZEMOS_API_KEY);
|
|
161
|
+
}
|
|
162
|
+
/**
|
|
163
|
+
* BUG231-C1a — fetch the agent credential's authoritative scope.
|
|
164
|
+
*
|
|
165
|
+
* `/auth/me` 403s for agent callers (`WRONG_ENDPOINT_FOR_AGENT`), so an
|
|
166
|
+
* agent-credential run of `applyDirContext` calls `GET /api/members/me`
|
|
167
|
+
* once instead. The credential is the source of truth: `member.org_id` is
|
|
168
|
+
* the org the key is bound to server-side, and `project` (nullable) is the
|
|
169
|
+
* project the credential is scoped to (null for an org-level key).
|
|
170
|
+
*
|
|
171
|
+
* BUG231-C1a security re-review (niko, web-security-ops, M1): this
|
|
172
|
+
* deliberately does NOT go through `api()` / `resolveBearerToken`. That
|
|
173
|
+
* path picks the bearer from `getActiveOrgId()` and can swap to a
|
|
174
|
+
* `FAZEMOS_API_KEY__{SLUG}` cross-org key whenever the (possibly stale,
|
|
175
|
+
* possibly machine-global-persisted) active org differs from
|
|
176
|
+
* `FAZEMOS_ORG_ID` — see `resolveBearerToken` above. That's exactly
|
|
177
|
+
* backwards for this call: `fetchCredentialScope` exists to *establish*
|
|
178
|
+
* the credential's scope before any org override is decided, so it must
|
|
179
|
+
* always authenticate with the raw primary `FAZEMOS_API_KEY` and never
|
|
180
|
+
* send `X-Org-Id`. Sending the wrong key here would make a cross-org
|
|
181
|
+
* write look like a verified same-org pin.
|
|
182
|
+
*
|
|
183
|
+
* On failure, throws an `Error` with an `.exitCode` of `EXIT.AUTH` (401) or
|
|
184
|
+
* `EXIT.API` (anything else — 5xx, network). Per the C1a ruling this is an
|
|
185
|
+
* API-failure signal, never `EXIT.USAGE` — a `/members/me` outage is not the
|
|
186
|
+
* same thing as an unresolvable pin.
|
|
187
|
+
*/
|
|
188
|
+
export async function fetchCredentialScope() {
|
|
189
|
+
const primaryApiKey = process.env.FAZEMOS_API_KEY;
|
|
190
|
+
if (!primaryApiKey) {
|
|
191
|
+
// Caller contract violation (isAgentCredential() should have gated
|
|
192
|
+
// this) — fail loud rather than silently querying unauthenticated.
|
|
193
|
+
throw new Error('fetchCredentialScope() called without FAZEMOS_API_KEY set');
|
|
194
|
+
}
|
|
195
|
+
const env = getEnv();
|
|
196
|
+
const fail = (message, exitCode) => {
|
|
197
|
+
const wrapped = new Error(`could not verify agent credential scope via GET /api/members/me: ${message}`);
|
|
198
|
+
wrapped.exitCode = exitCode;
|
|
199
|
+
throw wrapped;
|
|
200
|
+
};
|
|
201
|
+
let response;
|
|
202
|
+
try {
|
|
203
|
+
response = await fetch(`${env.apiUrl}/api/members/me`, {
|
|
204
|
+
method: 'GET',
|
|
205
|
+
headers: {
|
|
206
|
+
'Content-Type': 'application/json',
|
|
207
|
+
// Deliberately the raw primary key — see the M1 note above. No
|
|
208
|
+
// X-Org-Id: the server resolves org from the credential alone.
|
|
209
|
+
Authorization: `Bearer ${primaryApiKey}`,
|
|
210
|
+
},
|
|
211
|
+
});
|
|
212
|
+
}
|
|
213
|
+
catch (err) {
|
|
214
|
+
return fail(err instanceof Error ? err.message : String(err), EXIT.API);
|
|
215
|
+
}
|
|
216
|
+
const text = await response.text();
|
|
217
|
+
let data;
|
|
218
|
+
try {
|
|
219
|
+
data = JSON.parse(text);
|
|
220
|
+
}
|
|
221
|
+
catch {
|
|
222
|
+
data = text;
|
|
223
|
+
}
|
|
224
|
+
if (!response.ok) {
|
|
225
|
+
const obj = typeof data === 'object' && data !== null ? data : null;
|
|
226
|
+
return fail(obj?.error ?? `HTTP ${response.status}`, response.status === 401 ? EXIT.AUTH : EXIT.API);
|
|
227
|
+
}
|
|
228
|
+
const res = data;
|
|
229
|
+
return {
|
|
230
|
+
orgId: res.member.org_id,
|
|
231
|
+
project: res.project ? { id: res.project.id, slug: res.project.slug } : null,
|
|
232
|
+
};
|
|
233
|
+
}
|
|
151
234
|
/**
|
|
152
235
|
* Core API helper. Always authenticates, always sends X-Org-Id when one is
|
|
153
236
|
* active, and sends X-Fazemos-Project-Id when a project is active (or one
|
package/dist/api.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"api.js","sourceRoot":"","sources":["../src/api.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,MAAM,EACN,QAAQ,EACR,cAAc,EACd,kBAAkB,EAClB,iBAAiB,EACjB,aAAa,EACb,WAAW,EACX,cAAc,EACd,gBAAgB,GAEjB,MAAM,aAAa,CAAC;AACrB,OAAO,EAAE,cAAc,EAAE,MAAM,WAAW,CAAC;
|
|
1
|
+
{"version":3,"file":"api.js","sourceRoot":"","sources":["../src/api.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,MAAM,EACN,QAAQ,EACR,cAAc,EACd,kBAAkB,EAClB,iBAAiB,EACjB,aAAa,EACb,WAAW,EACX,cAAc,EACd,gBAAgB,GAEjB,MAAM,aAAa,CAAC;AACrB,OAAO,EAAE,cAAc,EAAE,MAAM,WAAW,CAAC;AAC3C,OAAO,EAAE,IAAI,EAA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AG,GACP,OAAO,IAAI,KAAK,QAAQ,IAAI,IAAI,KAAK,IAAI;YACvC,CAAC,CAAE,IAA0C;YAC7C,CAAC,CAAC,IAAI,CAAC;QACX,MAAM,IAAI,GAAG,GAAG,EAAE,IAAI,CAAC;QACvB,MAAM,GAAG,GAAG,GAAG,EAAE,KAAK,IAAI,QAAQ,QAAQ,CAAC,MAAM,EAAE,CAAC;QAEpD,+DAA+D;QAC/D,8DAA8D;QAC9D,IAAI,IAAI,KAAK,yBAAyB,EAAE,CAAC;YACvC,MAAM,IAAI,QAAQ,CAChB,8BAA8B,EAC9B,QAAQ,CAAC,MAAM,EACf,IAAI,EACJ,IAAI,CACL,CAAC;QACJ,CAAC;QAED,MAAM,IAAI,QAAQ,CAAC,GAAG,EAAE,QAAQ,CAAC,MAAM,EAAE,IAAI,EAAE,IAAI,CAAC,CAAC;IACvD,CAAC;IAED,OAAO,IAAI,CAAC;AACd,CAAC;AAED;;;;GAIG;AACH,MAAM,UAAU,qBAAqB;IACnC,gBAAgB,EAAE,CAAC;AACrB,CAAC;AAED,+EAA+E;AAE/E;;;;;;GAMG;AACH,MAAM,CAAC,KAAK,UAAU,oBAAoB,CACxC,KAAa,EACb,SAAiB,EACjB,IAAkD;IAElD,OAAO,GAAG,CACR,OAAO,EACP,sBAAsB,KAAK,aAAa,SAAS,EAAE,EACnD,IAAI,EACJ,EAAE,eAAe,EAAE,IAAI,EAAE,CAC1B,CAAC;AACJ,CAAC;AAED;;;;;;GAMG;AACH,MAAM,CAAC,KAAK,UAAU,iBAAiB,CACrC,KAAa,EACb,IAAmF;IAEnF,OAAO,GAAG,CACR,OAAO,EACP,sBAAsB,KAAK,EAAE,EAC7B,IAAI,EACJ,EAAE,eAAe,EAAE,IAAI,EAAE,CAC1B,CAAC;AACJ,CAAC"}
|
package/dist/config.d.ts
CHANGED
|
@@ -145,22 +145,36 @@ export declare function updateEnvironment(name: string, patch: Partial<Environme
|
|
|
145
145
|
export declare function getToken(): string | null;
|
|
146
146
|
export declare function getActiveOrgId(): string | null;
|
|
147
147
|
export declare function setActiveOrgId(orgId: string): void;
|
|
148
|
+
/**
|
|
149
|
+
* BUG231-C1 S4: `ignored` is set only on the `FAZEMOS_IGNORE_DIR_CONTEXT=1`
|
|
150
|
+
* bypass path — the pin was seen but deliberately not applied. Optional so
|
|
151
|
+
* the existing exact-shape assertions (e.g. `config-override.test.ts`)
|
|
152
|
+
* keep passing unmodified when it's absent.
|
|
153
|
+
*
|
|
154
|
+
* BUG231-C1a S6: `verified` is set only on the agent-credential path (see
|
|
155
|
+
* `applyDirContext` in `dircontext.ts`). `'credential'` means the pin was
|
|
156
|
+
* confirmed against the agent credential's own scope (a matched project pin,
|
|
157
|
+
* a matched UUID org pin, or a slug org pin verified via a matched project);
|
|
158
|
+
* `'unverified'` means the CLI proceeded on an unverifiable pin (an
|
|
159
|
+
* org-level key's project pin, or a slug org pin with no project pin to
|
|
160
|
+
* cross-check it) — present so an operator can tell the two cases apart in
|
|
161
|
+
* `whoami`/`env`. Absent on the human/Cognito path (exactly C1 as built).
|
|
162
|
+
*/
|
|
163
|
+
export interface DirContextSource {
|
|
164
|
+
path: string;
|
|
165
|
+
org?: string;
|
|
166
|
+
project?: string;
|
|
167
|
+
ignored?: true;
|
|
168
|
+
verified?: 'credential' | 'unverified';
|
|
169
|
+
}
|
|
148
170
|
/** Set the in-memory active-org override (resolved org id, or null to clear). */
|
|
149
171
|
export declare function setOrgOverride(orgId: string | null): void;
|
|
150
172
|
/** Set the in-memory active-project override (resolved project id, or null to clear). */
|
|
151
173
|
export declare function setProjectOverride(projectId: string | null): void;
|
|
152
174
|
/** Record where the directory context came from, for display in whoami/config. */
|
|
153
|
-
export declare function setDirContextSource(source:
|
|
154
|
-
path: string;
|
|
155
|
-
org?: string;
|
|
156
|
-
project?: string;
|
|
157
|
-
} | null): void;
|
|
175
|
+
export declare function setDirContextSource(source: DirContextSource | null): void;
|
|
158
176
|
/** Returns the directory-context source (file path + raw slugs) if one is active. */
|
|
159
|
-
export declare function getDirContextSource():
|
|
160
|
-
path: string;
|
|
161
|
-
org?: string;
|
|
162
|
-
project?: string;
|
|
163
|
-
} | null;
|
|
177
|
+
export declare function getDirContextSource(): DirContextSource | null;
|
|
164
178
|
export declare function setAuth(env: string, email: string, idToken: string, refreshToken: string, expiresInSeconds: number, clientId?: string): void;
|
|
165
179
|
/**
|
|
166
180
|
* Returns the active project id for the currently-active org, or null if
|
package/dist/config.js
CHANGED
|
@@ -108,14 +108,6 @@ export function getActiveOrgId() {
|
|
|
108
108
|
export function setActiveOrgId(orgId) {
|
|
109
109
|
config.set('activeOrgId', orgId);
|
|
110
110
|
}
|
|
111
|
-
// ── Directory-scoped context override (.fazemos.json) ───────
|
|
112
|
-
//
|
|
113
|
-
// A `.fazemos.json` discovered by walking up from the cwd pins a default org
|
|
114
|
-
// and project for the working directory. These overrides are resolved once at
|
|
115
|
-
// CLI bootstrap (slug → id against /auth/me) and held in memory for the
|
|
116
|
-
// process. They take precedence over the persisted "active" selection but sit
|
|
117
|
-
// below an explicit `--project` flag (which is threaded via ApiOptions). See
|
|
118
|
-
// src/dircontext.ts and the preAction hook in src/index.ts.
|
|
119
111
|
let orgOverride = null;
|
|
120
112
|
let projectOverride = null;
|
|
121
113
|
let dirContextSource = null;
|
package/dist/config.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"config.js","sourceRoot":"","sources":["../src/config.ts"],"names":[],"mappings":"AAAA,OAAO,IAAI,MAAM,MAAM,CAAC;AAyGxB,MAAM,CAAC,MAAM,oBAAoB,GAAG,CAAC,GAAG,EAAE,GAAG,IAAI,CAAC;AAElD,MAAM,CAAC,MAAM,MAAM,GAAG,IAAI,IAAI,CAAgB;IAC5C,WAAW,EAAE,aAAa;IAC1B,QAAQ,EAAE;QACR,YAAY,EAAE,EAAE;QAChB,SAAS,EAAE,EAAE;QACb,WAAW,EAAE,EAAE;QACf,kBAAkB,EAAE,EAAE;QACtB,IAAI,EAAE,EA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AAI,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,EAAE,KAAK,KAAK,CAAC,CAAC;IAC9C,IAAI,CAAC,GAAG;QAAE,OAAO,IAAI,CAAC;IACtB,OAAO,GAAG,CAAC,QAAQ,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,EAAE,KAAK,SAAS,CAAC,IAAI,IAAI,CAAC;AAC5D,CAAC;AAED,MAAM,UAAU,WAAW,CAAC,KAAa;IACvC,MAAM,EAAE,GAAG,cAAc,EAAE,CAAC;IAC5B,IAAI,CAAC,EAAE;QAAE,OAAO,IAAI,CAAC;IACrB,OAAO,EAAE,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,EAAE,KAAK,KAAK,CAAC,IAAI,IAAI,CAAC;AACnD,CAAC;AAED;;;;;GAKG;AACH,MAAM,UAAU,aAAa,CAAC,IAAY;IACxC,MAAM,EAAE,GAAG,cAAc,EAAE,CAAC;IAC5B,IAAI,CAAC,EAAE;QAAE,OAAO,IAAI,CAAC;IACrB,OAAO,EAAE,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,IAAI,KAAK,IAAI,CAAC,IAAI,IAAI,CAAC;AACpD,CAAC"}
|
package/dist/dircontext.d.ts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import type { DirContextSource } from './config.js';
|
|
1
2
|
/**
|
|
2
3
|
* Per-directory default org/project context.
|
|
3
4
|
*
|
|
@@ -43,3 +44,71 @@ export declare function findDirContextFile(startDir?: string): FoundDirContext |
|
|
|
43
44
|
export declare function writeDirContextFile(dir: string, context: DirContext): string;
|
|
44
45
|
/** Remove the `.fazemos.json` in `dir`. Returns the path if one was removed, else null. */
|
|
45
46
|
export declare function removeDirContextFile(dir: string): string | null;
|
|
47
|
+
/** Top-level commands that never need (and shouldn't trigger) context resolution. */
|
|
48
|
+
export declare const DIR_CONTEXT_SKIP: Set<string>;
|
|
49
|
+
/** The subset of the invoked command's own `.opts()` that affects bypass. */
|
|
50
|
+
export interface ApplyDirContextActionOpts {
|
|
51
|
+
/** An explicit per-command `--project <slug>` skips resolving the project pin. */
|
|
52
|
+
project?: string;
|
|
53
|
+
}
|
|
54
|
+
/** The agent credential's own scope, per `GET /api/members/me` (see `api.ts`). */
|
|
55
|
+
export interface CredentialScope {
|
|
56
|
+
orgId: string;
|
|
57
|
+
project: {
|
|
58
|
+
id: string;
|
|
59
|
+
slug: string;
|
|
60
|
+
} | null;
|
|
61
|
+
}
|
|
62
|
+
/** Injected collaborators so `applyDirContext` can be unit tested without the network or a real process exit. */
|
|
63
|
+
export interface ApplyDirContextDeps {
|
|
64
|
+
resolveOrgIdMaybeSlug: (value: string) => Promise<string>;
|
|
65
|
+
resolveProjectIdBySlug: (slugOverride?: string) => Promise<string | null>;
|
|
66
|
+
setOrgOverride: (orgId: string | null) => void;
|
|
67
|
+
setProjectOverride: (projectId: string | null) => void;
|
|
68
|
+
setDirContextSource: (source: DirContextSource | null) => void;
|
|
69
|
+
/** Must never return — matches `process.exit`'s type. */
|
|
70
|
+
exit: (code: number) => never;
|
|
71
|
+
env: NodeJS.ProcessEnv;
|
|
72
|
+
/** Write one line to stderr (color/formatting is the caller's concern). */
|
|
73
|
+
stderr: (message: string) => void;
|
|
74
|
+
/**
|
|
75
|
+
* BUG231-C1a — true when this run is authenticating as an agent
|
|
76
|
+
* (`FAZEMOS_API_KEY`), not a human Cognito session. Agent credentials
|
|
77
|
+
* can't use the `/auth/me`-backed resolvers above (403
|
|
78
|
+
* `WRONG_ENDPOINT_FOR_AGENT`), so a true result routes to the
|
|
79
|
+
* `fetchCredentialScope`-based path instead.
|
|
80
|
+
*/
|
|
81
|
+
isAgentCredential: () => boolean;
|
|
82
|
+
/**
|
|
83
|
+
* BUG231-C1a — fetch the agent credential's authoritative org/project
|
|
84
|
+
* scope from `GET /api/members/me`. Called at most once per invocation,
|
|
85
|
+
* and only when `isAgentCredential()` is true and a pin needs checking.
|
|
86
|
+
*/
|
|
87
|
+
fetchCredentialScope: () => Promise<CredentialScope>;
|
|
88
|
+
}
|
|
89
|
+
/**
|
|
90
|
+
* Resolve (or hard-error on) the nearest `.fazemos.json` pin for this
|
|
91
|
+
* invocation.
|
|
92
|
+
*
|
|
93
|
+
* Bypass order (Gate B amendment, fixed — do not reorder):
|
|
94
|
+
* 1. `FAZEMOS_IGNORE_DIR_CONTEXT=1` — skip everything. If a pin exists,
|
|
95
|
+
* record it with `ignored: true` so `whoami`/`config` can show it was
|
|
96
|
+
* seen but deliberately not applied. Not affected by a malformed pin.
|
|
97
|
+
* 2. The bootstrap command set (`use`/`auth`/`env`/`init`) — these
|
|
98
|
+
* manage or inspect the pin themselves and never resolve it here.
|
|
99
|
+
* 3. Find/parse the pin. A malformed file exits 2.
|
|
100
|
+
* 4. BUG231-C1a: an agent credential (`isAgentCredential()`) cannot use
|
|
101
|
+
* the `/auth/me`-backed resolvers below — that endpoint 403s
|
|
102
|
+
* (`WRONG_ENDPOINT_FOR_AGENT`) for agent callers. Branch to
|
|
103
|
+
* `applyAgentCredentialPin`, which checks the pin against the
|
|
104
|
+
* credential's own scope (`GET /api/members/me`) instead. The
|
|
105
|
+
* human/Cognito path below is exactly C1 as built — untouched.
|
|
106
|
+
* 5. The org pin, if set. No bypass except #1 above. Unresolvable → exit 2.
|
|
107
|
+
* 6. The project pin, if set. An explicit `--project <slug>` on the
|
|
108
|
+
* invoked command skips resolving it (the per-call override in `api.ts`
|
|
109
|
+
* handles that case instead). Otherwise unresolvable → exit 2.
|
|
110
|
+
*
|
|
111
|
+
* `--env` is applied by the caller before this runs (it affects which
|
|
112
|
+
* environment the resolvers hit), so it isn't part of this function.
|
|
113
|
+
*/
|
|
114
|
+
export declare function applyDirContext(topCommand: string, actionOpts: ApplyDirContextActionOpts, deps: ApplyDirContextDeps): Promise<void>;
|
package/dist/dircontext.js
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { existsSync, readFileSync, writeFileSync, rmSync } from 'fs';
|
|
2
2
|
import { dirname, join, parse as parsePath } from 'path';
|
|
3
|
+
import { EXIT } from './exitCodes.js';
|
|
3
4
|
/**
|
|
4
5
|
* Per-directory default org/project context.
|
|
5
6
|
*
|
|
@@ -86,4 +87,242 @@ export function removeDirContextFile(dir) {
|
|
|
86
87
|
rmSync(file);
|
|
87
88
|
return file;
|
|
88
89
|
}
|
|
90
|
+
// ── applyDirContext (BUG231-C1) ───────────────────────────────
|
|
91
|
+
//
|
|
92
|
+
// Resolves a discovered `.fazemos.json` pin to org/project ids and installs
|
|
93
|
+
// them as in-memory overrides, OR hard-errors (exit 2) when the pin cannot
|
|
94
|
+
// be resolved. There is no silent fallback to the machine-global active
|
|
95
|
+
// org/project anymore — per Marco's C1 contract, a write that can't confirm
|
|
96
|
+
// its pinned scope must not run at all.
|
|
97
|
+
//
|
|
98
|
+
// Extracted out of `index.ts` (Gate B amendment) so it can be unit tested
|
|
99
|
+
// with injected resolvers/exit/env instead of the `index.test.ts`
|
|
100
|
+
// `program.parseAsync` harness. This function holds NO module-level state —
|
|
101
|
+
// the caller (the `preAction` wrapper in `index.ts`) owns the
|
|
102
|
+
// once-per-process latch.
|
|
103
|
+
/** Top-level commands that never need (and shouldn't trigger) context resolution. */
|
|
104
|
+
export const DIR_CONTEXT_SKIP = new Set(['use', 'auth', 'env', 'init']);
|
|
105
|
+
const UUID_RE = /^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i;
|
|
106
|
+
/**
|
|
107
|
+
* Resolve (or hard-error on) the nearest `.fazemos.json` pin for this
|
|
108
|
+
* invocation.
|
|
109
|
+
*
|
|
110
|
+
* Bypass order (Gate B amendment, fixed — do not reorder):
|
|
111
|
+
* 1. `FAZEMOS_IGNORE_DIR_CONTEXT=1` — skip everything. If a pin exists,
|
|
112
|
+
* record it with `ignored: true` so `whoami`/`config` can show it was
|
|
113
|
+
* seen but deliberately not applied. Not affected by a malformed pin.
|
|
114
|
+
* 2. The bootstrap command set (`use`/`auth`/`env`/`init`) — these
|
|
115
|
+
* manage or inspect the pin themselves and never resolve it here.
|
|
116
|
+
* 3. Find/parse the pin. A malformed file exits 2.
|
|
117
|
+
* 4. BUG231-C1a: an agent credential (`isAgentCredential()`) cannot use
|
|
118
|
+
* the `/auth/me`-backed resolvers below — that endpoint 403s
|
|
119
|
+
* (`WRONG_ENDPOINT_FOR_AGENT`) for agent callers. Branch to
|
|
120
|
+
* `applyAgentCredentialPin`, which checks the pin against the
|
|
121
|
+
* credential's own scope (`GET /api/members/me`) instead. The
|
|
122
|
+
* human/Cognito path below is exactly C1 as built — untouched.
|
|
123
|
+
* 5. The org pin, if set. No bypass except #1 above. Unresolvable → exit 2.
|
|
124
|
+
* 6. The project pin, if set. An explicit `--project <slug>` on the
|
|
125
|
+
* invoked command skips resolving it (the per-call override in `api.ts`
|
|
126
|
+
* handles that case instead). Otherwise unresolvable → exit 2.
|
|
127
|
+
*
|
|
128
|
+
* `--env` is applied by the caller before this runs (it affects which
|
|
129
|
+
* environment the resolvers hit), so it isn't part of this function.
|
|
130
|
+
*/
|
|
131
|
+
export async function applyDirContext(topCommand, actionOpts, deps) {
|
|
132
|
+
if (deps.env.FAZEMOS_IGNORE_DIR_CONTEXT === '1') {
|
|
133
|
+
let found = null;
|
|
134
|
+
try {
|
|
135
|
+
found = findDirContextFile();
|
|
136
|
+
}
|
|
137
|
+
catch {
|
|
138
|
+
// Malformed, but we're bypassing entirely — nothing to report or apply.
|
|
139
|
+
found = null;
|
|
140
|
+
}
|
|
141
|
+
if (found) {
|
|
142
|
+
deps.setDirContextSource({ path: found.path, ...found.context, ignored: true });
|
|
143
|
+
}
|
|
144
|
+
return;
|
|
145
|
+
}
|
|
146
|
+
if (DIR_CONTEXT_SKIP.has(topCommand))
|
|
147
|
+
return;
|
|
148
|
+
let found;
|
|
149
|
+
try {
|
|
150
|
+
found = findDirContextFile();
|
|
151
|
+
}
|
|
152
|
+
catch (err) {
|
|
153
|
+
deps.stderr(err.message);
|
|
154
|
+
deps.exit(EXIT.USAGE);
|
|
155
|
+
return;
|
|
156
|
+
}
|
|
157
|
+
if (!found)
|
|
158
|
+
return;
|
|
159
|
+
deps.setDirContextSource({ path: found.path, ...found.context });
|
|
160
|
+
const { org, project } = found.context;
|
|
161
|
+
if (deps.isAgentCredential()) {
|
|
162
|
+
await applyAgentCredentialPin(found, org, project, actionOpts, deps);
|
|
163
|
+
return;
|
|
164
|
+
}
|
|
165
|
+
if (org) {
|
|
166
|
+
let orgId;
|
|
167
|
+
try {
|
|
168
|
+
orgId = await deps.resolveOrgIdMaybeSlug(org);
|
|
169
|
+
}
|
|
170
|
+
catch {
|
|
171
|
+
deps.stderr(`.fazemos.json pins org '${org}' but it could not be resolved ` +
|
|
172
|
+
`(offline, wrong --env, stale cache, or a typo'd slug). ` +
|
|
173
|
+
`Run with FAZEMOS_IGNORE_DIR_CONTEXT=1 to bypass, or fix the pin (fazemos use --org <slug>).`);
|
|
174
|
+
deps.exit(EXIT.USAGE);
|
|
175
|
+
return;
|
|
176
|
+
}
|
|
177
|
+
deps.setOrgOverride(orgId);
|
|
178
|
+
}
|
|
179
|
+
if (project) {
|
|
180
|
+
if (actionOpts.project) {
|
|
181
|
+
// The invoked command already supplies its own project scope — the
|
|
182
|
+
// pinned project is not resolved (and cannot exit 2) in this case.
|
|
183
|
+
}
|
|
184
|
+
else if (UUID_RE.test(project)) {
|
|
185
|
+
deps.setProjectOverride(project);
|
|
186
|
+
}
|
|
187
|
+
else {
|
|
188
|
+
let projectId;
|
|
189
|
+
try {
|
|
190
|
+
projectId = await deps.resolveProjectIdBySlug(project);
|
|
191
|
+
}
|
|
192
|
+
catch {
|
|
193
|
+
deps.stderr(`.fazemos.json pins project '${project}' but it could not be resolved. ` +
|
|
194
|
+
`Pass --project <slug>, or run with FAZEMOS_IGNORE_DIR_CONTEXT=1 to bypass.`);
|
|
195
|
+
deps.exit(EXIT.USAGE);
|
|
196
|
+
return;
|
|
197
|
+
}
|
|
198
|
+
if (projectId) {
|
|
199
|
+
deps.setProjectOverride(projectId);
|
|
200
|
+
}
|
|
201
|
+
else {
|
|
202
|
+
deps.stderr(`.fazemos.json pins project '${project}' but no such project exists in the active org. ` +
|
|
203
|
+
`Pass --project <slug>, or run with FAZEMOS_IGNORE_DIR_CONTEXT=1 to bypass.`);
|
|
204
|
+
deps.exit(EXIT.USAGE);
|
|
205
|
+
return;
|
|
206
|
+
}
|
|
207
|
+
}
|
|
208
|
+
}
|
|
209
|
+
}
|
|
210
|
+
// ── applyAgentCredentialPin (BUG231-C1a) ──────────────────────
|
|
211
|
+
//
|
|
212
|
+
// Resolves (or hard-errors on) a `.fazemos.json` pin under an agent
|
|
213
|
+
// credential (`FAZEMOS_API_KEY` set). `/auth/me` 403s for agents
|
|
214
|
+
// (`WRONG_ENDPOINT_FOR_AGENT`), so the credential's own scope — fetched
|
|
215
|
+
// once via `GET /api/members/me` — is authoritative and the pin is
|
|
216
|
+
// *checked against it* rather than resolved through it. See the
|
|
217
|
+
// 2026-09-24 C1a ruling (rules 1-3) for the full contract this implements.
|
|
218
|
+
/**
|
|
219
|
+
* @param found the discovered `.fazemos.json` (path + raw context), reused
|
|
220
|
+
* for the final `setDirContextSource` call so the `verified` marker lands
|
|
221
|
+
* on the same record the caller already stamped.
|
|
222
|
+
*/
|
|
223
|
+
async function applyAgentCredentialPin(found, org, project, actionOpts, deps) {
|
|
224
|
+
// An explicit --project bypasses the project pin exactly as it does on
|
|
225
|
+
// the human path (rule 2's carve-out). If that leaves nothing to check
|
|
226
|
+
// (no org pin either), there's no reason to hit /api/members/me at all.
|
|
227
|
+
const needsProjectCheck = !!project && !actionOpts.project;
|
|
228
|
+
if (!org && !needsProjectCheck)
|
|
229
|
+
return;
|
|
230
|
+
let scope;
|
|
231
|
+
try {
|
|
232
|
+
scope = await deps.fetchCredentialScope();
|
|
233
|
+
}
|
|
234
|
+
catch (err) {
|
|
235
|
+
// Rule 1: a /members/me failure is an API failure, not a context error
|
|
236
|
+
// — it must never surface as EXIT.USAGE. fetchCredentialScope (api.ts)
|
|
237
|
+
// stamps `.exitCode` with EXIT.AUTH (401) or EXIT.API (anything else);
|
|
238
|
+
// fall back to EXIT.API if a differently-shaped error slips through.
|
|
239
|
+
deps.stderr(typeof err?.message === 'string' ? err.message : `could not verify agent credential scope: ${err}`);
|
|
240
|
+
deps.exit(typeof err?.exitCode === 'number' ? err.exitCode : EXIT.API);
|
|
241
|
+
return;
|
|
242
|
+
}
|
|
243
|
+
// Security re-review (niko, web-security-ops, M1-2): rule 3 assumes a
|
|
244
|
+
// slug org pin resolves to "member.org_id, which equals env
|
|
245
|
+
// FAZEMOS_ORG_ID for the primary key" — turn that assumption into an
|
|
246
|
+
// assertion. If the launcher's own FAZEMOS_ORG_ID disagrees with what
|
|
247
|
+
// /members/me just reported, something is wrong with the credential or
|
|
248
|
+
// the environment itself; that's a context error the guard should stop,
|
|
249
|
+
// not something to reason further about with a possibly-untrustworthy
|
|
250
|
+
// scope.
|
|
251
|
+
const envOrgId = deps.env.FAZEMOS_ORG_ID;
|
|
252
|
+
if (envOrgId && scope.orgId !== envOrgId) {
|
|
253
|
+
deps.stderr(`agent credential org does not match FAZEMOS_ORG_ID (GET /api/members/me reported ` +
|
|
254
|
+
`member.org_id='${scope.orgId}', but FAZEMOS_ORG_ID='${envOrgId}'). This indicates a ` +
|
|
255
|
+
`credential/environment mismatch, not a resolvable pin.`);
|
|
256
|
+
deps.exit(EXIT.USAGE);
|
|
257
|
+
return;
|
|
258
|
+
}
|
|
259
|
+
// Tracks whether the *project* pin was itself confirmed against the
|
|
260
|
+
// credential — a matched project implies its org too (a project belongs
|
|
261
|
+
// to exactly one org), which is what lets a slug org pin below count as
|
|
262
|
+
// 'credential'-verified instead of merely assumed.
|
|
263
|
+
let projectVerified = false;
|
|
264
|
+
if (needsProjectCheck) {
|
|
265
|
+
if (scope.project) {
|
|
266
|
+
const matches = project === scope.project.id || project === scope.project.slug;
|
|
267
|
+
if (!matches) {
|
|
268
|
+
// Rule 2: a positive mismatch is a real wrong-scope signal — the
|
|
269
|
+
// guard keeps its teeth for it.
|
|
270
|
+
deps.stderr(`.fazemos.json pins project '${project}' but this agent credential is scoped to project '${scope.project.slug}'.`);
|
|
271
|
+
deps.exit(EXIT.USAGE);
|
|
272
|
+
return;
|
|
273
|
+
}
|
|
274
|
+
deps.setProjectOverride(scope.project.id);
|
|
275
|
+
projectVerified = true;
|
|
276
|
+
}
|
|
277
|
+
else {
|
|
278
|
+
// scope.project is null — the pin isn't verifiable at all. Per L1
|
|
279
|
+
// (niko, web-security-ops): this isn't only an org-level key; a
|
|
280
|
+
// human-held project-scoped fzm_ key reads the same way (project is
|
|
281
|
+
// populated only for isAgent callers — fazemos-api
|
|
282
|
+
// src/routes/members.ts). Word this around the fact actually
|
|
283
|
+
// observed (no project scope came back), not a guess at why.
|
|
284
|
+
// Proceed on FAZEMOS_PROJECT_ID if the environment set one; no exit,
|
|
285
|
+
// per rule 2.
|
|
286
|
+
const envProjectId = deps.env.FAZEMOS_PROJECT_ID;
|
|
287
|
+
if (envProjectId) {
|
|
288
|
+
deps.setProjectOverride(envProjectId);
|
|
289
|
+
}
|
|
290
|
+
deps.stderr(`project pin '${project}' not verified: credential project scope not returned by /api/members/me; using FAZEMOS_PROJECT_ID`);
|
|
291
|
+
}
|
|
292
|
+
}
|
|
293
|
+
let verified = projectVerified ? 'credential' : 'unverified';
|
|
294
|
+
if (org) {
|
|
295
|
+
if (UUID_RE.test(org)) {
|
|
296
|
+
if (org !== scope.orgId) {
|
|
297
|
+
deps.stderr(`.fazemos.json pins org '${org}' but this agent credential is scoped to org '${scope.orgId}'.`);
|
|
298
|
+
deps.exit(EXIT.USAGE);
|
|
299
|
+
return;
|
|
300
|
+
}
|
|
301
|
+
deps.setOrgOverride(scope.orgId);
|
|
302
|
+
verified = 'credential';
|
|
303
|
+
}
|
|
304
|
+
else {
|
|
305
|
+
// Rule 3, cross-org keys: a key for the pinned slug exists only for
|
|
306
|
+
// orgs other than the credential's own (F49 CHG-2) — its presence
|
|
307
|
+
// alone means this is a cross-org pin, which C1a doesn't support.
|
|
308
|
+
const upperSnake = org.toUpperCase().replace(/-/g, '_');
|
|
309
|
+
if (deps.env[`FAZEMOS_API_KEY__${upperSnake}`]) {
|
|
310
|
+
deps.stderr(`.fazemos.json pins org '${org}', which has a cross-org agent credential configured; ` +
|
|
311
|
+
`cross-org pin under an agent credential is not supported by C1a, pass --org explicitly.`);
|
|
312
|
+
deps.exit(EXIT.USAGE);
|
|
313
|
+
return;
|
|
314
|
+
}
|
|
315
|
+
// A slug can't be resolved for agents (no /auth/me). Resolve as the
|
|
316
|
+
// credential's own org — it's server-side org-bound and cannot write
|
|
317
|
+
// cross-org, so this never exits. It's 'credential'-verified only
|
|
318
|
+
// when the project pin above already confirmed it.
|
|
319
|
+
deps.setOrgOverride(scope.orgId);
|
|
320
|
+
if (verified !== 'credential') {
|
|
321
|
+
deps.stderr(`.fazemos.json pins org '${org}' by slug, which an agent credential cannot verify; ` +
|
|
322
|
+
`proceeding with the credential's own org (unverified).`);
|
|
323
|
+
}
|
|
324
|
+
}
|
|
325
|
+
}
|
|
326
|
+
deps.setDirContextSource({ path: found.path, ...found.context, verified });
|
|
327
|
+
}
|
|
89
328
|
//# sourceMappingURL=dircontext.js.map
|
package/dist/dircontext.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"dircontext.js","sourceRoot":"","sources":["../src/dircontext.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,YAAY,EAAE,aAAa,EAAE,MAAM,EAAE,MAAM,IAAI,CAAC;AACrE,OAAO,EAAE,OAAO,EAAE,IAAI,EAAE,KAAK,IAAI,SAAS,EAAE,MAAM,MAAM,CAAC;
|
|
1
|
+
{"version":3,"file":"dircontext.js","sourceRoot":"","sources":["../src/dircontext.ts"],"names":[],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