Hello,
In ArcGIS Online, you can export features from a hosted feature service to a zipped shapefile from the service's Overview page:

In addition, I'd like to clip the features using a user-defined extent.
I'm using the JavaScript API (v. 3.19).
I've seen a number of pieces that seem to have at least some of this functionality, including:
However, none of these samples put it all together. Is this even possible to do in JavaScript? Do I need to construct calls to the REST API? What's the URL of the GP service that I can use as an AGOL subscriber to perform the extraction?