import { createRequire as _createRequire } from 'node:module';
const require = _createRequire(import.meta.url);
import {
  createHttpClient,
  isHttpError,
  pRetry
} from "./chunk-HWT3LUJJ.js";
import {
  getTestOverrides
} from "./chunk-XZUGLEBK.js";
import {
  CliError,
  CliErrorCode
} from "./chunk-MTT3QXBC.js";
import {
  init_esm_shims
} from "./chunk-EXLZF52D.js";

// ../cli-site-old/src/http-request.ts
init_esm_shims();
async function httpRequest({ type, authState }, requestOptions, retryOptions) {
  const { minRetryTimeout } = getTestOverrides();
  const opts = {
    type,
    getAppToken: authState?.getAccessToken,
    createHeaders: authState?.getRequestHeaders
  };
  try {
    const requestPromise = retryOptions ? pRetry(() => createHttpClient(opts).request(requestOptions), {
      ...retryOptions,
      minTimeout: minRetryTimeout
    }) : createHttpClient(opts).request(requestOptions);
    return await requestPromise;
  } catch (e) {
    if (isHttpError(e) && e.response?.status === 403) {
      throw new CliError({
        code: CliErrorCode.PermissionDenied(),
        cause: e
      });
    }
    throw e;
  }
}

export {
  httpRequest
};
//# sourceMappingURL=chunk-HTRGINHM.js.map