function normalizeId(value) {
  if (typeof value !== "string") return null;
  const trimmed = value.trim();
  return trimmed.length > 0 ? trimmed : null;
}
function resolveActiveOrganizationId(auth) {
  if (!auth) return null;
  const selected = normalizeId(auth.orgId);
  if (selected) return selected;
  const actorOrgId = normalizeId(auth.actorOrgId);
  if (!actorOrgId) return null;
  if ("actorTenantId" in auth) {
    const actorTenantId = normalizeId(auth.actorTenantId);
    const effectiveTenantId = normalizeId(auth.tenantId);
    if (!actorTenantId || actorTenantId !== effectiveTenantId) return null;
  }
  return actorOrgId;
}
const ORGANIZATION_SCOPE_REQUIRED_ERROR_CODE = "organization_scope_required";
function organizationScopeRequiredResponse() {
  return Response.json(
    {
      error: "Select an organization to access this resource",
      code: ORGANIZATION_SCOPE_REQUIRED_ERROR_CODE
    },
    { status: 400 }
  );
}
export {
  ORGANIZATION_SCOPE_REQUIRED_ERROR_CODE,
  organizationScopeRequiredResponse,
  resolveActiveOrganizationId
};
//# sourceMappingURL=organizationScope.js.map
