 {
  const requestUrl = commandLine.getArgument(0);
  const requestUserAgent = commandLine.getArgument(1);
  const requestBuilderFilePath = commandLine.getArgument(2);

  const requestBuilderFile = await File.createFromFileName(
    requestBuilderFilePath
  );
  const requestBuilder = JSON.parse(await requestBuilderFile.text());

  const requestInit = await createRequestInit(requestBuilder);
  (requestInit.headers ??= {})["User-Agent"] = requestUserAgent;
  const request = new Request(requestUrl, requestInit);
  const response = await fetch(request);
  if (!response.ok) {
    console.error(
      `Request failed: ${response.status} ${response.statusText}\n${await response.text()}`
    );
    return 1;
  }

  await IOUtils.write(requestBuilderFilePath, await response.bytes());

  return EXIT_CODE.SUCCESS;
}
PK