Liferay.Loader.define("commerce-frontend-js@3.0.26/utilities/AJAX/index", ['module', 'exports', 'require', 'frontend-js-web', '../index'], function (module, exports, require) {
  var define = undefined;
  var global = window;
  {
    Object.defineProperty(exports, "__esModule", {
      value: true
    });
    exports.default = void 0;

    var _frontendJsWeb = require("frontend-js-web");

    var _index = require("../index");

    function ownKeys(object, enumerableOnly) {
      var keys = Object.keys(object);if (Object.getOwnPropertySymbols) {
        var symbols = Object.getOwnPropertySymbols(object);if (enumerableOnly) symbols = symbols.filter(function (sym) {
          return Object.getOwnPropertyDescriptor(object, sym).enumerable;
        });keys.push.apply(keys, symbols);
      }return keys;
    }

    function _objectSpread(target) {
      for (var i = 1; i < arguments.length; i++) {
        var source = arguments[i] != null ? arguments[i] : {};if (i % 2) {
          ownKeys(Object(source), true).forEach(function (key) {
            _defineProperty(target, key, source[key]);
          });
        } else if (Object.getOwnPropertyDescriptors) {
          Object.defineProperties(target, Object.getOwnPropertyDescriptors(source));
        } else {
          ownKeys(Object(source)).forEach(function (key) {
            Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key));
          });
        }
      }return target;
    }

    function _defineProperty(obj, key, value) {
      if (key in obj) {
        Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true });
      } else {
        obj[key] = value;
      }return obj;
    }

    var BASE_OPTIONS = _objectSpread({}, _index.fetchParams);

    function _fetch(url) {
      var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
      return (0, _frontendJsWeb.fetch)(url, _objectSpread(_objectSpread({}, BASE_OPTIONS), options)).then(function (response) {
        if (!response.ok) {
          return response.json().catch(function (parseError) {
            return Promise.reject(new Error(parseError));
          }).then(function (reason) {
            return Promise.reject(reason);
          });
        }

        if (response.status === 204) {
          return Promise.resolve();
        }

        return response.json();
      }).catch(function (error) {
        return Promise.reject(error);
      });
    }

    var AJAX = {
      DELETE: function DELETE(apiUrl) {
        var customOptions = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};

        var options = _objectSpread({
          method: 'DELETE'
        }, customOptions);

        return _fetch(apiUrl, options);
      },
      GET: function GET(apiUrl) {
        var customOptions = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
        return _fetch(apiUrl, customOptions);
      },
      PATCH: function PATCH(apiUrl) {
        var jsonProps = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
        var customOptions = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};

        var options = _objectSpread({
          body: JSON.stringify(jsonProps),
          method: 'PATCH'
        }, customOptions);

        return _fetch(apiUrl, options);
      },
      POST: function POST(apiUrl) {
        var json = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
        var customOptions = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};

        var options = _objectSpread({
          body: JSON.stringify(json),
          method: 'POST'
        }, customOptions);

        return _fetch(apiUrl, options);
      },
      PUT: function PUT(apiUrl) {
        var json = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
        var customOptions = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};

        var options = _objectSpread({
          body: JSON.stringify(json),
          method: 'PUT'
        }, customOptions);

        return _fetch(apiUrl, options);
      }
    };
    var _default = AJAX;
    exports.default = _default;
    //# sourceMappingURL=index.js.map
  }
});
//# sourceMappingURL=index.js.map