{"size": 3255, "ext": "js", "max_stars_repo_path": "node_modules/@microsoft/sp-loader/lib/stores/ManifestProvider.js", "max_stars_repo_name": "GhostMachineSoftware/SPFx_GetListItems", "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "node_modules/@microsoft/sp-loader/lib/stores/ManifestProvider.js", "max_issues_repo_name": "GhostMachineSoftware/SPFx_GetListItems", "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "node_modules/@microsoft/sp-loader/lib/stores/ManifestProvider.js", "max_forks_repo_name": "GhostMachineSoftware/SPFx_GetListItems", "max_forks_repo_forks_event_min_datetime": "2020-12-01T19:20:33.000Z", "max_forks_repo_forks_event_max_datetime": "2020-12-01T19:20:33.000Z"}
{"max_stars_count": null, "max_issues_count": null, "max_forks_count": 1, "avg_line_length": 53.3606557377, "max_line_length": 154, "alphanum_fraction": 0.6688172043}
import { Validate } from '@microsoft/sp-core-library';
import { _LogSource, _QosMonitor, _TraceLogger } from '@microsoft/sp-diagnostics';
import { SPHttpClient } from '@microsoft/sp-http';
import { PageContext } from '@microsoft/sp-page-context';
/**
 * @internal
 */
var ManifestProvider = /** @class */ (function () {
    function ManifestProvider(serviceScope, webAbsoluteUrl) {
        Validate.isNotNullOrUndefined(serviceScope, 'serviceScope');
        this._logSource = _LogSource.create('ManifestProvider');
        this._webAbsoluteUrl = webAbsoluteUrl;
        this._pageContext = serviceScope.consume(PageContext.serviceKey);
        this._httpClient = serviceScope.consume(SPHttpClient.serviceKey);
    }
    /**
     * Given a component id and version, requests its manifest (and all its dependencies) to SharePoint
     * through a REST API.
     * Returns a promise with all the manifests.
     * @param componentId - Id of the requested component
     * @param version - Optional. Version of the requested component
     */
    ManifestProvider.prototype.tryGetManifest = function (componentId, version) {
        return this.tryGetManifests([{ id: componentId, version: version }]);
    };
    /**
     * Given an array of ids and versions, requests their manifest (and all their dependencies) to SharePoint
     * through a REST API.
     * Returns a promise with all the manifests.
     * @param ids - Array with all the id and version pairs
     */
    ManifestProvider.prototype.tryGetManifests = function (ids) {
        var _this = this;
        var qosMonitor = new _QosMonitor('ManifestProvider.tryGetManifests');
        var webUrl = (this._pageContext.web && this._pageContext.web.absoluteUrl) || this._webAbsoluteUrl;
        return this._httpClient.post(webUrl + ManifestProvider._restApiUrl, SPHttpClient.configurations.v1, {
            body: JSON.stringify({ components: ids })
        }).then(function (response) {
            if (!response.ok) {
                var error = new Error("GetClientSideComponents failed with HTTP status " + response.status);
                qosMonitor.writeUnexpectedFailure('UnsuccessfulResponse', error, { statusCode: response.status, correlationId: response.correlationId });
                throw error;
            }
            qosMonitor.writeSuccess({ correlationId: response.correlationId });
            return response.json().then(_this._extractManifests);
        }).catch(function (error) {
            _TraceLogger.logError(_this._logSource, error);
            qosMonitor.writeUnexpectedFailure(undefined, error);
            throw error;
        });
    };
    ManifestProvider.prototype._extractManifests = function (response) {
        return response.value
            .filter(function (qr) { return qr.Status === 0 && !!qr.Manifest; }) // Remove query results that weren't successful or empty manifests
            .map(function (qr) { return JSON.parse(qr.Manifest); }); // Create the manifest object out of the string
    };
    ManifestProvider._restApiUrl = '/_api/web/GetClientSideComponents';
    return ManifestProvider;
}());
export default ManifestProvider;
//# sourceMappingURL=ManifestProvider.js.map