Source: bemap-services-v2/acl/bemap-geoserver-info-service.js

/**
 * BeNomad BeMap JavaScript API - GeoServerInfoService (v1.5)
 *
 * Promise-based wrapper around `POST service/geoServerInfo/1.0`. Returns
 * the metadata for a given geoserver: which BeMap services it exposes
 * (Routing, Geocoding, NearPoi, ...), which travel modes it supports,
 * the global copyright + supplier terms strings, and the per-service
 * resource limits (max distance, max via count, max isochrone radius, ...).
 *
 * **Why you want this in a customer app.** Combined with
 * `bemap.AclService.getCurrentUserDetails()` (which tells you _which
 * geoservers_ the user is allowed to use), this service tells you _which
 * services_ each of those geoservers actually exposes — so the UI can
 * disable controls that wouldn't work, surface server-side limits as
 * form hints, and never send a request the server would reject.
 *
 * Typical use:
 *
 *     var info = new bemap.GeoServerInfoService(ctx);
 *     info.getInfo('here').then(function(meta) {
 *         if (!meta.hasService('NearPoi')) hideNearPoiButton();
 *         var maxDist = meta.getLimitsForService('BenomadNearPoiService')
 *             .find(function(l) { return l.getKey() === 'MaxDistance'; });
 *         if (maxDist) updateSliderMax(Number(maxDist.getValue()));
 *     });
 *
 * @since 1.5.0
 * @public
 * @constructor
 * @extends {bemap.ServiceV2}
 * @param {bemap.Context} context BeMap-JS-API Context. Mandatory.
 * @param {Object} [options]
 */
bemap.GeoServerInfoService = function(context, options) {
    bemap.ServiceV2.call(this, context, options);
};
bemap.inherits(bemap.GeoServerInfoService, bemap.ServiceV2);

/**
 * Fetch the metadata for the named geoserver. When `geoserverName` is
 * omitted, the Context's configured geoserver is used.
 *
 * @public
 * @param {String} [geoserverName]
 * @param {Object} [options]
 * @param {String} [options.language]  ISO 639-1 language code for titles / descriptions.
 * @param {Array.<String>} [options.options]  Optional list of `LayersInfoOption` values.
 * @param {AbortSignal} [options.signal]
 * @return {Promise<bemap.GeoServerInfoResponse>}
 */
bemap.GeoServerInfoService.prototype.getInfo = function(geoserverName, options) {
    var opts = options || {};
    var body = {
        geoserver: geoserverName || this.ctx.getGeoserver()
    };
    if (opts.language) body.language = opts.language;
    if (Array.isArray(opts.options) && opts.options.length) body.options = opts.options.slice();

    return this._post('service/geoServerInfo/1.0', body, { signal: opts.signal })
        .then(function(json) {
            return bemap.GeoServerInfoResponse.fromJson(json);
        });
};