import { SHJDatasourceV2 as P } from "../index.mjs";
import { httpRequest as f } from "../utils/request.mjs";
import { DataSourceUtils as t } from "../utils/utils.mjs";
const S = (e, h, i) => {
  const { api: n } = e.source;
  try {
    if (n) {
      let { isHeaders: y, isBody: c, headers: r, contentType: d, url: a, postParam: o } = n;
      const l = t.getEnvironments(), p = (E) => {
        E.then((m) => {
          if (m.status === 200) {
            P.processData(
              e.source,
              m.data,
              e.id,
              h
            ).then((D) => {
              D && i(D);
            }).catch(() => i(t.noneData(e.id)));
            return;
          }
          i(t.noneData(e.id));
        }).catch(() => {
          i(t.noneData(e.id));
        });
      }, s = l.envBaseUrl || "";
      a = t.replaceURLVariables(a), a = t.replaceStringVariables(a), c && (o = t.replaceObjectVariables(o)), y && (r = t.replaceObjectVariables(r)), n.type === "GET" && p(f.get(s + a, { headers: r })), n.type === "POST" && p(
        f.post(
          s + a,
          o,
          { headers: r },
          d
        )
      ), n.type === "PUT" && p(
        f.put(
          s + a,
          o,
          { headers: r },
          d
        )
      ), n.type === "DELETE" && p(f.delete(s + a, { headers: r }));
    } else
      i(t.noneData(e.id));
  } catch {
    i(t.noneData(e.id));
  }
};
export {
  f as httpRequest,
  S as parseAPIPort
};
