openclaw
Version:
Multi-channel AI gateway with extensible messaging integrations
39 lines (38 loc) • 1.55 kB
JavaScript
import { n as authorizeOperatorScopesForMethod } from "./method-scopes-K6J_UQGL.js";
import { a as authorizeGatewayHttpRequestOrReply, v as resolveTrustedHttpOperatorScopes } from "./http-auth-utils-C3lb4QXY.js";
import { c as sendMethodNotAllowed, i as readJsonBodyOrError, l as sendMissingScopeForbidden } from "./http-common-BaZaosnr.js";
import "./http-utils-BHgXp7Zb.js";
//#region src/gateway/http-endpoint-helpers.ts
/** Handles a gateway POST JSON endpoint and returns the parsed body when authorized. */
async function handleGatewayPostJsonEndpoint(req, res, opts) {
if (new URL(req.url ?? "/", "http://localhost").pathname !== opts.pathname) return false;
if (req.method !== "POST") {
sendMethodNotAllowed(res);
return;
}
const requestAuth = await authorizeGatewayHttpRequestOrReply({
req,
res,
auth: opts.auth,
trustedProxies: opts.trustedProxies,
allowRealIpFallback: opts.allowRealIpFallback,
rateLimiter: opts.rateLimiter
});
if (!requestAuth) return;
if (opts.requiredOperatorMethod) {
const requestedScopes = opts.resolveOperatorScopes?.(req, requestAuth) ?? resolveTrustedHttpOperatorScopes(req, requestAuth);
const scopeAuth = authorizeOperatorScopesForMethod(opts.requiredOperatorMethod, requestedScopes);
if (!scopeAuth.allowed) {
sendMissingScopeForbidden(res, scopeAuth.missingScope);
return;
}
}
const body = await readJsonBodyOrError(req, res, opts.maxBodyBytes);
if (body === void 0) return;
return {
body,
requestAuth
};
}
//#endregion
export { handleGatewayPostJsonEndpoint as t };