Ассистент менеджера: вопрос о chargeback к контракту подрядчика (khb-chargeback, п.87); граница с accounting_automation
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -5,6 +5,7 @@ import { registerAgentRoutes } from "./agents-api.js";
|
||||
import { usageSummary, type UsageLog } from "./usage.js";
|
||||
import type { PrepJob, PrepResult } from "./jobs.js";
|
||||
import { checkMailAuth } from "./mail/auth.js";
|
||||
import { checkChargebackAuth, forwardChargeback, type ChargebackConfig } from "./chargeback/proxy.js";
|
||||
import { resolveForManager, sendForManager, type MailDeps } from "./mail/service.js";
|
||||
|
||||
export interface ChatApi {
|
||||
@@ -24,6 +25,8 @@ export interface PrepApiDeps {
|
||||
usageLog?: UsageLog;
|
||||
/** Письма подрядчикам (команда khb-mail): токен менеджера, не общий токен сервиса. */
|
||||
mail?: { deps: MailDeps; secret: string };
|
||||
/** chargeback к контракту (команда khb-chargeback): токен менеджера, вызов уходит в accounting_automation. */
|
||||
chargeback?: ChargebackConfig;
|
||||
}
|
||||
|
||||
interface RunState {
|
||||
@@ -45,6 +48,10 @@ export function buildApi(deps: PrepApiDeps): FastifyInstance {
|
||||
if (!deps.mail || !checkMailAuth(deps.mail.secret, String(req.headers["x-khb-caller"] ?? ""), req.headers.authorization)) return reply.code(401).send({ error: "unauthorized" });
|
||||
return;
|
||||
}
|
||||
if (req.url.startsWith("/chargeback/")) {
|
||||
if (!deps.chargeback || !checkChargebackAuth(deps.chargeback.secret, String(req.headers["x-khb-caller"] ?? ""), req.headers.authorization)) return reply.code(401).send({ error: "unauthorized" });
|
||||
return;
|
||||
}
|
||||
if (req.headers.authorization !== `Bearer ${deps.token}`) return reply.code(401).send({ error: "unauthorized" });
|
||||
});
|
||||
|
||||
@@ -59,6 +66,15 @@ export function buildApi(deps: PrepApiDeps): FastifyInstance {
|
||||
sendForManager(mail, { managerId: caller(req), project: req.body?.project, vendor: req.body?.vendor, work: req.body?.work, date: String(req.body?.date ?? ""), note: req.body?.note, channel: req.body?.channel }));
|
||||
}
|
||||
|
||||
if (deps.chargeback) {
|
||||
const cb = deps.chargeback;
|
||||
app.post<{ Params: { action: string }; Body: Record<string, unknown> }>("/chargeback/:action", async (req, reply) => {
|
||||
const body = req.body && typeof req.body === "object" && !Array.isArray(req.body) ? req.body : {};
|
||||
const r = await forwardChargeback(cb, req.params.action, String(req.headers["x-khb-caller"]), body);
|
||||
return reply.code(r.status).send(r.body);
|
||||
});
|
||||
}
|
||||
|
||||
app.get("/healthz", async () => {
|
||||
let db = false;
|
||||
try {
|
||||
|
||||
Reference in New Issue
Block a user