Add server routes for companies, approvals, costs, and dashboard
New routes: companies, approvals, costs, dashboard, authz. New
services: companies, approvals, costs, dashboard, heartbeat,
activity-log. Add auth middleware and structured error handling.
Expand existing agent and issue routes with richer CRUD operations.
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-02-17 09:07:27 -06:00
|
|
|
import type { Request } from "express";
|
2026-02-23 14:40:32 -06:00
|
|
|
import { forbidden, unauthorized } from "../errors.js";
|
Add server routes for companies, approvals, costs, and dashboard
New routes: companies, approvals, costs, dashboard, authz. New
services: companies, approvals, costs, dashboard, heartbeat,
activity-log. Add auth middleware and structured error handling.
Expand existing agent and issue routes with richer CRUD operations.
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-02-17 09:07:27 -06:00
|
|
|
|
|
|
|
|
export function assertBoard(req: Request) {
|
|
|
|
|
if (req.actor.type !== "board") {
|
|
|
|
|
throw forbidden("Board access required");
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2026-03-23 15:57:57 -05:00
|
|
|
export function assertInstanceAdmin(req: Request) {
|
|
|
|
|
assertBoard(req);
|
|
|
|
|
if (req.actor.source === "local_implicit" || req.actor.isInstanceAdmin) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
throw forbidden("Instance admin access required");
|
|
|
|
|
}
|
|
|
|
|
|
Add server routes for companies, approvals, costs, and dashboard
New routes: companies, approvals, costs, dashboard, authz. New
services: companies, approvals, costs, dashboard, heartbeat,
activity-log. Add auth middleware and structured error handling.
Expand existing agent and issue routes with richer CRUD operations.
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-02-17 09:07:27 -06:00
|
|
|
export function assertCompanyAccess(req: Request, companyId: string) {
|
2026-02-23 14:40:32 -06:00
|
|
|
if (req.actor.type === "none") {
|
|
|
|
|
throw unauthorized();
|
|
|
|
|
}
|
Add server routes for companies, approvals, costs, and dashboard
New routes: companies, approvals, costs, dashboard, authz. New
services: companies, approvals, costs, dashboard, heartbeat,
activity-log. Add auth middleware and structured error handling.
Expand existing agent and issue routes with richer CRUD operations.
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-02-17 09:07:27 -06:00
|
|
|
if (req.actor.type === "agent" && req.actor.companyId !== companyId) {
|
|
|
|
|
throw forbidden("Agent key cannot access another company");
|
|
|
|
|
}
|
2026-02-23 14:40:32 -06:00
|
|
|
if (req.actor.type === "board" && req.actor.source !== "local_implicit" && !req.actor.isInstanceAdmin) {
|
|
|
|
|
const allowedCompanies = req.actor.companyIds ?? [];
|
|
|
|
|
if (!allowedCompanies.includes(companyId)) {
|
|
|
|
|
throw forbidden("User does not have access to this company");
|
|
|
|
|
}
|
|
|
|
|
}
|
Add server routes for companies, approvals, costs, and dashboard
New routes: companies, approvals, costs, dashboard, authz. New
services: companies, approvals, costs, dashboard, heartbeat,
activity-log. Add auth middleware and structured error handling.
Expand existing agent and issue routes with richer CRUD operations.
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-02-17 09:07:27 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export function getActorInfo(req: Request) {
|
2026-02-23 14:40:32 -06:00
|
|
|
if (req.actor.type === "none") {
|
|
|
|
|
throw unauthorized();
|
|
|
|
|
}
|
Add server routes for companies, approvals, costs, and dashboard
New routes: companies, approvals, costs, dashboard, authz. New
services: companies, approvals, costs, dashboard, heartbeat,
activity-log. Add auth middleware and structured error handling.
Expand existing agent and issue routes with richer CRUD operations.
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-02-17 09:07:27 -06:00
|
|
|
if (req.actor.type === "agent") {
|
|
|
|
|
return {
|
|
|
|
|
actorType: "agent" as const,
|
|
|
|
|
actorId: req.actor.agentId ?? "unknown-agent",
|
|
|
|
|
agentId: req.actor.agentId ?? null,
|
2026-02-19 09:09:40 -06:00
|
|
|
runId: req.actor.runId ?? null,
|
Add server routes for companies, approvals, costs, and dashboard
New routes: companies, approvals, costs, dashboard, authz. New
services: companies, approvals, costs, dashboard, heartbeat,
activity-log. Add auth middleware and structured error handling.
Expand existing agent and issue routes with richer CRUD operations.
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-02-17 09:07:27 -06:00
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return {
|
|
|
|
|
actorType: "user" as const,
|
|
|
|
|
actorId: req.actor.userId ?? "board",
|
|
|
|
|
agentId: null,
|
2026-02-19 09:09:40 -06:00
|
|
|
runId: req.actor.runId ?? null,
|
Add server routes for companies, approvals, costs, and dashboard
New routes: companies, approvals, costs, dashboard, authz. New
services: companies, approvals, costs, dashboard, heartbeat,
activity-log. Add auth middleware and structured error handling.
Expand existing agent and issue routes with richer CRUD operations.
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-02-17 09:07:27 -06:00
|
|
|
};
|
|
|
|
|
}
|