@xdsjs/dossierx-daemon 0.1.16 → 0.1.18
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.js +122 -12
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -2290,7 +2290,7 @@ function createTaskArchive(options) {
|
|
|
2290
2290
|
|
|
2291
2291
|
// src/version.ts
|
|
2292
2292
|
var DAEMON_PACKAGE_NAME = "@xdsjs/dossierx-daemon";
|
|
2293
|
-
var DAEMON_VERSION = "0.1.
|
|
2293
|
+
var DAEMON_VERSION = "0.1.18";
|
|
2294
2294
|
|
|
2295
2295
|
// src/local-api/server.ts
|
|
2296
2296
|
var DEFAULT_MAX_FILE_BYTES = 5 * 1024 * 1024;
|
|
@@ -2307,12 +2307,51 @@ function json(response, status, body, origin) {
|
|
|
2307
2307
|
});
|
|
2308
2308
|
response.end(JSON.stringify(body));
|
|
2309
2309
|
}
|
|
2310
|
+
function vercelProjectNameFromAllowedOrigin(origin) {
|
|
2311
|
+
try {
|
|
2312
|
+
const url = new URL(origin);
|
|
2313
|
+
if (url.protocol !== "https:" || !url.hostname.endsWith(".vercel.app")) {
|
|
2314
|
+
return null;
|
|
2315
|
+
}
|
|
2316
|
+
const label = url.hostname.slice(0, -".vercel.app".length);
|
|
2317
|
+
for (const suffix of ["-beta", "-production", "-prod", "-preview", "-staging"]) {
|
|
2318
|
+
if (label.endsWith(suffix) && label.length > suffix.length) {
|
|
2319
|
+
return label.slice(0, -suffix.length);
|
|
2320
|
+
}
|
|
2321
|
+
}
|
|
2322
|
+
return label;
|
|
2323
|
+
} catch {
|
|
2324
|
+
return null;
|
|
2325
|
+
}
|
|
2326
|
+
}
|
|
2327
|
+
function isVercelDeploymentOriginAllowed(origin, allowedOrigins) {
|
|
2328
|
+
let requested;
|
|
2329
|
+
try {
|
|
2330
|
+
requested = new URL(origin);
|
|
2331
|
+
} catch {
|
|
2332
|
+
return false;
|
|
2333
|
+
}
|
|
2334
|
+
if (requested.protocol !== "https:" || !requested.hostname.endsWith(".vercel.app")) {
|
|
2335
|
+
return false;
|
|
2336
|
+
}
|
|
2337
|
+
const requestedLabel = requested.hostname.slice(0, -".vercel.app".length);
|
|
2338
|
+
return allowedOrigins.some((allowedOriginValue) => {
|
|
2339
|
+
const projectName = vercelProjectNameFromAllowedOrigin(allowedOriginValue);
|
|
2340
|
+
if (!projectName) {
|
|
2341
|
+
return false;
|
|
2342
|
+
}
|
|
2343
|
+
const deploymentPattern = new RegExp(
|
|
2344
|
+
`^${projectName.replace(/[.*+?^${}()|[\]\\]/g, "\\$&")}-[a-z0-9]+-[a-z0-9-]+$`
|
|
2345
|
+
);
|
|
2346
|
+
return requestedLabel === projectName || deploymentPattern.test(requestedLabel);
|
|
2347
|
+
});
|
|
2348
|
+
}
|
|
2310
2349
|
function allowedOrigin(request, allowedOrigins) {
|
|
2311
2350
|
const origin = request.headers.origin;
|
|
2312
2351
|
if (!origin) {
|
|
2313
2352
|
return "";
|
|
2314
2353
|
}
|
|
2315
|
-
return allowedOrigins.includes(origin) ? origin : null;
|
|
2354
|
+
return allowedOrigins.includes(origin) || isVercelDeploymentOriginAllowed(origin, allowedOrigins) ? origin : null;
|
|
2316
2355
|
}
|
|
2317
2356
|
function requestUrl(request) {
|
|
2318
2357
|
return new URL(request.url ?? "/", "http://127.0.0.1");
|
|
@@ -2545,16 +2584,40 @@ async function startWorkspaceReadServer(options) {
|
|
|
2545
2584
|
const taskArchive = options.taskArchive ?? createTaskArchive({ workspaceRoot: options.workspaceRoot });
|
|
2546
2585
|
const server = createServer((request, response) => {
|
|
2547
2586
|
void (async () => {
|
|
2587
|
+
const url = requestUrl(request);
|
|
2548
2588
|
const origin = allowedOrigin(request, options.allowedOrigins);
|
|
2549
2589
|
if (origin === null) {
|
|
2590
|
+
if (url.pathname === "/workspace/manifest" || url.pathname === "/runtime/daemon") {
|
|
2591
|
+
console.warn(
|
|
2592
|
+
JSON.stringify({
|
|
2593
|
+
msg: url.pathname === "/workspace/manifest" ? "workspace manifest cors rejected" : "runtime daemon cors rejected",
|
|
2594
|
+
origin: request.headers.origin ?? null,
|
|
2595
|
+
requestedMethod: request.headers["access-control-request-method"] ?? null,
|
|
2596
|
+
requestedPrivateNetwork: request.headers["access-control-request-private-network"] ?? null,
|
|
2597
|
+
status: 403,
|
|
2598
|
+
error: "Origin not allowed"
|
|
2599
|
+
})
|
|
2600
|
+
);
|
|
2601
|
+
}
|
|
2550
2602
|
json(response, 403, { error: "Origin not allowed" });
|
|
2551
2603
|
return;
|
|
2552
2604
|
}
|
|
2553
2605
|
if (request.method === "OPTIONS") {
|
|
2606
|
+
if (url.pathname === "/workspace/manifest" || url.pathname === "/runtime/daemon") {
|
|
2607
|
+
console.info(
|
|
2608
|
+
JSON.stringify({
|
|
2609
|
+
msg: url.pathname === "/workspace/manifest" ? "workspace manifest preflight served" : "runtime daemon preflight served",
|
|
2610
|
+
origin,
|
|
2611
|
+
requestedMethod: request.headers["access-control-request-method"] ?? null,
|
|
2612
|
+
requestedPrivateNetwork: request.headers["access-control-request-private-network"] ?? null,
|
|
2613
|
+
status: 204,
|
|
2614
|
+
allowPrivateNetwork: true
|
|
2615
|
+
})
|
|
2616
|
+
);
|
|
2617
|
+
}
|
|
2554
2618
|
json(response, 204, {}, origin);
|
|
2555
2619
|
return;
|
|
2556
2620
|
}
|
|
2557
|
-
const url = requestUrl(request);
|
|
2558
2621
|
if (request.method === "GET" && url.pathname === "/runtime/codex") {
|
|
2559
2622
|
json(
|
|
2560
2623
|
response,
|
|
@@ -2565,6 +2628,14 @@ async function startWorkspaceReadServer(options) {
|
|
|
2565
2628
|
return;
|
|
2566
2629
|
}
|
|
2567
2630
|
if (request.method === "GET" && url.pathname === "/runtime/daemon") {
|
|
2631
|
+
console.info(
|
|
2632
|
+
JSON.stringify({
|
|
2633
|
+
msg: "runtime daemon served",
|
|
2634
|
+
origin,
|
|
2635
|
+
status: 200,
|
|
2636
|
+
currentVersion: daemonVersion
|
|
2637
|
+
})
|
|
2638
|
+
);
|
|
2568
2639
|
json(
|
|
2569
2640
|
response,
|
|
2570
2641
|
200,
|
|
@@ -2614,26 +2685,65 @@ async function startWorkspaceReadServer(options) {
|
|
|
2614
2685
|
const ticker = url.searchParams.get("ticker");
|
|
2615
2686
|
const market = url.searchParams.get("market");
|
|
2616
2687
|
if (!ticker || !market) {
|
|
2688
|
+
console.warn(
|
|
2689
|
+
JSON.stringify({
|
|
2690
|
+
msg: "workspace manifest request rejected",
|
|
2691
|
+
origin,
|
|
2692
|
+
ticker,
|
|
2693
|
+
market,
|
|
2694
|
+
status: 400,
|
|
2695
|
+
error: "Missing ticker or market"
|
|
2696
|
+
})
|
|
2697
|
+
);
|
|
2617
2698
|
json(response, 400, { error: "Missing ticker or market" }, origin);
|
|
2618
2699
|
return;
|
|
2619
2700
|
}
|
|
2620
2701
|
try {
|
|
2621
|
-
|
|
2622
|
-
|
|
2623
|
-
|
|
2624
|
-
|
|
2625
|
-
|
|
2702
|
+
const body = await readCompanyManifest({
|
|
2703
|
+
workspaceRoot: options.workspaceRoot,
|
|
2704
|
+
ticker,
|
|
2705
|
+
market
|
|
2706
|
+
});
|
|
2707
|
+
const paths = body.manifest.pages.map((page) => page.path);
|
|
2708
|
+
console.info(
|
|
2709
|
+
JSON.stringify({
|
|
2710
|
+
msg: "workspace manifest served",
|
|
2711
|
+
origin,
|
|
2626
2712
|
ticker,
|
|
2627
|
-
market
|
|
2628
|
-
|
|
2629
|
-
|
|
2713
|
+
market,
|
|
2714
|
+
status: 200,
|
|
2715
|
+
pageCount: paths.length,
|
|
2716
|
+
hasNotebook: paths.some(
|
|
2717
|
+
(item) => item.endsWith("/financial-reports/notebooklm/notebook.json")
|
|
2718
|
+
),
|
|
2719
|
+
hasFactsBundle: paths.some(
|
|
2720
|
+
(item) => item.endsWith("/financial-reports/ingest/facts-bundle.json")
|
|
2721
|
+
),
|
|
2722
|
+
hasFinancialWiki: paths.some(
|
|
2723
|
+
(item) => item.endsWith(
|
|
2724
|
+
"/financial-reports/wiki/financial-report-analysis.md"
|
|
2725
|
+
)
|
|
2726
|
+
)
|
|
2727
|
+
})
|
|
2630
2728
|
);
|
|
2729
|
+
json(response, 200, body, origin);
|
|
2631
2730
|
} catch (error) {
|
|
2731
|
+
const message = error instanceof Error ? error.message : "Workspace manifest failed";
|
|
2732
|
+
console.warn(
|
|
2733
|
+
JSON.stringify({
|
|
2734
|
+
msg: "workspace manifest request failed",
|
|
2735
|
+
origin,
|
|
2736
|
+
ticker,
|
|
2737
|
+
market,
|
|
2738
|
+
status: 400,
|
|
2739
|
+
error: message
|
|
2740
|
+
})
|
|
2741
|
+
);
|
|
2632
2742
|
json(
|
|
2633
2743
|
response,
|
|
2634
2744
|
400,
|
|
2635
2745
|
{
|
|
2636
|
-
error:
|
|
2746
|
+
error: message
|
|
2637
2747
|
},
|
|
2638
2748
|
origin
|
|
2639
2749
|
);
|