UNPKG

3.19 kBJavaScriptView Raw
1// Copyright (c) Microsoft Corporation. All rights reserved.
2// Licensed under the MIT license.
3var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
4 function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
5 return new (P || (P = Promise))(function (resolve, reject) {
6 function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
7 function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
8 function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
9 step((generator = generator.apply(thisArg, _arguments || [])).next());
10 });
11};
12Object.defineProperty(exports, "__esModule", { value: true });
13const fs_1 = require("fs");
14const node_fetch_1 = require("node-fetch");
15class ManifestValidationDetails {
16}
17exports.ManifestValidationDetails = ManifestValidationDetails;
18class ManifestValidationIssue {
19}
20exports.ManifestValidationIssue = ManifestValidationIssue;
21class ManifestValidationProduct {
22}
23exports.ManifestValidationProduct = ManifestValidationProduct;
24class ManifestValidationReport {
25}
26exports.ManifestValidationReport = ManifestValidationReport;
27class ManifestValidation {
28 constructor() {
29 this.isValid = false;
30 }
31}
32exports.ManifestValidation = ManifestValidation;
33function validateManifest(manifestPath) {
34 return __awaiter(this, void 0, void 0, function* () {
35 const validation = new ManifestValidation();
36 // read the manifest file
37 // const manifest = await readManifestFile(manifestPath);
38 const stream = yield fs_1.createReadStream(manifestPath);
39 let response;
40 try {
41 response = yield node_fetch_1.default("https://verificationservice.osi.office.net/ova/addincheckingagent.svc/api/addincheck", {
42 body: stream,
43 headers: {
44 "Content-Type": "application/xml",
45 },
46 method: "POST",
47 });
48 }
49 catch (err) {
50 throw new Error(`Unable to contact the manifest validation service.\n${err}`);
51 }
52 const text = yield response.text();
53 const json = JSON.parse(text.trim());
54 if (json && json.checkReport) {
55 validation.report = json.checkReport.validationReport;
56 validation.details = json.checkReport.details;
57 validation.status = json.status;
58 }
59 if (validation.report) {
60 const result = validation.report.result;
61 if (result) {
62 switch (result.toLowerCase()) {
63 case "passed":
64 validation.isValid = true;
65 break;
66 }
67 }
68 }
69 else {
70 throw new Error("The manifest validation service did not return the expected response.");
71 }
72 return validation;
73 });
74}
75exports.validateManifest = validateManifest;
76//# sourceMappingURL=validate.js.map
\No newline at end of file