1 |
|
2 |
|
3 | var __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 | };
|
12 | Object.defineProperty(exports, "__esModule", { value: true });
|
13 | const fs_1 = require("fs");
|
14 | const node_fetch_1 = require("node-fetch");
|
15 | class ManifestValidationDetails {
|
16 | }
|
17 | exports.ManifestValidationDetails = ManifestValidationDetails;
|
18 | class ManifestValidationIssue {
|
19 | }
|
20 | exports.ManifestValidationIssue = ManifestValidationIssue;
|
21 | class ManifestValidationProduct {
|
22 | }
|
23 | exports.ManifestValidationProduct = ManifestValidationProduct;
|
24 | class ManifestValidationReport {
|
25 | }
|
26 | exports.ManifestValidationReport = ManifestValidationReport;
|
27 | class ManifestValidation {
|
28 | constructor() {
|
29 | this.isValid = false;
|
30 | }
|
31 | }
|
32 | exports.ManifestValidation = ManifestValidation;
|
33 | function validateManifest(manifestPath) {
|
34 | return __awaiter(this, void 0, void 0, function* () {
|
35 | const validation = new ManifestValidation();
|
36 |
|
37 |
|
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 | }
|
75 | exports.validateManifest = validateManifest;
|
76 |
|
\ | No newline at end of file |