perfai-cloud-mcp 0.1.0 → 0.3.0
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/README.md +47 -26
- package/dist/auth/oauthFlow.d.ts +1 -1
- package/dist/auth/oauthFlow.js +3 -3
- package/dist/auth/tokenValidator.d.ts +2 -2
- package/dist/auth/tokenValidator.js +3 -3
- package/dist/cli.js +42 -42
- package/dist/client/apiClient.d.ts +13 -4
- package/dist/client/apiClient.d.ts.map +1 -1
- package/dist/client/apiClient.js +63 -9
- package/dist/client/authManager.d.ts +20 -1
- package/dist/client/authManager.d.ts.map +1 -1
- package/dist/client/authManager.js +47 -0
- package/dist/client/types.d.ts +18 -0
- package/dist/client/types.d.ts.map +1 -1
- package/dist/config.d.ts +4 -0
- package/dist/config.d.ts.map +1 -1
- package/dist/config.js +23 -4
- package/dist/prompts.d.ts +31 -0
- package/dist/prompts.d.ts.map +1 -0
- package/dist/prompts.js +53 -0
- package/dist/server.js +37 -10
- package/dist/tools/index.d.ts +70 -18
- package/dist/tools/index.d.ts.map +1 -1
- package/dist/tools/index.js +3 -1
- package/dist/tools/protected/autoFix.d.ts +5 -1
- package/dist/tools/protected/autoFix.d.ts.map +1 -1
- package/dist/tools/protected/autoFix.js +27 -12
- package/dist/tools/protected/autoFixAll.d.ts +6 -2
- package/dist/tools/protected/autoFixAll.d.ts.map +1 -1
- package/dist/tools/protected/autoFixAll.js +29 -32
- package/dist/tools/protected/getFixSummary.d.ts +5 -1
- package/dist/tools/protected/getFixSummary.d.ts.map +1 -1
- package/dist/tools/protected/getFixSummary.js +35 -36
- package/dist/tools/protected/getVulnerabilities.d.ts +5 -1
- package/dist/tools/protected/getVulnerabilities.d.ts.map +1 -1
- package/dist/tools/protected/getVulnerabilities.js +7 -5
- package/dist/tools/protected/listApps.d.ts +1 -1
- package/dist/tools/protected/listApps.d.ts.map +1 -1
- package/dist/tools/protected/listApps.js +2 -1
- package/dist/tools/protected/logout.d.ts +1 -1
- package/dist/tools/protected/logout.js +1 -1
- package/dist/tools/protected/manageOrganizations.d.ts +26 -0
- package/dist/tools/protected/manageOrganizations.d.ts.map +1 -0
- package/dist/tools/protected/manageOrganizations.js +131 -0
- package/dist/tools/protected/registerApp.d.ts +1 -1
- package/dist/tools/protected/registerApp.js +3 -3
- package/dist/tools/protected/runSecurityTest.d.ts +5 -1
- package/dist/tools/protected/runSecurityTest.d.ts.map +1 -1
- package/dist/tools/protected/runSecurityTest.js +7 -5
- package/dist/tools/protected/selectApp.d.ts +1 -1
- package/dist/tools/protected/selectApp.d.ts.map +1 -1
- package/dist/tools/protected/selectApp.js +3 -1
- package/dist/tools/protected/vulnerabilityActions.d.ts +12 -4
- package/dist/tools/protected/vulnerabilityActions.d.ts.map +1 -1
- package/dist/tools/protected/vulnerabilityActions.js +25 -6
- package/dist/tools/public/authStatus.d.ts +1 -1
- package/dist/tools/public/authStatus.js +1 -1
- package/dist/tools/public/login.d.ts +12 -2
- package/dist/tools/public/login.d.ts.map +1 -1
- package/dist/tools/public/login.js +78 -86
- package/dist/utils/appResolver.d.ts +24 -0
- package/dist/utils/appResolver.d.ts.map +1 -0
- package/dist/utils/appResolver.js +156 -0
- package/dist/utils/formatters.d.ts +2 -1
- package/dist/utils/formatters.d.ts.map +1 -1
- package/dist/utils/formatters.js +19 -1
- package/dist/utils/promptBuilder.d.ts +8 -2
- package/dist/utils/promptBuilder.d.ts.map +1 -1
- package/dist/utils/promptBuilder.js +42 -26
- package/package.json +7 -8
- package/LICENSE +0 -21
package/README.md
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
#
|
|
1
|
+
# Perfai Cloud MCP Server
|
|
2
2
|
|
|
3
|
-
A standalone Model Context Protocol (MCP) server for the **hosted
|
|
3
|
+
A standalone Model Context Protocol (MCP) server for the **hosted Perfai cloud API**. Register an app by its URL, let Perfai run a security test in the cloud, pull the findings, and get an AI-powered fix prompt — from any MCP-compatible client.
|
|
4
4
|
|
|
5
5
|
|
|
6
6
|
## Authentication
|
|
@@ -8,7 +8,7 @@ A standalone Model Context Protocol (MCP) server for the **hosted PerfAI cloud A
|
|
|
8
8
|
1. **`PERFAI_TOKEN` env var** — if set, the server starts already authenticated, no `login` call needed. This is the same session token the OAuth/browser flows below produce — paste in one you already have.
|
|
9
9
|
2. **Explicit args** — `login {"email": "...", "password": "..."}`
|
|
10
10
|
3. **Env credentials** — `PERFAI_EMAIL` / `PERFAI_PASSWORD` set in the server's env; `login {}` authenticates directly.
|
|
11
|
-
4. **OAuth login** (Auth0 Authorization Code + PKCE) — if none of the above is available and `AUTH0_CLIENT_ID` is configured (it defaults to
|
|
11
|
+
4. **OAuth login** (Auth0 Authorization Code + PKCE) — if none of the above is available and `AUTH0_CLIENT_ID` is configured (it defaults to Perfai's own client, so this is on by default), `login {}` opens your browser to Auth0's hosted login page and starts a local callback server on `OAUTH_CALLBACK_PORT` (default `5173`). If your browser already has an active Auth0 session, this can complete silently via SSO without prompting for credentials again.
|
|
12
12
|
5. **Legacy browser login form** — fallback if OAuth is explicitly disabled (`AUTH0_CLIENT_ID=""`): opens a local HTML login form on `http://127.0.0.1:18200–18300`.
|
|
13
13
|
|
|
14
14
|
Once you see "Authenticated!" in the browser, call `login` again to confirm the session server-side.
|
|
@@ -19,15 +19,6 @@ auth_status # verify you're authenticated, see auth method, current a
|
|
|
19
19
|
logout # clear session
|
|
20
20
|
```
|
|
21
21
|
|
|
22
|
-
For cloud workspace environments, set `PERFAI_TOKEN` in the MCP server's env config instead. It's the same session token the browser/OAuth flow already produces:
|
|
23
|
-
|
|
24
|
-
1. Sign in once at [cloud.perfai.ai](https://cloud.perfai.ai) (or run the OAuth flow locally once).
|
|
25
|
-
2. Copy your `id_token` from the console, or from the `login` tool's confirmation output.
|
|
26
|
-
3. Paste it into your cloud workspace's MCP server config as `PERFAI_TOKEN`. No password ever touches that environment.
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
See `.env.example` for the full token/OAuth configuration reference.
|
|
30
|
-
|
|
31
22
|
---
|
|
32
23
|
|
|
33
24
|
## Available Tools
|
|
@@ -35,10 +26,16 @@ See `.env.example` for the full token/OAuth configuration reference.
|
|
|
35
26
|
### Authentication
|
|
36
27
|
| Tool | Description |
|
|
37
28
|
| --- | --- |
|
|
38
|
-
| `login` | Sign in to
|
|
29
|
+
| `login` | Sign in to Perfai. Opens browser or uses provided credentials. |
|
|
39
30
|
| `auth_status` | Check if you're currently authenticated. |
|
|
40
31
|
| `logout` | Sign out and clear session. |
|
|
41
32
|
|
|
33
|
+
### Organization Management
|
|
34
|
+
| Tool | Description |
|
|
35
|
+
| --- | --- |
|
|
36
|
+
| `manage_organizations` | List the organizations (tenants) your account belongs to and switch between them. Actions: `list` (default), `select` (by `sequence` or `org_id`), `refresh`. Not needed for fixing — app names are resolved across all orgs. |
|
|
37
|
+
|
|
38
|
+
|
|
42
39
|
### App Management
|
|
43
40
|
| Tool | Description |
|
|
44
41
|
| --- | --- |
|
|
@@ -51,23 +48,41 @@ See `.env.example` for the full token/OAuth configuration reference.
|
|
|
51
48
|
### Security Testing
|
|
52
49
|
| Tool | Description |
|
|
53
50
|
| --- | --- |
|
|
54
|
-
| `run_security_test` | Start a security scan
|
|
51
|
+
| `run_security_test` | Start a security scan. Accepts `app` (name) or `appId`. |
|
|
55
52
|
| `check_task_status` | Poll scan progress until complete. |
|
|
56
53
|
|
|
57
54
|
### Vulnerability Management
|
|
58
55
|
| Tool | Description |
|
|
59
56
|
| --- | --- |
|
|
60
|
-
| `get_vulnerabilities` | List all findings from the latest scan. |
|
|
57
|
+
| `get_vulnerabilities` | List all findings from the latest scan. Accepts `app` (name) or `appId`. |
|
|
61
58
|
| `suggest_fix` | Get a conversational fix prompt for a specific vulnerability. |
|
|
62
|
-
| `auto_fix` | Get structured, step-by-step fix instructions for one vulnerability. |
|
|
63
|
-
| `auto_fix_all` |
|
|
64
|
-
| `get_fix_summary` |
|
|
65
|
-
| `dismiss_vulnerability` | Dismiss a finding (false positive, accepted risk, etc.). |
|
|
59
|
+
| `auto_fix` | Get structured, step-by-step fix instructions for one vulnerability. Accepts `app` (name). |
|
|
60
|
+
| `auto_fix_all` | The one-line fix. Takes `app` (name), optional `severity` / `max_fixes`; returns a prioritized plan the agent runs autonomously, 15 findings per batch. |
|
|
61
|
+
| `get_fix_summary` | Fix progress: fixed, skipped as not applicable, still open — by severity. Accepts `app` (name). |
|
|
62
|
+
| `dismiss_vulnerability` | Dismiss a finding (false positive, accepted risk, etc.) with an optional `reason`, stored on the finding. |
|
|
66
63
|
| `reopen_vulnerability` | Reopen a previously dismissed finding. |
|
|
67
|
-
| `mark_vulnerability_fixed` |
|
|
64
|
+
| `mark_vulnerability_fixed` | Claim a finding as fixed after applying the code change; the next scan confirms it. |
|
|
68
65
|
|
|
69
66
|
---
|
|
70
67
|
|
|
68
|
+
## One-line fix
|
|
69
|
+
|
|
70
|
+
Connect the server to your code agent, sign in with `login`, open the app's codebase, and type:
|
|
71
|
+
|
|
72
|
+
> **<App_name> fix all**
|
|
73
|
+
|
|
74
|
+
That's it: no listing orgs, listing apps, or selecting a project. The agent calls `auto_fix_all` with `app: "<App_name>"`; the name is resolved across every organization you belong to, the right org and app are selected, and the agent fixes every open finding from critical to low. Findings that don't apply to your code are dismissed silently with a reason, and the run ends with one line of counts.
|
|
75
|
+
|
|
76
|
+
| Say | Does |
|
|
77
|
+
| --- | --- |
|
|
78
|
+
| `<App_name> fix all` | Every open finding |
|
|
79
|
+
| `<App_name> fix critical` | Only critical (also `high`, `medium`, `low`) |
|
|
80
|
+
| `<App_name> fix 1` | The single most severe open finding (`fix 5` → top 5) |
|
|
81
|
+
|
|
82
|
+
Clients that support MCP prompts also get it as a slash command — in Claude Code: `/mcp__perfai-cloud__fix_all <App_name>` or `/mcp__perfai-cloud__fix <App_name> critical` (the middle part is whatever you named the server).
|
|
83
|
+
|
|
84
|
+
You only see a list when the name is ambiguous (e.g. two apps called "Shared" in different orgs) — pick one and the run continues. An exact name wins over partial ones, so `<App_name>` is not ambiguous with `<App_name>-staging`.
|
|
85
|
+
|
|
71
86
|
## Typical Workflow
|
|
72
87
|
|
|
73
88
|
### The simple version
|
|
@@ -102,9 +117,12 @@ Here are some things you can say to your AI assistant:
|
|
|
102
117
|
| What you want | What to say |
|
|
103
118
|
| --- | --- |
|
|
104
119
|
| **Full scan** | *"Register https://api.myapp.com, run a security test, and show me all vulnerabilities."* |
|
|
105
|
-
| **Fix everything** | *"
|
|
120
|
+
| **Fix everything** | *"Bookstore fix all"* |
|
|
121
|
+
| **Fix only critical** | *"Bookstore fix critical"* |
|
|
106
122
|
| **Fix one issue** | *"Show me how to fix vulnerability #2."* |
|
|
107
123
|
| **Check progress** | *"Show me the fix summary for my app."* |
|
|
124
|
+
| **List organizations** | *"List my organizations."* |
|
|
125
|
+
| **Switch organization** | *"Switch to the second organization, then list my apps."* |
|
|
108
126
|
| **List my apps** | *"List all my registered apps."* |
|
|
109
127
|
| **Switch apps** | *"Select the app with URL https://other-app.com."* |
|
|
110
128
|
| **Dismiss a finding** | *"Dismiss vulnerability #3 — it's a false positive."* |
|
|
@@ -153,10 +171,11 @@ $env:MCP_TRANSPORT="http"; node dist/server.js
|
|
|
153
171
|
| `PERFAI_EMAIL` | No | — | Auto-login email (for local/stdio mode) |
|
|
154
172
|
| `PERFAI_PASSWORD` | No | — | Auto-login password (for local/stdio mode) |
|
|
155
173
|
| `AUTH0_DOMAIN` | No | `auth.perfai.ai` | Auth0 tenant domain used for OAuth PKCE login and HTTP bearer-token validation |
|
|
156
|
-
| `AUTH0_CLIENT_ID` | No | *(
|
|
174
|
+
| `AUTH0_CLIENT_ID` | No | *(Perfai's public client)* | Auth0 application client ID for the OAuth PKCE browser flow |
|
|
157
175
|
| `AUTH0_AUDIENCE` | No | — | Auth0 API audience, if your tenant requires one |
|
|
158
176
|
| `OAUTH_CALLBACK_PORT` | No | `5173` | Local port the OAuth flow listens on for the Auth0 redirect |
|
|
159
177
|
| `OAUTH_SCOPES` | No | `openid profile email offline_access` | Scopes requested during OAuth login |
|
|
178
|
+
| `LOGIN_WAIT_SECONDS` | No | `90` | How long `login` waits for the browser sign-in before asking the agent to call it again. Keep it under your client's tool-call timeout |
|
|
160
179
|
| `MCP_API_KEY` | No | — | Legacy static API key (accepted alongside credential tokens) |
|
|
161
180
|
|
|
162
181
|
### Deploy with Docker
|
|
@@ -188,11 +207,12 @@ Opens the Inspector UI at `http://localhost:6274` where you can test tools inter
|
|
|
188
207
|
|
|
189
208
|
## API Mapping
|
|
190
209
|
|
|
191
|
-
Every tool maps directly to a
|
|
210
|
+
Every tool maps directly to a Perfai cloud API endpoint:
|
|
192
211
|
|
|
193
212
|
| Tool | API Endpoint |
|
|
194
213
|
| --- | --- |
|
|
195
214
|
| `login` | `POST /api/v1/auth/token` |
|
|
215
|
+
| `manage_organizations` | `GET /api/v1/org-users/get_users_orgs` (selected org is then sent as the `X-Org-ID` header on app requests) |
|
|
196
216
|
| `register_app` | `POST /v1/apps` |
|
|
197
217
|
| `check_app_status` | `GET /v1/apps/{appId}` |
|
|
198
218
|
| `list_apps` | `GET /v1/apps` |
|
|
@@ -205,10 +225,11 @@ Every tool maps directly to a PerfAI cloud API endpoint:
|
|
|
205
225
|
| `auto_fix` | Local prompt builder (no API call) |
|
|
206
226
|
| `auto_fix_all` | `GET /v1/apps/{appId}/vulnerabilities` + local prompt builder |
|
|
207
227
|
| `get_fix_summary` | `GET /v1/apps/{appId}/vulnerabilities` + local aggregation |
|
|
208
|
-
| `dismiss_vulnerability` | `POST /v1/vulnerabilities/{id}/dismiss` |
|
|
228
|
+
| `dismiss_vulnerability` | `POST /v1/vulnerabilities/{id}/dismiss` (`reason` → `comment`) |
|
|
209
229
|
| `reopen_vulnerability` | `POST /v1/vulnerabilities/{id}/reopen` |
|
|
210
230
|
| `mark_vulnerability_fixed` | `POST /v1/vulnerabilities/{id}/fix` |
|
|
211
|
-
| `
|
|
231
|
+
| `app` name on any tool | `GET /v1/apps?search=` in the session org; on a miss, `GET /api/v1/org-users/get_users_orgs` then the same search per org with `X-Org-ID` |
|
|
232
|
+
| `auth_status` / `logout` | Local session state only (`logout` also clears the selected organization) |
|
|
212
233
|
|
|
213
234
|
---
|
|
214
235
|
|
|
@@ -231,7 +252,7 @@ Every tool maps directly to a PerfAI cloud API endpoint:
|
|
|
231
252
|
## Security
|
|
232
253
|
|
|
233
254
|
- Access tokens are transmitted over **HTTPS** only
|
|
234
|
-
- Tokens are validated against the
|
|
255
|
+
- Tokens are validated against the Perfai cloud auth API on every new session
|
|
235
256
|
- Validated tokens are cached server-side for 30 minutes to reduce auth API calls
|
|
236
257
|
- Each MCP session gets its own isolated authentication state
|
|
237
258
|
- No credentials are stored on disk by the MCP server
|
package/dist/auth/oauthFlow.d.ts
CHANGED
|
@@ -17,7 +17,7 @@ export interface OAuthTokens {
|
|
|
17
17
|
*
|
|
18
18
|
* Reuses the existing login token — no new auth mechanism — just the
|
|
19
19
|
* standard Auth0 PKCE handshake that produces the same id_token the
|
|
20
|
-
*
|
|
20
|
+
* Perfai API already accepts.
|
|
21
21
|
*/
|
|
22
22
|
export declare function startOAuthBrowserFlow(): Promise<OAuthTokens>;
|
|
23
23
|
//# sourceMappingURL=oauthFlow.d.ts.map
|
package/dist/auth/oauthFlow.js
CHANGED
|
@@ -24,7 +24,7 @@ function openBrowser(url) {
|
|
|
24
24
|
*
|
|
25
25
|
* Reuses the existing login token — no new auth mechanism — just the
|
|
26
26
|
* standard Auth0 PKCE handshake that produces the same id_token the
|
|
27
|
-
*
|
|
27
|
+
* Perfai API already accepts.
|
|
28
28
|
*/
|
|
29
29
|
export function startOAuthBrowserFlow() {
|
|
30
30
|
return new Promise((resolve, reject) => {
|
|
@@ -48,13 +48,13 @@ export function startOAuthBrowserFlow() {
|
|
|
48
48
|
}
|
|
49
49
|
};
|
|
50
50
|
const SUCCESS_HTML = `<!DOCTYPE html><html><head><meta charset="UTF-8">
|
|
51
|
-
<title>
|
|
51
|
+
<title>Perfai — Authenticated</title>
|
|
52
52
|
<style>*{margin:0;padding:0;box-sizing:border-box}body{font-family:-apple-system,BlinkMacSystemFont,'Segoe UI',Roboto,sans-serif;background:#f5f5f5;display:flex;align-items:center;justify-content:center;min-height:100vh}
|
|
53
53
|
.c{background:#fff;border-radius:12px;padding:40px;box-shadow:0 4px 24px rgba(0,0,0,.1);max-width:420px;text-align:center}
|
|
54
54
|
h1{color:#38a169;font-size:24px;margin-bottom:12px}p{color:#666;font-size:14px;line-height:1.5}</style></head>
|
|
55
55
|
<body><div class="c"><h1>Authenticated!</h1><p>You can close this tab and return to your AI assistant.</p></div></body></html>`;
|
|
56
56
|
const ERROR_HTML = (msg) => `<!DOCTYPE html><html><head><meta charset="UTF-8">
|
|
57
|
-
<title>
|
|
57
|
+
<title>Perfai — Error</title>
|
|
58
58
|
<style>*{margin:0;padding:0;box-sizing:border-box}body{font-family:-apple-system,BlinkMacSystemFont,'Segoe UI',Roboto,sans-serif;background:#f5f5f5;display:flex;align-items:center;justify-content:center;min-height:100vh}
|
|
59
59
|
.c{background:#fff;border-radius:12px;padding:40px;box-shadow:0 4px 24px rgba(0,0,0,.1);max-width:420px;text-align:center}
|
|
60
60
|
h1{color:#e53e3e;font-size:24px;margin-bottom:12px}p{color:#666;font-size:14px;line-height:1.5}</style></head>
|
|
@@ -6,9 +6,9 @@
|
|
|
6
6
|
* This avoids pulling in a JWKS library while still validating tokens
|
|
7
7
|
* against the real authorization server.
|
|
8
8
|
*
|
|
9
|
-
* For id_tokens (which the
|
|
9
|
+
* For id_tokens (which the Perfai API accepts as Bearer), we also
|
|
10
10
|
* support a basic structural check + expiry validation without
|
|
11
|
-
* signature verification — the
|
|
11
|
+
* signature verification — the Perfai API itself is the final
|
|
12
12
|
* authority on token validity.
|
|
13
13
|
*/
|
|
14
14
|
interface TokenValidation {
|
|
@@ -60,7 +60,7 @@ export async function validateBearerToken(token) {
|
|
|
60
60
|
const audiences = Array.isArray(payload.aud) ? payload.aud : [payload.aud];
|
|
61
61
|
if (!audiences.includes(AUTH0_AUDIENCE)) {
|
|
62
62
|
// Don't reject — the id_token's audience might be the Auth0 client_id,
|
|
63
|
-
// not the API audience. The
|
|
63
|
+
// not the API audience. The Perfai API is the final validator.
|
|
64
64
|
}
|
|
65
65
|
}
|
|
66
66
|
const email = payload.email ?? payload.sub;
|
|
@@ -76,7 +76,7 @@ export async function validateBearerToken(token) {
|
|
|
76
76
|
}
|
|
77
77
|
// /userinfo might fail for id_tokens — fall back to structural + expiry check
|
|
78
78
|
}
|
|
79
|
-
// Structural + expiry check passed — trust the token and let the
|
|
79
|
+
// Structural + expiry check passed — trust the token and let the Perfai
|
|
80
80
|
// API do final validation when tools make API calls
|
|
81
81
|
if (email) {
|
|
82
82
|
validatedTokens.set(token, { email, validatedAt: Date.now() });
|
|
@@ -105,7 +105,7 @@ async function validateViaUserInfo(token) {
|
|
|
105
105
|
if (axios.isAxiosError(err) && err.response?.status === 401) {
|
|
106
106
|
return { valid: false, error: "Token rejected by authorization server" };
|
|
107
107
|
}
|
|
108
|
-
// Network error — don't reject the token, let
|
|
108
|
+
// Network error — don't reject the token, let Perfai API validate it
|
|
109
109
|
return { valid: true, error: "Could not reach authorization server for validation" };
|
|
110
110
|
}
|
|
111
111
|
}
|
package/dist/cli.js
CHANGED
|
@@ -54,25 +54,25 @@ function openBrowser(url) {
|
|
|
54
54
|
: `xdg-open "${url}"`;
|
|
55
55
|
exec(cmd, () => { });
|
|
56
56
|
}
|
|
57
|
-
const LOGIN_HTML = `<!DOCTYPE html><html><head><meta charset="UTF-8"><meta name="viewport" content="width=device-width,initial-scale=1">
|
|
58
|
-
<title>
|
|
59
|
-
*{margin:0;padding:0;box-sizing:border-box}body{font-family:-apple-system,BlinkMacSystemFont,'Segoe UI',Roboto,sans-serif;background:#f5f5f5;display:flex;align-items:center;justify-content:center;min-height:100vh}
|
|
60
|
-
.c{background:#fff;border-radius:12px;padding:40px;box-shadow:0 4px 24px rgba(0,0,0,.1);width:100%;max-width:400px}
|
|
61
|
-
.logo{text-align:center;margin-bottom:24px}.logo h1{font-size:24px;color:#111}.logo p{color:#666;font-size:14px;margin-top:4px}
|
|
62
|
-
label{display:block;font-size:14px;font-weight:500;color:#333;margin-bottom:6px}
|
|
63
|
-
input{width:100%;padding:10px 12px;border:1px solid #ddd;border-radius:8px;font-size:14px;margin-bottom:16px;outline:none}input:focus{border-color:#111}
|
|
64
|
-
button{width:100%;padding:12px;background:#111;color:#fff;border:none;border-radius:8px;font-size:15px;font-weight:600;cursor:pointer}button:hover{background:#333}button:disabled{background:#999}
|
|
65
|
-
.err{color:#e53e3e;font-size:13px;margin-bottom:12px;display:none}.ok{text-align:center;color:#38a169;font-size:16px;font-weight:600;display:none;margin-top:16px}
|
|
66
|
-
</style></head><body><div class="c"><div class="logo"><h1>
|
|
67
|
-
<form id="f"><label for="e">Email</label><input type="email" id="e" placeholder="you@example.com" required autofocus>
|
|
68
|
-
<label for="p">Password</label><input type="password" id="p" placeholder="Your password" required>
|
|
69
|
-
<div class="err" id="x"></div><button type="submit" id="b">Sign in</button></form>
|
|
70
|
-
<div class="ok" id="s">Authenticated! You can close this tab.</div></div>
|
|
71
|
-
<script>document.getElementById('f').addEventListener('submit',async e=>{e.preventDefault();const b=document.getElementById('b'),x=document.getElementById('x');
|
|
72
|
-
b.disabled=true;b.textContent='Signing in...';x.style.display='none';try{const r=await fetch('/auth',{method:'POST',headers:{'Content-Type':'application/json'},
|
|
73
|
-
body:JSON.stringify({email:document.getElementById('e').value,password:document.getElementById('p').value})});const d=await r.json();
|
|
74
|
-
if(d.ok){document.getElementById('f').style.display='none';document.getElementById('s').style.display='block'}
|
|
75
|
-
else{x.textContent=d.message||'Login failed';x.style.display='block';b.disabled=false;b.textContent='Sign in'}}
|
|
57
|
+
const LOGIN_HTML = `<!DOCTYPE html><html><head><meta charset="UTF-8"><meta name="viewport" content="width=device-width,initial-scale=1">
|
|
58
|
+
<title>Perfai Login</title><style>
|
|
59
|
+
*{margin:0;padding:0;box-sizing:border-box}body{font-family:-apple-system,BlinkMacSystemFont,'Segoe UI',Roboto,sans-serif;background:#f5f5f5;display:flex;align-items:center;justify-content:center;min-height:100vh}
|
|
60
|
+
.c{background:#fff;border-radius:12px;padding:40px;box-shadow:0 4px 24px rgba(0,0,0,.1);width:100%;max-width:400px}
|
|
61
|
+
.logo{text-align:center;margin-bottom:24px}.logo h1{font-size:24px;color:#111}.logo p{color:#666;font-size:14px;margin-top:4px}
|
|
62
|
+
label{display:block;font-size:14px;font-weight:500;color:#333;margin-bottom:6px}
|
|
63
|
+
input{width:100%;padding:10px 12px;border:1px solid #ddd;border-radius:8px;font-size:14px;margin-bottom:16px;outline:none}input:focus{border-color:#111}
|
|
64
|
+
button{width:100%;padding:12px;background:#111;color:#fff;border:none;border-radius:8px;font-size:15px;font-weight:600;cursor:pointer}button:hover{background:#333}button:disabled{background:#999}
|
|
65
|
+
.err{color:#e53e3e;font-size:13px;margin-bottom:12px;display:none}.ok{text-align:center;color:#38a169;font-size:16px;font-weight:600;display:none;margin-top:16px}
|
|
66
|
+
</style></head><body><div class="c"><div class="logo"><h1>Perfai</h1><p>Sign in with your cloud.perfai.ai account</p></div>
|
|
67
|
+
<form id="f"><label for="e">Email</label><input type="email" id="e" placeholder="you@example.com" required autofocus>
|
|
68
|
+
<label for="p">Password</label><input type="password" id="p" placeholder="Your password" required>
|
|
69
|
+
<div class="err" id="x"></div><button type="submit" id="b">Sign in</button></form>
|
|
70
|
+
<div class="ok" id="s">Authenticated! You can close this tab.</div></div>
|
|
71
|
+
<script>document.getElementById('f').addEventListener('submit',async e=>{e.preventDefault();const b=document.getElementById('b'),x=document.getElementById('x');
|
|
72
|
+
b.disabled=true;b.textContent='Signing in...';x.style.display='none';try{const r=await fetch('/auth',{method:'POST',headers:{'Content-Type':'application/json'},
|
|
73
|
+
body:JSON.stringify({email:document.getElementById('e').value,password:document.getElementById('p').value})});const d=await r.json();
|
|
74
|
+
if(d.ok){document.getElementById('f').style.display='none';document.getElementById('s').style.display='block'}
|
|
75
|
+
else{x.textContent=d.message||'Login failed';x.style.display='block';b.disabled=false;b.textContent='Sign in'}}
|
|
76
76
|
catch{x.textContent='Connection error';x.style.display='block';b.disabled=false;b.textContent='Sign in'}});</script></body></html>`;
|
|
77
77
|
function browserLogin(auth) {
|
|
78
78
|
return new Promise((resolve, reject) => {
|
|
@@ -196,7 +196,7 @@ async function scan(url) {
|
|
|
196
196
|
const TOTAL_STEPS = 5;
|
|
197
197
|
const auth = new AuthManager();
|
|
198
198
|
// ── Step 1: Authenticate ──────────────────────────────────────────
|
|
199
|
-
step(1, TOTAL_STEPS, "Authenticate with
|
|
199
|
+
step(1, TOTAL_STEPS, "Authenticate with Perfai");
|
|
200
200
|
if (auth.hasCredentials()) {
|
|
201
201
|
const sp = spinner("Logging in with environment credentials...");
|
|
202
202
|
await auth.login();
|
|
@@ -332,27 +332,27 @@ async function scan(url) {
|
|
|
332
332
|
/* CLI argument parsing */
|
|
333
333
|
/* ------------------------------------------------------------------ */
|
|
334
334
|
function printHelp() {
|
|
335
|
-
log(`
|
|
336
|
-
${BOLD}perfai${RESET} —
|
|
337
|
-
|
|
338
|
-
${BOLD}USAGE${RESET}
|
|
339
|
-
npx perfai scan <url> Scan an app for security vulnerabilities
|
|
340
|
-
npx perfai scan --help Show this help
|
|
341
|
-
|
|
342
|
-
${BOLD}EXAMPLES${RESET}
|
|
343
|
-
npx perfai scan https://api.myapp.com
|
|
344
|
-
npx perfai scan https://staging.example.com
|
|
345
|
-
|
|
346
|
-
${BOLD}AUTHENTICATION${RESET}
|
|
347
|
-
Set environment variables for non-interactive login:
|
|
348
|
-
PERFAI_EMAIL=you@example.com
|
|
349
|
-
PERFAI_PASSWORD=your-password
|
|
350
|
-
|
|
351
|
-
Or omit them — a browser window will open for you to sign in.
|
|
352
|
-
|
|
353
|
-
${BOLD}MORE INFO${RESET}
|
|
354
|
-
https://cloud.perfai.ai
|
|
355
|
-
https://mcp-server.perfai.ai
|
|
335
|
+
log(`
|
|
336
|
+
${BOLD}perfai${RESET} — Perfai Security Scanner CLI v${SERVER_INFO.version}
|
|
337
|
+
|
|
338
|
+
${BOLD}USAGE${RESET}
|
|
339
|
+
npx perfai scan <url> Scan an app for security vulnerabilities
|
|
340
|
+
npx perfai scan --help Show this help
|
|
341
|
+
|
|
342
|
+
${BOLD}EXAMPLES${RESET}
|
|
343
|
+
npx perfai scan https://api.myapp.com
|
|
344
|
+
npx perfai scan https://staging.example.com
|
|
345
|
+
|
|
346
|
+
${BOLD}AUTHENTICATION${RESET}
|
|
347
|
+
Set environment variables for non-interactive login:
|
|
348
|
+
PERFAI_EMAIL=you@example.com
|
|
349
|
+
PERFAI_PASSWORD=your-password
|
|
350
|
+
|
|
351
|
+
Or omit them — a browser window will open for you to sign in.
|
|
352
|
+
|
|
353
|
+
${BOLD}MORE INFO${RESET}
|
|
354
|
+
https://cloud.perfai.ai
|
|
355
|
+
https://mcp-server.perfai.ai
|
|
356
356
|
`);
|
|
357
357
|
}
|
|
358
358
|
async function main() {
|
|
@@ -375,7 +375,7 @@ async function main() {
|
|
|
375
375
|
fail("URL must start with http:// or https://");
|
|
376
376
|
process.exit(1);
|
|
377
377
|
}
|
|
378
|
-
log(`\n${BOLD}
|
|
378
|
+
log(`\n${BOLD}Perfai Security Scanner${RESET} v${SERVER_INFO.version}\n`);
|
|
379
379
|
try {
|
|
380
380
|
await scan(url);
|
|
381
381
|
}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { AuthManager } from "./authManager.js";
|
|
2
|
-
import type { AppListResponse, AppRecord, TaskRecord, VulnerabilityListResponse } from "./types.js";
|
|
2
|
+
import type { AppListResponse, AppRecord, TaskRecord, UserOrganizationsResponse, VulnerabilityListResponse, VulnerabilityRecord } from "./types.js";
|
|
3
3
|
export interface RegisterAppInput {
|
|
4
4
|
appUrl: string;
|
|
5
5
|
tenantOneCredentials?: Record<string, unknown>;
|
|
@@ -12,7 +12,7 @@ export declare function listApps(auth: AuthManager, params: {
|
|
|
12
12
|
page?: number;
|
|
13
13
|
pageSize?: number;
|
|
14
14
|
search?: string;
|
|
15
|
-
}): Promise<AppListResponse>;
|
|
15
|
+
}, orgId?: string): Promise<AppListResponse>;
|
|
16
16
|
export declare function submitAccountSetup(auth: AuthManager, appId: string, credentials: Record<string, unknown>): Promise<TaskRecord>;
|
|
17
17
|
export declare function runSecurityAgent(auth: AuthManager, appId: string): Promise<TaskRecord>;
|
|
18
18
|
export declare function getTask(auth: AuthManager, taskId: string): Promise<TaskRecord>;
|
|
@@ -21,7 +21,16 @@ export declare function getVulnerabilities(auth: AuthManager, appId: string, par
|
|
|
21
21
|
pageSize?: number;
|
|
22
22
|
search?: string;
|
|
23
23
|
}): Promise<VulnerabilityListResponse>;
|
|
24
|
-
|
|
24
|
+
/** Pages through every finding for an app (the API caps pageSize at 100). */
|
|
25
|
+
export declare function getAllVulnerabilities(auth: AuthManager, appId: string): Promise<VulnerabilityRecord[]>;
|
|
26
|
+
export declare function dismissVulnerability(auth: AuthManager, id: string, comment?: string): Promise<unknown>;
|
|
25
27
|
export declare function reopenVulnerability(auth: AuthManager, id: string): Promise<unknown>;
|
|
26
|
-
export declare function fixVulnerability(auth: AuthManager, id: string): Promise<unknown>;
|
|
28
|
+
export declare function fixVulnerability(auth: AuthManager, id: string, comment?: string): Promise<unknown>;
|
|
29
|
+
/**
|
|
30
|
+
* Lists the organizations (tenants) this account belongs to, plus whichever
|
|
31
|
+
* one the account was last using. Separate base URL from the rest of the
|
|
32
|
+
* API (lives under /api/v1, not /v1), so this bypasses the shared request()
|
|
33
|
+
* helper rather than fighting its baseURL binding.
|
|
34
|
+
*/
|
|
35
|
+
export declare function getUserOrganizations(auth: AuthManager): Promise<UserOrganizationsResponse>;
|
|
27
36
|
//# sourceMappingURL=apiClient.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"apiClient.d.ts","sourceRoot":"","sources":["../../src/client/apiClient.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,WAAW,EAAE,MAAM,kBAAkB,CAAC;AAE/C,OAAO,KAAK,EACV,eAAe,EACf,SAAS,EACT,UAAU,EACV,yBAAyB,
|
|
1
|
+
{"version":3,"file":"apiClient.d.ts","sourceRoot":"","sources":["../../src/client/apiClient.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,WAAW,EAAE,MAAM,kBAAkB,CAAC;AAE/C,OAAO,KAAK,EACV,eAAe,EACf,SAAS,EACT,UAAU,EACV,yBAAyB,EACzB,yBAAyB,EACzB,mBAAmB,EACpB,MAAM,YAAY,CAAC;AAwDpB,MAAM,WAAW,gBAAgB;IAC/B,MAAM,EAAE,MAAM,CAAC;IACf,oBAAoB,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;IAC/C,kBAAkB,CAAC,EAAE,OAAO,CAAC;IAC7B,aAAa,CAAC,EAAE,MAAM,EAAE,CAAC;CAC1B;AAED,wBAAgB,WAAW,CAAC,IAAI,EAAE,WAAW,EAAE,KAAK,EAAE,gBAAgB,GAAG,OAAO,CAAC,SAAS,CAAC,CAE1F;AAED,wBAAgB,MAAM,CAAC,IAAI,EAAE,WAAW,EAAE,KAAK,EAAE,MAAM,GAAG,OAAO,CAAC,SAAS,CAAC,CAE3E;AAED,wBAAgB,QAAQ,CACtB,IAAI,EAAE,WAAW,EACjB,MAAM,EAAE;IAAE,IAAI,CAAC,EAAE,MAAM,CAAC;IAAC,QAAQ,CAAC,EAAE,MAAM,CAAC;IAAC,MAAM,CAAC,EAAE,MAAM,CAAA;CAAE,EAC7D,KAAK,CAAC,EAAE,MAAM,GACb,OAAO,CAAC,eAAe,CAAC,CAE1B;AAED,wBAAgB,kBAAkB,CAChC,IAAI,EAAE,WAAW,EACjB,KAAK,EAAE,MAAM,EACb,WAAW,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GACnC,OAAO,CAAC,UAAU,CAAC,CAMrB;AAED,wBAAgB,gBAAgB,CAAC,IAAI,EAAE,WAAW,EAAE,KAAK,EAAE,MAAM,GAAG,OAAO,CAAC,UAAU,CAAC,CAKtF;AAED,wBAAgB,OAAO,CAAC,IAAI,EAAE,WAAW,EAAE,MAAM,EAAE,MAAM,GAAG,OAAO,CAAC,UAAU,CAAC,CAE9E;AAED,wBAAgB,kBAAkB,CAChC,IAAI,EAAE,WAAW,EACjB,KAAK,EAAE,MAAM,EACb,MAAM,EAAE;IAAE,IAAI,CAAC,EAAE,MAAM,CAAC;IAAC,QAAQ,CAAC,EAAE,MAAM,CAAC;IAAC,MAAM,CAAC,EAAE,MAAM,CAAA;CAAE,GAC5D,OAAO,CAAC,yBAAyB,CAAC,CAMpC;AAED,6EAA6E;AAC7E,wBAAsB,qBAAqB,CAAC,IAAI,EAAE,WAAW,EAAE,KAAK,EAAE,MAAM,GAAG,OAAO,CAAC,mBAAmB,EAAE,CAAC,CAO5G;AAQD,wBAAgB,oBAAoB,CAAC,IAAI,EAAE,WAAW,EAAE,EAAE,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,MAAM,GAAG,OAAO,CAAC,OAAO,CAAC,CAMtG;AAED,wBAAgB,mBAAmB,CAAC,IAAI,EAAE,WAAW,EAAE,EAAE,EAAE,MAAM,GAAG,OAAO,CAAC,OAAO,CAAC,CAEnF;AAED,wBAAgB,gBAAgB,CAAC,IAAI,EAAE,WAAW,EAAE,EAAE,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,MAAM,GAAG,OAAO,CAAC,OAAO,CAAC,CAMlG;AAED;;;;;GAKG;AACH,wBAAsB,oBAAoB,CAAC,IAAI,EAAE,WAAW,GAAG,OAAO,CAAC,yBAAyB,CAAC,CAoBhG"}
|
package/dist/client/apiClient.js
CHANGED
|
@@ -1,7 +1,13 @@
|
|
|
1
1
|
import axios from "axios";
|
|
2
|
-
import { API_BASE_URL } from "../config.js";
|
|
2
|
+
import { API_BASE_URL, ORGANIZATIONS_URL } from "../config.js";
|
|
3
3
|
import { ApiError, formatApiError } from "./errors.js";
|
|
4
|
+
/**
|
|
5
|
+
* `orgId` overrides the X-Org-ID header for this one request without changing
|
|
6
|
+
* the session's selected org — used to search other orgs for an app by name.
|
|
7
|
+
*/
|
|
4
8
|
async function request(auth, config, allowReauth = true) {
|
|
9
|
+
const { orgId: orgOverride, ...axiosConfig } = config;
|
|
10
|
+
const orgId = orgOverride ?? auth.getSelectedOrgId();
|
|
5
11
|
if (!auth.isAuthenticated()) {
|
|
6
12
|
if (auth.hasCredentials()) {
|
|
7
13
|
await auth.login();
|
|
@@ -12,12 +18,13 @@ async function request(auth, config, allowReauth = true) {
|
|
|
12
18
|
}
|
|
13
19
|
try {
|
|
14
20
|
const response = await axios.request({
|
|
15
|
-
...
|
|
21
|
+
...axiosConfig,
|
|
16
22
|
baseURL: API_BASE_URL,
|
|
17
23
|
timeout: 30_000,
|
|
18
24
|
headers: {
|
|
19
|
-
...
|
|
25
|
+
...axiosConfig.headers,
|
|
20
26
|
Authorization: `Bearer ${auth.getToken()}`,
|
|
27
|
+
...(orgId ? { "X-Org-ID": orgId } : {}),
|
|
21
28
|
"Content-Type": "application/json",
|
|
22
29
|
},
|
|
23
30
|
});
|
|
@@ -44,8 +51,8 @@ export function registerApp(auth, input) {
|
|
|
44
51
|
export function getApp(auth, appId) {
|
|
45
52
|
return request(auth, { method: "GET", url: `/apps/${encodeURIComponent(appId)}` });
|
|
46
53
|
}
|
|
47
|
-
export function listApps(auth, params) {
|
|
48
|
-
return request(auth, { method: "GET", url: "/apps", params });
|
|
54
|
+
export function listApps(auth, params, orgId) {
|
|
55
|
+
return request(auth, { method: "GET", url: "/apps", params, orgId });
|
|
49
56
|
}
|
|
50
57
|
export function submitAccountSetup(auth, appId, credentials) {
|
|
51
58
|
return request(auth, {
|
|
@@ -70,12 +77,59 @@ export function getVulnerabilities(auth, appId, params) {
|
|
|
70
77
|
params,
|
|
71
78
|
});
|
|
72
79
|
}
|
|
73
|
-
|
|
74
|
-
|
|
80
|
+
/** Pages through every finding for an app (the API caps pageSize at 100). */
|
|
81
|
+
export async function getAllVulnerabilities(auth, appId) {
|
|
82
|
+
const all = [];
|
|
83
|
+
for (let page = 1;; page++) {
|
|
84
|
+
const result = await getVulnerabilities(auth, appId, { page, pageSize: 100 });
|
|
85
|
+
all.push(...result.data);
|
|
86
|
+
if (result.data.length === 0 || all.length >= result.total)
|
|
87
|
+
return all;
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
/** The dismiss / fix endpoints accept an optional comment (max 1000 chars) stored on the finding. */
|
|
91
|
+
function actionBody(comment) {
|
|
92
|
+
const trimmed = comment?.trim();
|
|
93
|
+
return trimmed ? { comment: trimmed.slice(0, 1000) } : undefined;
|
|
94
|
+
}
|
|
95
|
+
export function dismissVulnerability(auth, id, comment) {
|
|
96
|
+
return request(auth, {
|
|
97
|
+
method: "POST",
|
|
98
|
+
url: `/vulnerabilities/${encodeURIComponent(id)}/dismiss`,
|
|
99
|
+
data: actionBody(comment),
|
|
100
|
+
});
|
|
75
101
|
}
|
|
76
102
|
export function reopenVulnerability(auth, id) {
|
|
77
103
|
return request(auth, { method: "POST", url: `/vulnerabilities/${encodeURIComponent(id)}/reopen` });
|
|
78
104
|
}
|
|
79
|
-
export function fixVulnerability(auth, id) {
|
|
80
|
-
return request(auth, {
|
|
105
|
+
export function fixVulnerability(auth, id, comment) {
|
|
106
|
+
return request(auth, {
|
|
107
|
+
method: "POST",
|
|
108
|
+
url: `/vulnerabilities/${encodeURIComponent(id)}/fix`,
|
|
109
|
+
data: actionBody(comment),
|
|
110
|
+
});
|
|
111
|
+
}
|
|
112
|
+
/**
|
|
113
|
+
* Lists the organizations (tenants) this account belongs to, plus whichever
|
|
114
|
+
* one the account was last using. Separate base URL from the rest of the
|
|
115
|
+
* API (lives under /api/v1, not /v1), so this bypasses the shared request()
|
|
116
|
+
* helper rather than fighting its baseURL binding.
|
|
117
|
+
*/
|
|
118
|
+
export async function getUserOrganizations(auth) {
|
|
119
|
+
if (!auth.isAuthenticated()) {
|
|
120
|
+
throw new Error("Not authenticated. Run the `login` tool first.");
|
|
121
|
+
}
|
|
122
|
+
try {
|
|
123
|
+
const response = await axios.get(ORGANIZATIONS_URL, {
|
|
124
|
+
headers: { Authorization: `Bearer ${auth.getToken()}` },
|
|
125
|
+
timeout: 30_000,
|
|
126
|
+
});
|
|
127
|
+
return response.data;
|
|
128
|
+
}
|
|
129
|
+
catch (error) {
|
|
130
|
+
if (axios.isAxiosError(error)) {
|
|
131
|
+
throw new ApiError(formatApiError(error), error.response?.status, error.response?.data);
|
|
132
|
+
}
|
|
133
|
+
throw error;
|
|
134
|
+
}
|
|
81
135
|
}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { VulnerabilityRecord } from "./types.js";
|
|
1
|
+
import type { OrganizationRecord, VulnerabilityRecord } from "./types.js";
|
|
2
2
|
export type AuthMethod = "credentials" | "token" | "oauth" | "none";
|
|
3
3
|
/**
|
|
4
4
|
* Holds the auth token plus the small amount of "current selection" state
|
|
@@ -17,6 +17,11 @@ export declare class AuthManager {
|
|
|
17
17
|
currentTaskId?: string;
|
|
18
18
|
private vulnCache;
|
|
19
19
|
private vulnCacheAppId?;
|
|
20
|
+
private organizations;
|
|
21
|
+
private selectedOrgId?;
|
|
22
|
+
private defaultOrgId?;
|
|
23
|
+
/** appId → org it lives in, for apps surfaced by a cross-org name lookup. */
|
|
24
|
+
private appOrgHints;
|
|
20
25
|
constructor();
|
|
21
26
|
hasCredentials(): boolean;
|
|
22
27
|
setCredentials(email: string, password: string): void;
|
|
@@ -31,6 +36,20 @@ export declare class AuthManager {
|
|
|
31
36
|
getAuthMethod(): AuthMethod;
|
|
32
37
|
login(email?: string, password?: string): Promise<string>;
|
|
33
38
|
logout(): void;
|
|
39
|
+
/** Returns the cached org list (empty until manage_organizations fetches it). */
|
|
40
|
+
getOrganizations(): OrganizationRecord[];
|
|
41
|
+
getSelectedOrgId(): string | undefined;
|
|
42
|
+
/** Selects an org by ID; subsequent API calls send it as X-Org-ID. */
|
|
43
|
+
setSelectedOrgId(orgId: string): void;
|
|
44
|
+
/** Caches the org list from get_users_orgs; auto-selects currentOrgId, or
|
|
45
|
+
* the first org if nothing is selected yet (mirrors login-time default). */
|
|
46
|
+
setOrganizations(organizations: OrganizationRecord[], currentOrgId?: string): void;
|
|
47
|
+
/** The org the API falls back to when no X-Org-ID is sent (currentOrg from get_users_orgs). */
|
|
48
|
+
getDefaultOrgId(): string | undefined;
|
|
49
|
+
/** Caches the org list for app-name resolution WITHOUT changing the selected org. */
|
|
50
|
+
cacheOrganizationList(organizations: OrganizationRecord[], defaultOrgId?: string): void;
|
|
51
|
+
rememberAppOrg(appId: string, orgId: string): void;
|
|
52
|
+
getAppOrg(appId: string): string | undefined;
|
|
34
53
|
setCurrentApp(appId: string, appUrl?: string): void;
|
|
35
54
|
/** Caches a vulnerability page (keyed by 1-based sequence number) so tools can refer to "#3". */
|
|
36
55
|
cacheVulnerabilities(appId: string, vulnerabilities: VulnerabilityRecord[]): void;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"authManager.d.ts","sourceRoot":"","sources":["../../src/client/authManager.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,YAAY,CAAC;
|
|
1
|
+
{"version":3,"file":"authManager.d.ts","sourceRoot":"","sources":["../../src/client/authManager.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,kBAAkB,EAAE,mBAAmB,EAAE,MAAM,YAAY,CAAC;AAE1E,MAAM,MAAM,UAAU,GAAG,aAAa,GAAG,OAAO,GAAG,OAAO,GAAG,MAAM,CAAC;AAEpE;;;;;GAKG;AACH,qBAAa,WAAW;IACtB,OAAO,CAAC,KAAK,CAAC,CAAwB;IACtC,OAAO,CAAC,QAAQ,CAAC,CAA2B;IAC5C,OAAO,CAAC,OAAO,CAAC,CAAS;IACzB,OAAO,CAAC,kBAAkB,CAAC,CAAS;IACpC,OAAO,CAAC,UAAU,CAAsB;IAExC,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB,aAAa,CAAC,EAAE,MAAM,CAAC;IACvB,aAAa,CAAC,EAAE,MAAM,CAAC;IAEvB,OAAO,CAAC,SAAS,CAA0C;IAC3D,OAAO,CAAC,cAAc,CAAC,CAAS;IAEhC,OAAO,CAAC,aAAa,CAA4B;IACjD,OAAO,CAAC,aAAa,CAAC,CAAS;IAC/B,OAAO,CAAC,YAAY,CAAC,CAAS;IAC9B,6EAA6E;IAC7E,OAAO,CAAC,WAAW,CAA6B;;IAWhD,cAAc,IAAI,OAAO;IAIzB,cAAc,CAAC,KAAK,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,GAAG,IAAI;IAKrD;;;OAGG;IACH,QAAQ,CAAC,KAAK,EAAE,MAAM,EAAE,KAAK,CAAC,EAAE,MAAM,EAAE,MAAM,GAAE,UAAoB,GAAG,IAAI;IAgB3E,eAAe,IAAI,OAAO;IAI1B,QAAQ,IAAI,MAAM,GAAG,SAAS;IAI9B,qBAAqB,IAAI,MAAM,GAAG,SAAS;IAI3C,aAAa,IAAI,UAAU;IAIrB,KAAK,CAAC,KAAK,CAAC,EAAE,MAAM,EAAE,QAAQ,CAAC,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC;IAyC/D,MAAM,IAAI,IAAI;IAed,iFAAiF;IACjF,gBAAgB,IAAI,kBAAkB,EAAE;IAIxC,gBAAgB,IAAI,MAAM,GAAG,SAAS;IAItC,sEAAsE;IACtE,gBAAgB,CAAC,KAAK,EAAE,MAAM,GAAG,IAAI;IAIrC;iFAC6E;IAC7E,gBAAgB,CAAC,aAAa,EAAE,kBAAkB,EAAE,EAAE,YAAY,CAAC,EAAE,MAAM,GAAG,IAAI;IAUlF,+FAA+F;IAC/F,eAAe,IAAI,MAAM,GAAG,SAAS;IAIrC,qFAAqF;IACrF,qBAAqB,CAAC,aAAa,EAAE,kBAAkB,EAAE,EAAE,YAAY,CAAC,EAAE,MAAM,GAAG,IAAI;IAKvF,cAAc,CAAC,KAAK,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,GAAG,IAAI;IAIlD,SAAS,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM,GAAG,SAAS;IAI5C,aAAa,CAAC,KAAK,EAAE,MAAM,EAAE,MAAM,CAAC,EAAE,MAAM,GAAG,IAAI;IAKnD,iGAAiG;IACjG,oBAAoB,CAAC,KAAK,EAAE,MAAM,EAAE,eAAe,EAAE,mBAAmB,EAAE,GAAG,IAAI;IAMjF,8GAA8G;IAC9G,sBAAsB,CAAC,KAAK,EAAE,MAAM,EAAE,YAAY,EAAE,MAAM,GAAG,mBAAmB,GAAG,SAAS;IAa5F,kFAAkF;IAClF,sBAAsB,CAAC,KAAK,EAAE,MAAM,EAAE,YAAY,EAAE,MAAM,GAAG,MAAM;CAKpE"}
|
|
@@ -18,6 +18,11 @@ export class AuthManager {
|
|
|
18
18
|
currentTaskId;
|
|
19
19
|
vulnCache = new Map();
|
|
20
20
|
vulnCacheAppId;
|
|
21
|
+
organizations = [];
|
|
22
|
+
selectedOrgId;
|
|
23
|
+
defaultOrgId;
|
|
24
|
+
/** appId → org it lives in, for apps surfaced by a cross-org name lookup. */
|
|
25
|
+
appOrgHints = new Map();
|
|
21
26
|
constructor() {
|
|
22
27
|
// Auto-load PERFAI_TOKEN if set (headless fallback for Replit/Lovable/Bolt).
|
|
23
28
|
// This takes priority over email/password since it's an existing, validated token.
|
|
@@ -102,6 +107,48 @@ export class AuthManager {
|
|
|
102
107
|
this.currentTaskId = undefined;
|
|
103
108
|
this.vulnCache.clear();
|
|
104
109
|
this.vulnCacheAppId = undefined;
|
|
110
|
+
this.organizations = [];
|
|
111
|
+
this.selectedOrgId = undefined;
|
|
112
|
+
this.defaultOrgId = undefined;
|
|
113
|
+
this.appOrgHints.clear();
|
|
114
|
+
}
|
|
115
|
+
/** Returns the cached org list (empty until manage_organizations fetches it). */
|
|
116
|
+
getOrganizations() {
|
|
117
|
+
return this.organizations;
|
|
118
|
+
}
|
|
119
|
+
getSelectedOrgId() {
|
|
120
|
+
return this.selectedOrgId;
|
|
121
|
+
}
|
|
122
|
+
/** Selects an org by ID; subsequent API calls send it as X-Org-ID. */
|
|
123
|
+
setSelectedOrgId(orgId) {
|
|
124
|
+
this.selectedOrgId = orgId;
|
|
125
|
+
}
|
|
126
|
+
/** Caches the org list from get_users_orgs; auto-selects currentOrgId, or
|
|
127
|
+
* the first org if nothing is selected yet (mirrors login-time default). */
|
|
128
|
+
setOrganizations(organizations, currentOrgId) {
|
|
129
|
+
this.organizations = organizations;
|
|
130
|
+
this.defaultOrgId = currentOrgId;
|
|
131
|
+
if (currentOrgId) {
|
|
132
|
+
this.selectedOrgId = currentOrgId;
|
|
133
|
+
}
|
|
134
|
+
else if (!this.selectedOrgId && organizations.length > 0) {
|
|
135
|
+
this.selectedOrgId = organizations[0].org_id;
|
|
136
|
+
}
|
|
137
|
+
}
|
|
138
|
+
/** The org the API falls back to when no X-Org-ID is sent (currentOrg from get_users_orgs). */
|
|
139
|
+
getDefaultOrgId() {
|
|
140
|
+
return this.defaultOrgId;
|
|
141
|
+
}
|
|
142
|
+
/** Caches the org list for app-name resolution WITHOUT changing the selected org. */
|
|
143
|
+
cacheOrganizationList(organizations, defaultOrgId) {
|
|
144
|
+
this.organizations = organizations;
|
|
145
|
+
this.defaultOrgId = defaultOrgId;
|
|
146
|
+
}
|
|
147
|
+
rememberAppOrg(appId, orgId) {
|
|
148
|
+
this.appOrgHints.set(appId, orgId);
|
|
149
|
+
}
|
|
150
|
+
getAppOrg(appId) {
|
|
151
|
+
return this.appOrgHints.get(appId);
|
|
105
152
|
}
|
|
106
153
|
setCurrentApp(appId, appUrl) {
|
|
107
154
|
this.currentAppId = appId;
|