Liferay.Loader.define("portal-search-ranking-web@2.0.50/js/utils/api.es", ['module', 'exports', 'require', 'frontend-js-web', './util.es'], function (module, exports, require) {
  var define = undefined;
  var global = window;
  {
    Object.defineProperty(exports, "__esModule", {
      value: true
    });
    exports.fetchResponse = fetchResponse;
    exports.fetchDocuments = fetchDocuments;

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

    var _util = require("./util.es");

    /**
     * Copyright (c) 2000-present Liferay, Inc. All rights reserved.
     *
     * The contents of this file are subject to the terms of the Liferay Enterprise
     * Subscription License ("License"). You may not use this file except in
     * compliance with the License. You can obtain a copy of the License by
     * contacting Liferay, Inc. See the License for the specific language governing
     * permissions and limitations under the License, including but not limited to
     * distribution rights of the Software.
     */

    /**
     * Fetches basic response given the url and parameters.
     * @param {string} url The base url to fetch.
     * @param {Object} params The url parameters to be included in the request.
     * @returns {Promise} The fetch request promise.
     */
    function fetchResponse(url, params) {
      var fetchUrl = new URL(url);
      Object.keys(params).forEach(function (property) {
        if (!(0, _util.isNull)(params[property])) {
          fetchUrl.searchParams.set(property, params[property]);
        }
      });
      return (0, _frontendJsWeb.fetch)(fetchUrl).then(function (response) {
        return response.json();
      });
    }
    /**
     * Fetches documents and maps the data response to the expected object shape
     * of {items: [{}, {}, ...], total: 10}.
     * @param {string} url The base url to fetch documents.
     * @param {Object} params The url parameters to be included in the request.
     * @returns {Promise} The fetch request promise.
     */

    function fetchDocuments(url, params) {
      return fetchResponse(url, params).then(function (data) {
        return {
          items: data.documents,
          total: data.total
        };
      });
    }
    //# sourceMappingURL=api.es.js.map
  }
});
//# sourceMappingURL=api.es.js.map