// flips the api's e2e network kill-switch (api routes/dev.ts) so a flow can
// make authed writes fail and then recover — the ios simulator has no airplane
// mode, so maestro's setAirplaneMode is a no-op here. DOWN is passed as a
// runScript env string ('true' | 'false'); anything else leaves the api online.

var apiUrl =
  typeof API_URL === 'string' && API_URL.length
    ? API_URL
    : 'http://localhost:4000'
var down = typeof DOWN === 'string' && DOWN === 'true'

var res = http.post(apiUrl + '/dev/network', {
  headers: {'Content-Type': 'application/json'},
  body: JSON.stringify({down: down}),
})
// fail the flow here rather than let a silently-missed toggle surface as a
// confusing assertion timeout later
if (!res.ok)
  throw new Error('/dev/network failed with status ' + res.status)
