Measurement of cosmic deuteron flux with the AMS-02 detector