109 lines
5.0 KiB
JavaScript
109 lines
5.0 KiB
JavaScript
// Copyright (c) Microsoft Corporation. All rights reserved.
|
|
// Licensed under the MIT license.
|
|
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
return new (P || (P = Promise))(function (resolve, reject) {
|
|
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
});
|
|
};
|
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
exports.validateManifest = exports.ManifestValidation = exports.ManifestValidationReport = exports.ManifestValidationProduct = exports.ManifestValidationIssue = exports.ManifestValidationDetails = void 0;
|
|
const fs_1 = require("fs");
|
|
const teams_manifest_1 = require("@microsoft/teams-manifest");
|
|
const node_fetch_1 = require("node-fetch");
|
|
const manifestOperations_1 = require("./manifestOperations");
|
|
const defaults_1 = require("./defaults");
|
|
class ManifestValidationDetails {
|
|
}
|
|
exports.ManifestValidationDetails = ManifestValidationDetails;
|
|
class ManifestValidationIssue {
|
|
}
|
|
exports.ManifestValidationIssue = ManifestValidationIssue;
|
|
class ManifestValidationProduct {
|
|
}
|
|
exports.ManifestValidationProduct = ManifestValidationProduct;
|
|
class ManifestValidationReport {
|
|
}
|
|
exports.ManifestValidationReport = ManifestValidationReport;
|
|
class ManifestValidation {
|
|
constructor() {
|
|
this.isValid = false;
|
|
}
|
|
}
|
|
exports.ManifestValidation = ManifestValidation;
|
|
function validateManifest(manifestPath, verifyProduction = false) {
|
|
return __awaiter(this, void 0, void 0, function* () {
|
|
try {
|
|
const validation = new ManifestValidation();
|
|
// read the manifest file to ensure the file path is valid
|
|
yield manifestOperations_1.OfficeAddinManifest.readManifestFile(manifestPath);
|
|
if (manifestPath.endsWith(".json")) {
|
|
const manifest = yield teams_manifest_1.ManifestUtil.loadFromPath(manifestPath);
|
|
const validationResult = yield teams_manifest_1.ManifestUtil.validateManifest(manifest);
|
|
if (validationResult.length !== 0) {
|
|
// There are errors
|
|
validation.isValid = false;
|
|
validation.report = new ManifestValidationReport();
|
|
validation.report.errors = [];
|
|
validationResult.forEach((error) => {
|
|
var _a, _b;
|
|
let issue = new ManifestValidationIssue();
|
|
issue.content = error;
|
|
issue.title = "Error";
|
|
(_b = (_a = validation.report) === null || _a === void 0 ? void 0 : _a.errors) === null || _b === void 0 ? void 0 : _b.push(issue);
|
|
});
|
|
}
|
|
else {
|
|
validation.isValid = true;
|
|
}
|
|
}
|
|
else {
|
|
const stream = yield (0, fs_1.createReadStream)(manifestPath);
|
|
const clientId = verifyProduction ? "Default" : "devx";
|
|
let response;
|
|
try {
|
|
response = yield (0, node_fetch_1.default)(`https://validationgateway.omex.office.net/package/api/check?clientId=${clientId}`, {
|
|
body: stream,
|
|
headers: {
|
|
"Content-Type": "application/xml",
|
|
},
|
|
method: "POST",
|
|
});
|
|
}
|
|
catch (err) {
|
|
throw new Error(`Unable to contact the manifest validation service.\n${err}`);
|
|
}
|
|
validation.status = response.status;
|
|
validation.statusText = response.statusText;
|
|
const text = yield response.text();
|
|
try {
|
|
const json = JSON.parse(text.trim());
|
|
if (json) {
|
|
validation.report = json;
|
|
}
|
|
}
|
|
catch (_a) { } // eslint-disable-line no-empty
|
|
if (validation.report) {
|
|
const result = validation.report.status;
|
|
if (result) {
|
|
switch (result.toLowerCase()) {
|
|
case "accepted":
|
|
validation.isValid = true;
|
|
break;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
return validation;
|
|
}
|
|
catch (err) {
|
|
defaults_1.usageDataObject.reportException("validateManifest()", err);
|
|
throw err;
|
|
}
|
|
});
|
|
}
|
|
exports.validateManifest = validateManifest;
|
|
//# sourceMappingURL=validate.js.map
|