@pensar/apex 1.8.0 → 1.8.2-canary.fb75c486
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 +11 -0
- package/build/agent-6dj1qm50.js +221 -0
- package/build/agent-6xr8vpgm.js +28 -0
- package/build/agent-x1htbpe3.js +22 -0
- package/build/apps-t0gmwc7z.js +446 -0
- package/build/{auth-dxjgy41e.js → auth-p4r1m7xq.js} +50 -13
- package/build/authentication-je2b0c3w.js +22 -0
- package/build/blackboxAgent-a4jnt0y5.js +22 -0
- package/build/{blackboxPentest-8ps4yvbk.js → blackboxPentest-b5741n3h.js} +19 -17
- package/build/{cli-y61d9433.js → cli-0tnv1vkp.js} +138 -38
- package/build/{cli-jg7r7y5n.js → cli-4xb21y6g.js} +30 -2
- package/build/{cli-k0tckznm.js → cli-6p7d2k55.js} +39701 -31695
- package/build/cli-87zakjb2.js +17 -0
- package/build/{authentication-e30mfzbe.js → cli-8frjr68r.js} +11 -18
- package/build/cli-8xknm7d9.js +204 -0
- package/build/cli-9egg9azd.js +22 -0
- package/build/cli-9fsre5pt.js +0 -0
- package/build/cli-abbka8n3.js +501 -0
- package/build/{cli-3y0dgy56.js → cli-c8131c4q.js} +2 -2
- package/build/cli-e08r86zk.js +24 -0
- package/build/{cli-0ghkg3w6.js → cli-e6rgwtpb.js} +19950 -18556
- package/build/cli-g5h24ny8.js +197 -0
- package/build/{cli-nr1cjfr9.js → cli-gtcd5c3f.js} +26 -7
- package/build/cli-k0730f59.js +52 -0
- package/build/{cli-tp1tqn3k.js → cli-mswm4k81.js} +1 -1
- package/build/{cli-m788e4f3.js → cli-q8dfq25x.js} +584 -33
- package/build/cli-rhry8mat.js +7213 -0
- package/build/{cli-g8t710ew.js → cli-ryy39d77.js} +253 -250
- package/build/cli-s1nckt4k.js +20 -0
- package/build/{cli-k4hrygff.js → cli-v9ds4jb8.js} +9 -5
- package/build/{cli-dqt80sw3.js → cli-w5990vr6.js} +199 -68
- package/build/{cli-3w2syxpv.js → cli-wfmdch3r.js} +102695 -104816
- package/build/cli.js +351 -280
- package/build/config-3bvtf3j8.js +188 -0
- package/build/{doctor-8tva8j99.js → doctor-2bkpddws.js} +1 -1
- package/build/{fixes-q5bhgxhc.js → fixes-60k3ts71.js} +23 -4
- package/build/{index-pfee23kv.js → index-0gp3x2r8.js} +19306 -18954
- package/build/index-861hkebg.js +12 -0
- package/build/{index-y5xpp21a.js → index-acc00eq4.js} +77 -108
- package/build/index-acdgrqa0.js +36 -0
- package/build/{index-e898mdyh.js → index-cfberehw.js} +4 -2
- package/build/{index-wfeb2gcc.js → index-hxn4rk8f.js} +9 -11
- package/build/{index-dw1xbhfn.js → index-vc29b21w.js} +161 -26
- package/build/index-vwt27stc.js +184 -0
- package/build/{issues-qbmdneej.js → issues-1bynat5q.js} +33 -9
- package/build/{logs-xm5vbymy.js → logs-e78vx2dy.js} +23 -4
- package/build/{main-3d7dfdvs.js → main-3zneyg7p.js} +93 -17
- package/build/{offesecAgent-re6kt2ff.js → offesecAgent-w9m0svwk.js} +14 -11
- package/build/parse-15kqmy2v.js +207 -0
- package/build/pentest-gpvqpvmd.js +31 -0
- package/build/{pentests-e3rj5845.js → pentests-nq7wa8yb.js} +36 -17
- package/build/{targetedPentest-fs0v570s.js → targetedPentest-fjxqn089.js} +15 -12
- package/build/threatModel-9yqx7d7x.js +29 -0
- package/build/{uninstall-qb2xbh2t.js → uninstall-9zbf4cwc.js} +6 -4
- package/build/{utils-jf52rmrb.js → utils-dh1t2r1e.js} +13 -10
- package/package.json +86 -88
- package/build/agent-4d8j2jsw.js +0 -278
- package/build/agent-z2s6h7n2.js +0 -19
- package/build/blackboxAgent-j9pczwym.js +0 -19
- package/build/cli-03z6pswp.js +0 -1423
- package/build/cli-0fy9j5dw.js +0 -61
- package/build/cli-asyas1xb.js +0 -110
- package/build/cli-dj1dgw2n.js +0 -190
- package/build/cli-q7r2sth7.js +0 -103
- package/build/cli-vkwch0bc.js +0 -1207
- package/build/cli-wr7g9qcr.js +0 -645
- package/build/index-bz6f8jry.js +0 -32
- package/build/pentest-mfm4hake.js +0 -29
- package/build/projects-qk22qcbt.js +0 -35
- package/build/threatModel-xfvc6cch.js +0 -67
|
@@ -1,33 +1,54 @@
|
|
|
1
1
|
import {
|
|
2
2
|
config,
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
3
|
+
init_config
|
|
4
|
+
} from "./cli-9egg9azd.js";
|
|
5
|
+
import {
|
|
6
|
+
__esm
|
|
7
|
+
} from "./cli-8rxa073f.js";
|
|
7
8
|
|
|
8
|
-
// src/core/auth/
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
9
|
+
// src/core/auth/connection.ts
|
|
10
|
+
function isConnected(cfg) {
|
|
11
|
+
return !!(cfg.accessToken || cfg.pensarAPIKey);
|
|
12
|
+
}
|
|
13
|
+
async function disconnect() {
|
|
14
|
+
await config.update({
|
|
15
|
+
pensarAPIKey: null,
|
|
16
|
+
accessToken: null,
|
|
17
|
+
refreshToken: null,
|
|
18
|
+
workspaceId: null,
|
|
19
|
+
workspaceSlug: null,
|
|
20
|
+
gatewaySigningKey: null
|
|
21
|
+
});
|
|
22
|
+
}
|
|
23
|
+
var init_connection = __esm(() => {
|
|
24
|
+
init_config();
|
|
25
|
+
});
|
|
26
|
+
|
|
27
|
+
// src/core/api/constants.ts
|
|
28
|
+
function getPensarApiUrl() {
|
|
29
|
+
return process.env.PENSAR_API_URL || PENSAR_API_BASE_URL;
|
|
30
|
+
}
|
|
31
|
+
function getPensarGatewayUrl() {
|
|
32
|
+
return process.env.PENSAR_GATEWAY_URL || PENSAR_GATEWAY_BASE_URL;
|
|
33
|
+
}
|
|
34
|
+
function getPensarConsoleUrl() {
|
|
35
|
+
return process.env.PENSAR_CONSOLE_URL || PENSAR_CONSOLE_BASE_URL;
|
|
20
36
|
}
|
|
37
|
+
var PENSAR_API_BASE_URL = "https://api.pensar.dev", PENSAR_GATEWAY_BASE_URL = "https://gateway.pensar.dev", PENSAR_CONSOLE_BASE_URL = "https://console.pensar.dev";
|
|
38
|
+
var init_constants = () => {};
|
|
39
|
+
|
|
21
40
|
// src/core/auth/device-flow.ts
|
|
22
41
|
function sleep(ms) {
|
|
23
42
|
return new Promise((resolve) => setTimeout(resolve, ms));
|
|
24
43
|
}
|
|
25
44
|
async function startDeviceFlow(apiUrl) {
|
|
26
45
|
const url = apiUrl ?? getPensarApiUrl();
|
|
46
|
+
let workosClientId;
|
|
27
47
|
try {
|
|
28
48
|
const configResponse = await fetch(`${url}/api/cli/config`);
|
|
29
49
|
if (configResponse.ok) {
|
|
30
50
|
const cliConfig = await configResponse.json();
|
|
51
|
+
workosClientId = cliConfig.workosClientId;
|
|
31
52
|
const response2 = await fetch("https://api.workos.com/user_management/authorize/device", {
|
|
32
53
|
method: "POST",
|
|
33
54
|
headers: { "Content-Type": "application/json" },
|
|
@@ -45,13 +66,14 @@ async function startDeviceFlow(apiUrl) {
|
|
|
45
66
|
} catch {}
|
|
46
67
|
const response = await fetch(`${url}/auth/device/code`, {
|
|
47
68
|
method: "POST",
|
|
48
|
-
headers: { "Content-Type": "application/json" }
|
|
69
|
+
headers: { "Content-Type": "application/json" },
|
|
70
|
+
body: JSON.stringify(workosClientId ? { client_id: workosClientId } : {})
|
|
49
71
|
});
|
|
50
72
|
if (!response.ok) {
|
|
51
73
|
throw new Error("Failed to start device authorization");
|
|
52
74
|
}
|
|
53
75
|
const deviceInfo = await response.json();
|
|
54
|
-
return { mode: "legacy", deviceInfo };
|
|
76
|
+
return { mode: "legacy", clientId: workosClientId, deviceInfo };
|
|
55
77
|
}
|
|
56
78
|
async function pollWorkOSToken(params) {
|
|
57
79
|
const { clientId, deviceCode, interval, expiresIn, signal } = params;
|
|
@@ -92,7 +114,7 @@ async function pollWorkOSToken(params) {
|
|
|
92
114
|
throw new Error("Authorization timed out. Please try again.");
|
|
93
115
|
}
|
|
94
116
|
async function pollLegacyToken(params) {
|
|
95
|
-
const { apiUrl, deviceCode, interval, expiresIn, signal } = params;
|
|
117
|
+
const { apiUrl, deviceCode, interval, expiresIn, clientId, signal } = params;
|
|
96
118
|
const deadline = Date.now() + expiresIn * 1000;
|
|
97
119
|
while (Date.now() < deadline) {
|
|
98
120
|
if (signal?.aborted)
|
|
@@ -104,7 +126,7 @@ async function pollLegacyToken(params) {
|
|
|
104
126
|
const response = await fetch(`${apiUrl}/auth/device/token`, {
|
|
105
127
|
method: "POST",
|
|
106
128
|
headers: { "Content-Type": "application/json" },
|
|
107
|
-
body: JSON.stringify({ deviceCode })
|
|
129
|
+
body: JSON.stringify(clientId ? { deviceCode, client_id: clientId } : { deviceCode })
|
|
108
130
|
});
|
|
109
131
|
if (!response.ok)
|
|
110
132
|
continue;
|
|
@@ -129,6 +151,150 @@ async function pollLegacyToken(params) {
|
|
|
129
151
|
}
|
|
130
152
|
throw new Error("Authorization timed out. Please try again.");
|
|
131
153
|
}
|
|
154
|
+
var init_device_flow = __esm(() => {
|
|
155
|
+
init_constants();
|
|
156
|
+
});
|
|
157
|
+
|
|
158
|
+
// src/core/auth/token.ts
|
|
159
|
+
function decodeJwtPayload(token) {
|
|
160
|
+
try {
|
|
161
|
+
const parts = token.split(".");
|
|
162
|
+
if (parts.length !== 3)
|
|
163
|
+
return null;
|
|
164
|
+
const payload = Buffer.from(parts[1], "base64url").toString("utf-8");
|
|
165
|
+
return JSON.parse(payload);
|
|
166
|
+
} catch {
|
|
167
|
+
return null;
|
|
168
|
+
}
|
|
169
|
+
}
|
|
170
|
+
function isTokenExpired(token, bufferSeconds = 60) {
|
|
171
|
+
const payload = decodeJwtPayload(token);
|
|
172
|
+
if (!payload || typeof payload.exp !== "number")
|
|
173
|
+
return true;
|
|
174
|
+
const nowSeconds = Math.floor(Date.now() / 1000);
|
|
175
|
+
return payload.exp - nowSeconds < bufferSeconds;
|
|
176
|
+
}
|
|
177
|
+
async function fetchWorkOSClientId() {
|
|
178
|
+
if (cachedClientId)
|
|
179
|
+
return cachedClientId;
|
|
180
|
+
try {
|
|
181
|
+
const apiUrl = getPensarApiUrl();
|
|
182
|
+
const response = await fetch(`${apiUrl}/api/cli/config`);
|
|
183
|
+
if (!response.ok)
|
|
184
|
+
return null;
|
|
185
|
+
const data = await response.json();
|
|
186
|
+
cachedClientId = data.workosClientId;
|
|
187
|
+
return cachedClientId;
|
|
188
|
+
} catch {
|
|
189
|
+
return null;
|
|
190
|
+
}
|
|
191
|
+
}
|
|
192
|
+
async function refreshAccessToken(clientId, refreshToken) {
|
|
193
|
+
try {
|
|
194
|
+
const response = await fetch("https://api.workos.com/user_management/authenticate", {
|
|
195
|
+
method: "POST",
|
|
196
|
+
headers: { "Content-Type": "application/json" },
|
|
197
|
+
body: JSON.stringify({
|
|
198
|
+
client_id: clientId,
|
|
199
|
+
grant_type: "refresh_token",
|
|
200
|
+
refresh_token: refreshToken
|
|
201
|
+
})
|
|
202
|
+
});
|
|
203
|
+
if (!response.ok) {
|
|
204
|
+
console.error(`[pensar] Token refresh failed: ${response.status} ${response.statusText}`);
|
|
205
|
+
return null;
|
|
206
|
+
}
|
|
207
|
+
const data = await response.json();
|
|
208
|
+
await config.update({
|
|
209
|
+
accessToken: data.access_token,
|
|
210
|
+
refreshToken: data.refresh_token
|
|
211
|
+
});
|
|
212
|
+
return data.access_token;
|
|
213
|
+
} catch (err) {
|
|
214
|
+
console.error("[pensar] Token refresh error:", err);
|
|
215
|
+
return null;
|
|
216
|
+
}
|
|
217
|
+
}
|
|
218
|
+
async function ensureValidToken(cfg) {
|
|
219
|
+
if (cfg.accessToken) {
|
|
220
|
+
if (!isTokenExpired(cfg.accessToken)) {
|
|
221
|
+
return { token: cfg.accessToken, type: "workos" };
|
|
222
|
+
}
|
|
223
|
+
if (cfg.refreshToken) {
|
|
224
|
+
const clientId = await fetchWorkOSClientId();
|
|
225
|
+
if (clientId) {
|
|
226
|
+
const newToken = await refreshAccessToken(clientId, cfg.refreshToken);
|
|
227
|
+
if (newToken) {
|
|
228
|
+
return { token: newToken, type: "workos" };
|
|
229
|
+
}
|
|
230
|
+
}
|
|
231
|
+
}
|
|
232
|
+
}
|
|
233
|
+
if (cfg.pensarAPIKey) {
|
|
234
|
+
return { token: cfg.pensarAPIKey, type: "legacy" };
|
|
235
|
+
}
|
|
236
|
+
return null;
|
|
237
|
+
}
|
|
238
|
+
var cachedClientId = null;
|
|
239
|
+
var init_token = __esm(() => {
|
|
240
|
+
init_constants();
|
|
241
|
+
init_config();
|
|
242
|
+
});
|
|
243
|
+
|
|
244
|
+
// src/core/auth/gateway.ts
|
|
245
|
+
async function validateGateway() {
|
|
246
|
+
const cfg = await config.get();
|
|
247
|
+
const tokenResult = await ensureValidToken({
|
|
248
|
+
accessToken: cfg.accessToken,
|
|
249
|
+
refreshToken: cfg.refreshToken,
|
|
250
|
+
pensarAPIKey: cfg.pensarAPIKey
|
|
251
|
+
});
|
|
252
|
+
if (!tokenResult)
|
|
253
|
+
return null;
|
|
254
|
+
const gatewayUrl = cfg.gatewayUrl || getPensarGatewayUrl();
|
|
255
|
+
const headers = {
|
|
256
|
+
Authorization: `Bearer ${tokenResult.token}`
|
|
257
|
+
};
|
|
258
|
+
if (cfg.workspaceId) {
|
|
259
|
+
headers["X-Workspace-Id"] = cfg.workspaceId;
|
|
260
|
+
}
|
|
261
|
+
const response = await fetch(`${gatewayUrl}/gateway/validate`, {
|
|
262
|
+
method: "GET",
|
|
263
|
+
headers
|
|
264
|
+
});
|
|
265
|
+
if (!response.ok) {
|
|
266
|
+
throw new Error(`Gateway validation failed (${response.status})`);
|
|
267
|
+
}
|
|
268
|
+
const result = await response.json();
|
|
269
|
+
if (result.signingKey || result.gatewayUrl) {
|
|
270
|
+
await config.update({
|
|
271
|
+
gatewaySigningKey: result.signingKey ?? undefined,
|
|
272
|
+
gatewayUrl: result.gatewayUrl ?? undefined
|
|
273
|
+
});
|
|
274
|
+
}
|
|
275
|
+
return result;
|
|
276
|
+
}
|
|
277
|
+
var init_gateway = __esm(() => {
|
|
278
|
+
init_constants();
|
|
279
|
+
init_config();
|
|
280
|
+
init_token();
|
|
281
|
+
});
|
|
282
|
+
|
|
283
|
+
// src/core/auth/signing.ts
|
|
284
|
+
import { createHash, createHmac, randomUUID } from "crypto";
|
|
285
|
+
function signGatewayRequest(signingKey, modelId, body) {
|
|
286
|
+
const timestamp = String(Math.floor(Date.now() / 1000));
|
|
287
|
+
const nonce = randomUUID();
|
|
288
|
+
const bodyHash = createHash("sha256").update(body).digest("hex");
|
|
289
|
+
const payload = `${timestamp}
|
|
290
|
+
${nonce}
|
|
291
|
+
${modelId}
|
|
292
|
+
${bodyHash}`;
|
|
293
|
+
const signature = createHmac("sha256", signingKey).update(payload).digest("base64");
|
|
294
|
+
return { signature, timestamp, nonce };
|
|
295
|
+
}
|
|
296
|
+
var init_signing = () => {};
|
|
297
|
+
|
|
132
298
|
// src/core/auth/workspaces.ts
|
|
133
299
|
function sleep2(ms) {
|
|
134
300
|
return new Promise((resolve) => setTimeout(resolve, ms));
|
|
@@ -184,51 +350,16 @@ async function selectWorkspace(apiUrl, accessToken, workspaceId) {
|
|
|
184
350
|
}
|
|
185
351
|
return await response.json();
|
|
186
352
|
}
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
}
|
|
201
|
-
// src/core/auth/gateway.ts
|
|
202
|
-
async function validateGateway() {
|
|
203
|
-
const cfg = await config.get();
|
|
204
|
-
const tokenResult = await ensureValidToken({
|
|
205
|
-
accessToken: cfg.accessToken,
|
|
206
|
-
refreshToken: cfg.refreshToken,
|
|
207
|
-
pensarAPIKey: cfg.pensarAPIKey
|
|
208
|
-
});
|
|
209
|
-
if (!tokenResult)
|
|
210
|
-
return null;
|
|
211
|
-
const gatewayUrl = cfg.gatewayUrl || getPensarGatewayUrl();
|
|
212
|
-
const headers = {
|
|
213
|
-
Authorization: `Bearer ${tokenResult.token}`
|
|
214
|
-
};
|
|
215
|
-
if (cfg.workspaceId) {
|
|
216
|
-
headers["X-Workspace-Id"] = cfg.workspaceId;
|
|
217
|
-
}
|
|
218
|
-
const response = await fetch(`${gatewayUrl}/gateway/validate`, {
|
|
219
|
-
method: "GET",
|
|
220
|
-
headers
|
|
221
|
-
});
|
|
222
|
-
if (!response.ok) {
|
|
223
|
-
throw new Error(`Gateway validation failed (${response.status})`);
|
|
224
|
-
}
|
|
225
|
-
const result = await response.json();
|
|
226
|
-
if (result.signingKey || result.gatewayUrl) {
|
|
227
|
-
await config.update({
|
|
228
|
-
gatewaySigningKey: result.signingKey ?? undefined,
|
|
229
|
-
gatewayUrl: result.gatewayUrl ?? undefined
|
|
230
|
-
});
|
|
231
|
-
}
|
|
232
|
-
return result;
|
|
233
|
-
}
|
|
234
|
-
export { signGatewayRequest, startDeviceFlow, pollWorkOSToken, pollLegacyToken, fetchWorkspaces, pollForWorkspaceCreation, selectWorkspace, isConnected, disconnect, validateGateway };
|
|
353
|
+
var init_workspaces = () => {};
|
|
354
|
+
|
|
355
|
+
// src/core/auth/index.ts
|
|
356
|
+
var init_auth = __esm(() => {
|
|
357
|
+
init_connection();
|
|
358
|
+
init_device_flow();
|
|
359
|
+
init_gateway();
|
|
360
|
+
init_signing();
|
|
361
|
+
init_token();
|
|
362
|
+
init_workspaces();
|
|
363
|
+
});
|
|
364
|
+
|
|
365
|
+
export { getPensarApiUrl, getPensarGatewayUrl, getPensarConsoleUrl, init_constants, isConnected, disconnect, startDeviceFlow, pollWorkOSToken, pollLegacyToken, isTokenExpired, ensureValidToken, validateGateway, signGatewayRequest, fetchWorkspaces, pollForWorkspaceCreation, selectWorkspace, init_auth };
|