import { v as validateAuth } from './auth-DuunT7Cg.js';
import { s as sosCoordinator } from './coordinator-DMU_ADXf.js';
import { j as json } from './index-lhTMmBNn.js';
import './shared-server-DaWdgxVh.js';
import 'crypto';
import 'better-sqlite3';
import 'fs';
import 'os';
import 'path';

const MAX_RELAY_TEXT = 10240;
const POST = async ({ params, request }) => {
  const authError = validateAuth(request);
  if (authError) {
    return authError;
  }
  let body;
  try {
    body = await request.json();
  } catch {
    return json({ error: "Invalid JSON in request body" }, { status: 400 });
  }
  if (typeof body !== "object" || body === null) {
    return json({ error: "Invalid JSON in request body" }, { status: 400 });
  }
  const payload = body;
  if (typeof payload.toMemberId !== "string" || payload.toMemberId.length === 0) {
    return json({ error: "toMemberId is required (string)" }, { status: 400 });
  }
  if (typeof payload.text !== "string" || payload.text.length === 0) {
    return json({ error: "text is required (string)" }, { status: 400 });
  }
  if (Buffer.byteLength(payload.text, "utf8") > MAX_RELAY_TEXT) {
    return json({ error: `text exceeds ${MAX_RELAY_TEXT} bytes` }, { status: 413 });
  }
  const error = sosCoordinator.relayForward(params.id ?? "", payload.toMemberId, payload.text);
  if (error) {
    const status = error.includes("not found") ? 404 : 400;
    return json({ error }, { status });
  }
  return json({ ok: true });
};

export { POST };
//# sourceMappingURL=_server.ts-NVx03KEN.js.map
