polygonKonva = async (points) => {
  try {
    const delay = (timeout = 0) => new Promise((resolve) => setTimeout(resolve, timeout));
    const stage = window.Konva.stages[0];

    for (const point of points) {
      stage.fire("mousedown", {
        evt: { offsetX: point[0], offsetY: point[1], timeStamp: Date.now(), preventDefault: () => {} },
      });
      stage.fire("click", {
        evt: { offsetX: point[0], offsetY: point[1], timeStamp: Date.now(), preventDefault: () => {} },
      });
      stage.fire("mouseup", {
        evt: { offsetX: point[0], offsetY: point[1], timeStamp: Date.now(), preventDefault: () => {} },
      });
      await delay(50);
    }

    // this works in 50% runs for no reason; maybe some async lazy calculations
    // const firstPoint = stage.getIntersection({ x, y });

    // Circles (polygon points) redraw every new click so we can find it only after last click
    const lastPoint = stage.find("Circle").slice(-1)[0];
    const firstPoint = lastPoint.parent.find("Circle")[0];
    // for closing the Polygon we should place cursor over the first point

    firstPoint.fire("mouseover");
    await delay(100);
    // and only after that we can click on it
    firstPoint.fire("click", { evt: { preventDefault: () => {} } });
  } catch (e) {
    return String(e);
  }
}
Create Polygon on Stage by clicking multiple times and click on the first point at the end
@param {number[][]} points array of coords arrays ([[x1, y1], [x2, y2], ...])