"use strict";

Object.defineProperty(exports, "__esModule", {
  value: true
});
exports.ActionRoute = void 0;
function _express() {
  const data = require("@teambit/express");
  _express = function () {
    return data;
  };
  return data;
}
function _legacy() {
  const data = require("@teambit/legacy.scope-api");
  _legacy = function () {
    return data;
  };
  return data;
}
function _http() {
  const data = require("@teambit/legacy/dist/scope/network/http/http");
  _http = function () {
    return data;
  };
  return data;
}
function _defineProperty(e, r, t) { return (r = _toPropertyKey(r)) in e ? Object.defineProperty(e, r, { value: t, enumerable: !0, configurable: !0, writable: !0 }) : e[r] = t, e; }
function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == typeof i ? i : i + ""; }
function _toPrimitive(t, r) { if ("object" != typeof t || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != typeof i) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); }
class ActionRoute {
  constructor(scope) {
    this.scope = scope;
    _defineProperty(this, "method", 'post');
    _defineProperty(this, "route", '/scope/action');
    _defineProperty(this, "verb", _express().Verb.WRITE);
    _defineProperty(this, "middlewares", [async (req, res) => {
      req.setTimeout(this.scope.config.httpTimeOut);
      const authData = (0, _http().getAuthDataFromHeader)(req.headers.authorization);
      const result = await (0, _legacy().action)(this.scope.path, req.body.name, req.body.options, authData);
      // in case the result is empty, send `{}` to make it a valid json.
      res.json(result || {});
    }]);
  }
}
exports.ActionRoute = ActionRoute;

//# sourceMappingURL=action.route.js.map