“flashing” just means “writing to dedicated partitions on the NVME drive.”
You can write a program that first downloads the appropriate files to the local main file system (to make sure you have the full data package,) and then uses “dd” (with root permissions) or C-style open()/write() to update each of the partitions. This is similar to what an OTA update might want to do, too.
Note that if you lose power in the middle, you’re very likely to render the device un-bootable, without then recovering from boot driver / USB mode, though.