Initial commit

This commit is contained in:
2025-03-07 19:22:02 +01:00
commit 4a98255d83
55743 changed files with 5280367 additions and 0 deletions
+34
View File
@@ -0,0 +1,34 @@
/**
* The types of Office add-ins.
*/
export declare enum AddInType {
Content = "content",
Mail = "mail",
TaskPane = "taskpane"
}
/**
* Get the Office app for the manifest Host name
* @param host Host name
*/
export declare function getAddInTypeForManifestOfficeAppType(officeAppType: string): AddInType | undefined;
/**
* Returns the Office add-in types.
*/
export declare function getAddInTypes(): AddInType[];
/**
* Converts the string to the AddInType enum value.
* @param value string
* @throws Error if the value is not a valid Office add-in type.
*/
export declare function parseAddInType(value: string): AddInType;
/**
* Converts the strings to the AddInType enum values.
* @param input "all" for all Office add-in types, or a comma-separated list of one or more Office apps.
* @throws Error if a value is not a valid Office app.
*/
export declare function parseAddInTypes(input: string): AddInType[];
/**
* Returns the AddInType enum for the value, or undefined if not valid.
* @param value Office add-in type string
*/
export declare function toAddInType(value: string): AddInType | undefined;
+88
View File
@@ -0,0 +1,88 @@
"use strict";
// copyright (c) Microsoft Corporation. All rights reserved.
// licensed under the MIT license.
Object.defineProperty(exports, "__esModule", { value: true });
exports.toAddInType = exports.parseAddInTypes = exports.parseAddInType = exports.getAddInTypes = exports.getAddInTypeForManifestOfficeAppType = exports.AddInType = void 0;
const office_addin_usage_data_1 = require("office-addin-usage-data");
/**
* The types of Office add-ins.
*/
var AddInType;
(function (AddInType) {
// the string values should be lowercase
AddInType["Content"] = "content";
AddInType["Mail"] = "mail";
AddInType["TaskPane"] = "taskpane";
// when adding new entries, update the other functions
})(AddInType = exports.AddInType || (exports.AddInType = {}));
// initialized once since this list won't change
const addInTypes = Object.keys(AddInType).map((key) => parseAddInType(key));
/**
* Get the Office app for the manifest Host name
* @param host Host name
*/
function getAddInTypeForManifestOfficeAppType(officeAppType) {
switch (officeAppType ? officeAppType.trim().toLowerCase() : officeAppType) {
case "contentapp":
return AddInType.Content;
case "mailapp":
return AddInType.Mail;
case "taskpaneapp":
return AddInType.TaskPane;
default:
return undefined;
}
}
exports.getAddInTypeForManifestOfficeAppType = getAddInTypeForManifestOfficeAppType;
/**
* Returns the Office add-in types.
*/
function getAddInTypes() {
return addInTypes;
}
exports.getAddInTypes = getAddInTypes;
/**
* Converts the string to the AddInType enum value.
* @param value string
* @throws Error if the value is not a valid Office add-in type.
*/
function parseAddInType(value) {
const addInType = toAddInType(value);
if (!addInType) {
throw new office_addin_usage_data_1.ExpectedError(`${value} is not a valid Office add-in type.`);
}
return addInType;
}
exports.parseAddInType = parseAddInType;
/**
* Converts the strings to the AddInType enum values.
* @param input "all" for all Office add-in types, or a comma-separated list of one or more Office apps.
* @throws Error if a value is not a valid Office app.
*/
function parseAddInTypes(input) {
if (input.trim().toLowerCase() === "all") {
return getAddInTypes();
}
else {
return input.split(",").map((appString) => parseAddInType(appString));
}
}
exports.parseAddInTypes = parseAddInTypes;
/**
* Returns the AddInType enum for the value, or undefined if not valid.
* @param value Office add-in type string
*/
function toAddInType(value) {
switch (value.trim().toLowerCase()) {
case AddInType.Content:
return AddInType.Content;
case AddInType.Mail:
return AddInType.Mail;
case AddInType.TaskPane:
return AddInType.TaskPane;
default:
return undefined;
}
}
exports.toAddInType = toAddInType;
//# sourceMappingURL=addInTypes.js.map
+1
View File
@@ -0,0 +1 @@
{"version":3,"file":"addInTypes.js","sourceRoot":"","sources":["../src/addInTypes.ts"],"names":[],"mappings":";AAAA,4DAA4D;AAC5D,kCAAkC;;;AAElC,qEAAwD;AAExD;;GAEG;AACH,IAAY,SAMX;AAND,WAAY,SAAS;IACnB,wCAAwC;IACxC,gCAAmB,CAAA;IACnB,0BAAa,CAAA;IACb,kCAAqB,CAAA;IACrB,sDAAsD;AACxD,CAAC,EANW,SAAS,GAAT,iBAAS,KAAT,iBAAS,QAMpB;AAED,gDAAgD;AAChD,MAAM,UAAU,GAAgB,MAAM,CAAC,IAAI,CAAC,SAAS,CAAC,CAAC,GAAG,CAAY,CAAC,GAAG,EAAE,EAAE,CAAC,cAAc,CAAC,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KAAK,SAAS,CAAC,IAAI;YACjB,OAAO,SAAS,CAAC,IAAI,CAAC;QACxB,KAAK,SAAS,CAAC,QAAQ;YACrB,OAAO,SAAS,CAAC,QAAQ,CAAC;QAC5B;YACE,OAAO,SAAS,CAAC;KACpB;AACH,CAAC;AAXD,kCAWC"}
+2
View File
@@ -0,0 +1,2 @@
#!/usr/bin/env node
export {};
+63
View File
@@ -0,0 +1,63 @@
#!/usr/bin/env node
"use strict";
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT license.
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
var desc = Object.getOwnPropertyDescriptor(m, k);
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
desc = { enumerable: true, get: function() { return m[k]; } };
}
Object.defineProperty(o, k2, desc);
}) : (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
o[k2] = m[k];
}));
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
Object.defineProperty(o, "default", { enumerable: true, value: v });
}) : function(o, v) {
o["default"] = v;
});
var __importStar = (this && this.__importStar) || function (mod) {
if (mod && mod.__esModule) return mod;
var result = {};
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
__setModuleDefault(result, mod);
return result;
};
Object.defineProperty(exports, "__esModule", { value: true });
const commander_1 = require("commander");
const office_addin_usage_data_1 = require("office-addin-usage-data");
const commands = __importStar(require("./commands"));
/* global process */
const commander = new commander_1.Command();
commander.name("office-addin-manifest");
commander.version(process.env.npm_package_version || "(version not available)");
commander.command("info <manifest-path>").action(commands.info);
commander
.command("modify <manifest-path>")
.option("-g,--guid [guid]", "Change the guid. A random guid is used if one is not provided.")
.option("-d, --displayName <name>", "Change the display name.")
.action(commands.modify);
commander
.command("validate <manifest-path>")
.option("-p, --production", "Verify the manifest for production environment")
.action(commands.validate);
commander
.command("export")
.option("-m, --manifest <manfest-path>", "Specify the location of the manifest file. Default is './manifest.json'")
.option("-o, --output <output-path>", "Specify where to save the package. Default is next to the manifest file input")
.action(commands.exportManifest);
// if the command is not known, display an error
commander.on("command:*", function () {
(0, office_addin_usage_data_1.logErrorMessage)(`The command syntax is not valid.\n`);
process.exitCode = 1;
commander.help();
});
if (process.argv.length > 2) {
commander.parse(process.argv);
}
else {
commander.help();
}
//# sourceMappingURL=cli.js.map
+1
View File
@@ -0,0 +1 @@
{"version":3,"file":"cli.js","sourceRoot":"","sources":["../src/cli.ts"],"names":[],"mappings":";;AAEA,4DAA4D;AAC5D,kCAAkC;;;;;;;;;;;;;;;;;;;;;;;;;AAElC,yCAAoC;AACpC,qEAA0D;AAC1D,qDAAuC;AAEvC,oBAAoB;AAEpB,MAAM,SAAS,GAAG,IAAI,mBAAO,EAAE,CAAC;AAEhC,SAAS,CAAC,IAAI,CAAC,uBAAuB,CAAC,CAAC;AACxC,SAAS,CAAC,OAAO,CAAC,OAAO,CAAC,GAAG,CAAC,mBAAmB,IAAI,yBAAyB,CAAC,CAAC;AAEhF,SAAS,CAAC,OAAO,CAAC,sBAAsB,CAAC,CAAC,MAAM,CAAC,QAAQ,CAAC,IAAI,CAAC,CAAC;AAEhE,SAAS;KACN,OAAO,CAAC,wBAAwB,CAAC;KACjC,MAAM,CAAC,kBAAkB,EAAE,gEAAgE,CAAC;KAC5F,MAAM,CAAC,0BAA0B,EAAE,0BAA0B,CAAC;KAC9D,MAAM,CAAC,QAAQ,CAAC,MAAM,CAAC,CAAC;AAE3B,SAAS;KACN,OAAO,CAAC,0BAA0B,CAAC;KACnC,MAAM,CAAC,kBAAkB,EAAE,gDAAgD,CAAC;KAC5E,MAAM,CAAC,QAAQ,CAAC,QAAQ,CAAC,CAAC;AAE7B,SAAS;KACN,OAAO,CAAC,QAAQ,CAAC;KACjB,MAAM,CACL,+BAA+B,EAC/B,0EAA0E,CAC3E;KACA,MAAM,CACL,4BAA4B,EAC5B,gFAAgF,CACjF;KACA,MAAM,CAAC,QAAQ,CAAC,cAAc,CAAC,CAAC;AAEnC,gDAAgD;AAChD,SAAS,CAAC,EAAE,CAAC,WAAW,EAAE;IACxB,IAAA,yCAAe,EAAC,oCAAoC,CAAC,CAAC;IACtD,OAAO,CAAC,QAAQ,GAAG,CAAC,CAAC;IACrB,SAAS,CAAC,IAAI,EAAE,CAAC;AACnB,CAAC,CAAC,CAAC;AAEH,IAAI,OAAO,CAAC,IAAI,CAAC,MAAM,GAAG,CAAC,EAAE;IAC3B,SAAS,CAAC,KAAK,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC;CAC/B;KAAM;IACL,SAAS,CAAC,IAAI,EAAE,CAAC;CAClB"}
+5
View File
@@ -0,0 +1,5 @@
import { OptionValues } from "commander";
export declare function info(manifestPath: string): Promise<void>;
export declare function modify(manifestPath: string, options: OptionValues): Promise<void>;
export declare function validate(manifestPath: string, options: OptionValues): Promise<void>;
export declare function exportManifest(options: OptionValues): Promise<void>;
+192
View File
@@ -0,0 +1,192 @@
"use strict";
// 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());
});
};
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.exportManifest = exports.validate = exports.modify = exports.info = void 0;
const chalk_1 = __importDefault(require("chalk"));
const office_addin_usage_data_1 = require("office-addin-usage-data");
const manifestOperations_1 = require("./manifestOperations");
const validate_1 = require("./validate");
const defaults_1 = require("./defaults");
const export_1 = require("./export");
/* global console process */
function getCommandOptionString(option, defaultValue) {
// For a command option defined with an optional value, e.g. "--option [value]",
// when the option is provided with a value, it will be of type "string", return the specified value;
// when the option is provided without a value, it will be of type "boolean", return undefined.
return typeof option === "boolean" ? defaultValue : option;
}
function info(manifestPath) {
return __awaiter(this, void 0, void 0, function* () {
try {
const manifest = yield manifestOperations_1.OfficeAddinManifest.readManifestFile(manifestPath);
logManifestInfo(manifestPath, manifest);
defaults_1.usageDataObject.reportSuccess("info");
}
catch (err) {
defaults_1.usageDataObject.reportException("info", err);
(0, office_addin_usage_data_1.logErrorMessage)(err);
}
});
}
exports.info = info;
function logManifestInfo(manifestPath, manifest) {
console.log(`Manifest: ${manifestPath}`);
console.log(` Id: ${manifest.id || ""}`);
console.log(` Name: ${manifest.displayName || ""}`);
console.log(` Provider: ${manifest.providerName || ""}`);
console.log(` Type: ${manifest.officeAppType || ""}`);
console.log(` Version: ${manifest.version || ""}`);
if (manifest.alternateId) {
console.log(` AlternateId: ${manifest.alternateId}`);
}
console.log(` AppDomains: ${manifest.appDomains ? manifest.appDomains.join(", ") : ""}`);
console.log(` Default Locale: ${manifest.defaultLocale || ""}`);
console.log(` Description: ${manifest.description || ""}`);
console.log(` High Resolution Icon Url: ${manifest.highResolutionIconUrl || ""}`);
console.log(` Hosts: ${manifest.hosts ? manifest.hosts.join(", ") : ""}`);
console.log(` Icon Url: ${manifest.iconUrl || ""}`);
console.log(` Permissions: ${manifest.permissions || ""}`);
console.log(` Support Url: ${manifest.supportUrl || ""}`);
if (manifest.defaultSettings) {
console.log(" Default Settings:");
console.log(` Requested Height: ${manifest.defaultSettings.requestedHeight || ""}`);
console.log(` Requested Width: ${manifest.defaultSettings.requestedWidth || ""}`);
console.log(` Source Location: ${manifest.defaultSettings.sourceLocation || ""}`);
}
}
function logManifestValidationErrors(errors) {
if (errors) {
let errorNumber = 1;
for (const currentError of errors) {
console.log(chalk_1.default.bold.red(`Error #${errorNumber}: `));
logManifestValidationIssue(currentError);
console.log();
++errorNumber;
}
}
}
function logManifestValidationInfos(infos) {
if (infos) {
console.log(chalk_1.default.bold.blue(`Validation Information: `));
for (const currentInfo of infos) {
logManifestValidationIssue(currentInfo);
console.log();
}
}
}
function logManifestValidationWarnings(warnings) {
if (warnings) {
let warningNumber = 1;
for (const currentWarning of warnings) {
console.log(chalk_1.default.bold.yellow(`Warning #${warningNumber}: `));
logManifestValidationIssue(currentWarning);
console.log();
++warningNumber;
}
}
}
function logManifestValidationIssue(issue) {
console.log(`${issue.title}: ${issue.content}` + (issue.helpUrl ? ` (link: ${issue.helpUrl})` : ``));
if (issue.code) {
console.log(` - Details: ${issue.code}`);
}
if (issue.line) {
console.log(` - Line: ${issue.line}`);
}
if (issue.column) {
console.log(` - Column: ${issue.column}`);
}
}
function logManifestValidationSupportedProducts(products) {
if (products) {
const productTitles = new Set(products.filter((product) => product.title).map((product) => product.title));
if (productTitles.size > 0) {
console.log(`\nBased on the requirements specified in your manifest, your add-in can run on the following platforms; your add-in will be tested on these platforms when you submit it to the Office Store:`);
for (const productTitle of productTitles) {
console.log(` - ${productTitle}`);
}
console.log(`Important: This analysis is based on the requirements specified in your manifest and does not account for any runtime JavaScript calls within your add-in. For information about which API sets and features are supported on each platform, see Office Add-in host and platform availability. (https://docs.microsoft.com/office/dev/add-ins/overview/office-add-in-availability).\n`);
console.log(`*This does not include mobile apps. You can opt-in to support mobile apps when you submit your add-in.`);
}
}
}
function modify(manifestPath, options) {
return __awaiter(this, void 0, void 0, function* () {
try {
// if the --guid command option is provided without a value, use "" to specify to change to a random guid value.
const guid = getCommandOptionString(options.guid, "");
const displayName = getCommandOptionString(options.displayName);
const manifest = yield manifestOperations_1.OfficeAddinManifest.modifyManifestFile(manifestPath, guid, displayName);
logManifestInfo(manifestPath, manifest);
defaults_1.usageDataObject.reportSuccess("modify");
}
catch (err) {
defaults_1.usageDataObject.reportException("modify", err);
(0, office_addin_usage_data_1.logErrorMessage)(err);
}
});
}
exports.modify = modify;
function validate(manifestPath, options) {
return __awaiter(this, void 0, void 0, function* () {
try {
const verifyProduction = options.production;
const validation = yield (0, validate_1.validateManifest)(manifestPath, verifyProduction);
if (validation.status && validation.status != 200) {
console.log(`Unable to validate the manifest.\n${validation.status}\n${validation.statusText}`);
}
else if (validation.report) {
logManifestValidationInfos(validation.report.notes);
logManifestValidationErrors(validation.report.errors);
logManifestValidationWarnings(validation.report.warnings);
if (validation.isValid) {
if (validation.report.addInDetails) {
logManifestValidationSupportedProducts(validation.report.addInDetails.supportedProducts);
console.log();
}
console.log(chalk_1.default.bold.green("The manifest is valid.\n"));
}
else {
console.log(chalk_1.default.bold.red("The manifest is not valid.\n"));
}
}
process.exitCode = validation.isValid ? 0 : 1;
defaults_1.usageDataObject.reportSuccess("validate");
}
catch (err) {
defaults_1.usageDataObject.reportException("validate", err);
(0, office_addin_usage_data_1.logErrorMessage)(err);
}
});
}
exports.validate = validate;
function exportManifest(options) {
var _a, _b;
return __awaiter(this, void 0, void 0, function* () {
try {
const outputPath = (_a = options.output) !== null && _a !== void 0 ? _a : "";
const manifestPath = (_b = options.manifest) !== null && _b !== void 0 ? _b : "./manifest.json";
yield (0, export_1.exportMetadataPackage)(outputPath, manifestPath);
defaults_1.usageDataObject.reportSuccess("export");
}
catch (err) {
defaults_1.usageDataObject.reportException("export", err);
(0, office_addin_usage_data_1.logErrorMessage)(err);
}
});
}
exports.exportManifest = exportManifest;
//# sourceMappingURL=commands.js.map
File diff suppressed because one or more lines are too long
+2
View File
@@ -0,0 +1,2 @@
import { OfficeAddinUsageData } from "office-addin-usage-data";
export declare const usageDataObject: OfficeAddinUsageData;
+13
View File
@@ -0,0 +1,13 @@
"use strict";
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT license.
Object.defineProperty(exports, "__esModule", { value: true });
exports.usageDataObject = void 0;
const office_addin_usage_data_1 = require("office-addin-usage-data");
// Usage data defaults
exports.usageDataObject = new office_addin_usage_data_1.OfficeAddinUsageData({
projectName: "office-addin-manifest",
instrumentationKey: office_addin_usage_data_1.instrumentationKeyForOfficeAddinCLITools,
raisePrompt: false,
});
//# sourceMappingURL=defaults.js.map
+1
View File
@@ -0,0 +1 @@
{"version":3,"file":"defaults.js","sourceRoot":"","sources":["../src/defaults.ts"],"names":[],"mappings":";AAAA,4DAA4D;AAC5D,kCAAkC;;;AAElC,qEAGiC;AAEjC,sBAAsB;AACT,QAAA,eAAe,GAAyB,IAAI,8CAAoB,CAAC;IAC5E,WAAW,EAAE,uBAAuB;IACpC,kBAAkB,EAAE,kEAAwC;IAC5D,WAAW,EAAE,KAAK;CACnB,CAAC,CAAC"}
+1
View File
@@ -0,0 +1 @@
export declare function exportMetadataPackage(output?: string, manifest?: string): Promise<string>;
+76
View File
@@ -0,0 +1,76 @@
"use strict";
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());
});
};
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.exportMetadataPackage = void 0;
const fs_1 = __importDefault(require("fs"));
const fs_extra_1 = __importDefault(require("fs-extra"));
const adm_zip_1 = __importDefault(require("adm-zip"));
const path_1 = __importDefault(require("path"));
const teams_manifest_1 = require("@microsoft/teams-manifest");
/* global console */
function exportMetadataPackage(output = "", manifest = "manifest.json") {
return __awaiter(this, void 0, void 0, function* () {
const zip = yield createZip(manifest);
if (output === "") {
output = path_1.default.join(path_1.default.dirname(path_1.default.resolve(manifest)), "manifest.zip");
}
yield saveZip(zip, output);
return Promise.resolve(output);
});
}
exports.exportMetadataPackage = exportMetadataPackage;
function createZip(manifestPath) {
var _a, _b;
return __awaiter(this, void 0, void 0, function* () {
const absolutePath = path_1.default.resolve(manifestPath);
const manifestDir = path_1.default.dirname(absolutePath);
const zip = new adm_zip_1.default();
if (fs_1.default.existsSync(manifestPath)) {
zip.addLocalFile(manifestPath, "", "manifest.json");
}
else {
throw new Error(`The file '${manifestPath}' does not exist`);
}
const manifest = yield teams_manifest_1.ManifestUtil.loadFromPath(manifestPath);
addIconFile((_a = manifest.icons) === null || _a === void 0 ? void 0 : _a.color, manifestDir, zip);
addIconFile((_b = manifest.icons) === null || _b === void 0 ? void 0 : _b.outline, manifestDir, zip);
return Promise.resolve(zip);
});
}
function addIconFile(iconPath, manifestDir, zip) {
if (iconPath && !iconPath.startsWith("https://")) {
const filePath = path_1.default.join(manifestDir, iconPath);
const iconDir = path_1.default.dirname(iconPath);
if (fs_1.default.existsSync(filePath)) {
zip.addLocalFile(filePath, iconDir === "." ? "" : iconDir);
}
else {
console.log(`Icon File ${filePath} does not exist`);
}
}
}
function saveZip(zip, outputPath) {
return __awaiter(this, void 0, void 0, function* () {
outputPath = path_1.default.resolve(outputPath);
fs_extra_1.default.ensureDirSync(path_1.default.dirname(outputPath));
const result = yield zip.writeZipPromise(outputPath);
if (result) {
console.log(`Manifest package saved to ${outputPath}`);
}
else {
throw new Error(`Error writting zip file to ${outputPath}`);
}
});
}
//# sourceMappingURL=export.js.map
+1
View File
@@ -0,0 +1 @@
{"version":3,"file":"export.js","sourceRoot":"","sources":["../src/export.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;AAAA,4CAAoB;AACpB,wDAA+B;AAC/B,sDAA6B;AAC7B,gDAAwB;AACxB,8DAAqE;AAErE,oBAAoB;AAEpB,SAAsB,qBAAqB,CACzC,SAAiB,EAAE,EACnB,WAAmB,eAAe;;QAElC,MAAM,GAAG,GAAW,MAAM,SAAS,CAAC,QAAQ,CAAC,CAAC;QAE9C,IAAI,MAAM,KAAK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E,QAAQ,CAAC,CAAC;QAC1D,MAAM,OAAO,GAAW,cAAI,CAAC,OAAO,CAAC,QAAQ,CAAC,CAAC;QAC/C,IAAI,YAAE,CAAC,UAAU,CAAC,QAAQ,CAAC,EAAE;YAC3B,GAAG,CAAC,YAAY,CAAC,QAAQ,EAAE,OAAO,KAAK,GAAG,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,OAAO,CAAC,CAAC;SAC5D;aAAM;YACL,OAAO,CAAC,GAAG,CAAC,aAAa,QAAQ,iBAAiB,CAAC,CAAC;SACrD;KACF;AACH,CAAC;AAED,SAAe,OAAO,CAAC,GAAW,EAAE,UAAkB;;QACpD,UAAU,GAAG,cAAI,CAAC,OAAO,CAAC,UAAU,CAAC,CAAC;QAEtC,kBAAO,CAAC,aAAa,CAAC,cAAI,CAAC,OAAO,CAAC,UAAU,CAAC,CAAC,CAAC;QAChD,MAAM,MAAM,GAAY,MAAM,GAAG,CAAC,eAAe,CAAC,UAAU,CAAC,CAAC;QAC9D,IAAI,MAAM,EAAE;YACV,OAAO,CAAC,GAAG,CAAC,6BAA6B,UAAU,EAAE,CAAC,CAAC;SACxD;aAAM;YACL,MAAM,IAAI,KAAK,CAAC,8BAA8B,UAAU,EAAE,CAAC,CAAC;SAC7D;IACH,CAAC;CAAA"}
+7
View File
@@ -0,0 +1,7 @@
export * from "./addInTypes";
export * from "./export";
export * from "./manifestInfo";
export * from "./manifestOperations";
export * from "./officeApp";
export * from "./validate";
export * from "./xml";
+26
View File
@@ -0,0 +1,26 @@
"use strict";
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT license.
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
var desc = Object.getOwnPropertyDescriptor(m, k);
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
desc = { enumerable: true, get: function() { return m[k]; } };
}
Object.defineProperty(o, k2, desc);
}) : (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
o[k2] = m[k];
}));
var __exportStar = (this && this.__exportStar) || function(m, exports) {
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
};
Object.defineProperty(exports, "__esModule", { value: true });
__exportStar(require("./addInTypes"), exports);
__exportStar(require("./export"), exports);
__exportStar(require("./manifestInfo"), exports);
__exportStar(require("./manifestOperations"), exports);
__exportStar(require("./officeApp"), exports);
__exportStar(require("./validate"), exports);
__exportStar(require("./xml"), exports);
//# sourceMappingURL=main.js.map
+1
View File
@@ -0,0 +1 @@
{"version":3,"file":"main.js","sourceRoot":"","sources":["../src/main.ts"],"names":[],"mappings":";AAAA,4DAA4D;AAC5D,kCAAkC;;;;;;;;;;;;;;;;AAElC,+CAA6B;AAC7B,2CAAyB;AACzB,iDAA+B;AAC/B,uDAAqC;AACrC,8CAA4B;AAC5B,6CAA2B;AAC3B,wCAAsB"}
@@ -0,0 +1,8 @@
import { ManifestInfo } from "../manifestInfo";
export declare abstract class ManifestHandler {
constructor(manifestPath: string);
abstract modifyManifest(guid?: string, displayName?: string): Promise<any>;
abstract parseManifest(): Promise<ManifestInfo>;
abstract writeManifestData(manifestData: any): Promise<void>;
manifestPath: string;
}
@@ -0,0 +1,12 @@
"use strict";
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT license.
Object.defineProperty(exports, "__esModule", { value: true });
exports.ManifestHandler = void 0;
class ManifestHandler {
constructor(manifestPath) {
this.manifestPath = manifestPath;
}
}
exports.ManifestHandler = ManifestHandler;
//# sourceMappingURL=manifestHandler.js.map
@@ -0,0 +1 @@
{"version":3,"file":"manifestHandler.js","sourceRoot":"","sources":["../../src/manifestHandler/manifestHandler.ts"],"names":[],"mappings":";AAAA,4DAA4D;AAC5D,kCAAkC;;;AAIlC,MAAsB,eAAe;IACnC,YAAY,YAAoB;QAC9B,IAAI,CAAC,YAAY,GAAG,YAAY,CAAC;IACnC,CAAC;CAMF;AATD,0CASC"}
@@ -0,0 +1,9 @@
import { devPreview } from "@microsoft/teams-manifest";
import { ManifestInfo } from "../manifestInfo";
import { ManifestHandler } from "./manifestHandler";
export declare class ManifestHandlerJson extends ManifestHandler {
modifyManifest(guid?: string, displayName?: string): Promise<devPreview.DevPreviewSchema>;
parseManifest(): Promise<ManifestInfo>;
getManifestInfo(appManifest: devPreview.DevPreviewSchema): ManifestInfo;
writeManifestData(manifestData: devPreview.DevPreviewSchema): Promise<void>;
}
@@ -0,0 +1,79 @@
"use strict";
// 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.ManifestHandlerJson = void 0;
const teams_manifest_1 = require("@microsoft/teams-manifest");
const uuid_1 = require("uuid");
const manifestInfo_1 = require("../manifestInfo");
const manifestHandler_1 = require("./manifestHandler");
class ManifestHandlerJson extends manifestHandler_1.ManifestHandler {
modifyManifest(guid, displayName) {
return __awaiter(this, void 0, void 0, function* () {
try {
const appManifest = yield teams_manifest_1.ManifestUtil.loadFromPath(this.manifestPath);
if (typeof guid !== "undefined") {
if (!guid || guid === "random") {
guid = (0, uuid_1.v4)();
}
appManifest.id = guid;
}
if (typeof displayName !== "undefined") {
appManifest.name.short = displayName;
}
return appManifest;
}
catch (err) {
throw new Error(`Unable to modify json data for manifest file: ${this.manifestPath}. \n${err}`);
}
});
}
parseManifest() {
return __awaiter(this, void 0, void 0, function* () {
try {
const file = yield teams_manifest_1.ManifestUtil.loadFromPath(this.manifestPath);
return this.getManifestInfo(file);
}
catch (err) {
throw new Error(`Unable to read data for manifest file: ${this.manifestPath}. \n${err}`);
}
});
}
getManifestInfo(appManifest) {
var _a, _b, _c, _d, _e, _f, _g;
const manifestInfo = new manifestInfo_1.ManifestInfo();
// Need to handle mutliple version of the prerelease json manifest schema
const extensionElement = (_a = appManifest.extensions) === null || _a === void 0 ? void 0 : _a[0];
manifestInfo.id = appManifest.id;
manifestInfo.appDomains = appManifest.validDomains;
manifestInfo.defaultLocale = (_b = appManifest.localizationInfo) === null || _b === void 0 ? void 0 : _b.defaultLanguageTag;
manifestInfo.description = appManifest.description.short;
manifestInfo.displayName = appManifest.name.short;
manifestInfo.highResolutionIconUrl = appManifest.icons.color;
manifestInfo.hosts = (_c = extensionElement === null || extensionElement === void 0 ? void 0 : extensionElement.requirements) === null || _c === void 0 ? void 0 : _c.scopes;
manifestInfo.iconUrl = appManifest.icons.color;
manifestInfo.officeAppType = "TaskPaneApp"; // Should check "ContentRuntimes" in JSON the tell if the Office type is "ContentApp". Hard code here because web extension will be removed after all.
manifestInfo.permissions = (_g = (_f = (_e = (_d = appManifest.authorization) === null || _d === void 0 ? void 0 : _d.permissions) === null || _e === void 0 ? void 0 : _e.resourceSpecific) === null || _f === void 0 ? void 0 : _f[0]) === null || _g === void 0 ? void 0 : _g.name;
manifestInfo.providerName = appManifest.developer.name;
manifestInfo.supportUrl = appManifest.developer.websiteUrl;
manifestInfo.version = appManifest.version;
manifestInfo.manifestType = manifestInfo_1.ManifestType.JSON;
return manifestInfo;
}
writeManifestData(manifestData) {
return __awaiter(this, void 0, void 0, function* () {
yield teams_manifest_1.ManifestUtil.writeToPath(this.manifestPath, manifestData);
});
}
}
exports.ManifestHandlerJson = ManifestHandlerJson;
//# sourceMappingURL=manifestHandlerJson.js.map
@@ -0,0 +1 @@
{"version":3,"file":"manifestHandlerJson.js","sourceRoot":"","sources":["../../src/manifestHandler/manifestHandlerJson.ts"],"names":[],"mappings":";AAAA,4DAA4D;AAC5D,kCAA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ifestHandler } from "./manifestHandler";
export type Xml = xmlMethods.Xml;
export declare class ManifestHandlerXml extends ManifestHandler {
modifyManifest(guid?: string, displayName?: string): Promise<Xml>;
parseManifest(): Promise<ManifestInfo>;
parseXmlAsync(): Promise<Xml>;
readFromManifestFile(): Promise<string>;
setModifiedXmlData(xml: any, guid: string | undefined, displayName: string | undefined): void;
writeManifestData(manifestData: any): Promise<void>;
}
@@ -0,0 +1,159 @@
"use strict";
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT license.
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
var desc = Object.getOwnPropertyDescriptor(m, k);
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
desc = { enumerable: true, get: function() { return m[k]; } };
}
Object.defineProperty(o, k2, desc);
}) : (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
o[k2] = m[k];
}));
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
Object.defineProperty(o, "default", { enumerable: true, value: v });
}) : function(o, v) {
o["default"] = v;
});
var __importStar = (this && this.__importStar) || function (mod) {
if (mod && mod.__esModule) return mod;
var result = {};
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
__setModuleDefault(result, mod);
return result;
};
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());
});
};
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.ManifestHandlerXml = void 0;
const fs_1 = __importDefault(require("fs"));
const util_1 = __importDefault(require("util"));
const uuid_1 = require("uuid");
const xml2js_1 = __importDefault(require("xml2js"));
const xmlMethods = __importStar(require("../xml"));
const manifestInfo_1 = require("../manifestInfo");
const manifestHandler_1 = require("./manifestHandler");
const writeFileAsync = util_1.default.promisify(fs_1.default.writeFile);
class ManifestHandlerXml extends manifestHandler_1.ManifestHandler {
modifyManifest(guid, displayName) {
return __awaiter(this, void 0, void 0, function* () {
try {
const manifestXml = yield this.parseXmlAsync();
this.setModifiedXmlData(manifestXml.OfficeApp, guid, displayName);
return manifestXml;
}
catch (err) {
throw new Error(`Unable to modify xml data for manifest file: ${this.manifestPath}.\n${err}`);
}
});
}
parseManifest() {
return __awaiter(this, void 0, void 0, function* () {
const xml = yield this.parseXmlAsync();
const manifest = new manifestInfo_1.ManifestInfo();
const officeApp = xml.OfficeApp;
if (officeApp) {
const defaultSettingsXml = xmlMethods.getXmlElement(officeApp, "DefaultSettings");
manifest.id = xmlMethods.getXmlElementValue(officeApp, "Id");
manifest.allowSnapshot = xmlMethods.getXmlElementValue(officeApp, "AllowSnapshot");
manifest.alternateId = xmlMethods.getXmlElementValue(officeApp, "AlternateId");
manifest.appDomains = xmlMethods.getXmlElementsValue(officeApp, "AppDomains", "AppDomain");
manifest.defaultLocale = xmlMethods.getXmlElementValue(officeApp, "DefaultLocale");
manifest.description = xmlMethods.getXmlElementAttributeValue(officeApp, "Description");
manifest.displayName = xmlMethods.getXmlElementAttributeValue(officeApp, "DisplayName");
manifest.highResolutionIconUrl = xmlMethods.getXmlElementAttributeValue(officeApp, "HighResolutionIconUrl");
manifest.hosts = xmlMethods.getXmlElementsAttributeValue(officeApp, "Hosts", "Host", "Name");
manifest.iconUrl = xmlMethods.getXmlElementAttributeValue(officeApp, "IconUrl");
manifest.officeAppType = xmlMethods.getXmlAttributeValue(officeApp, "xsi:type");
manifest.permissions = xmlMethods.getXmlElementValue(officeApp, "Permissions");
manifest.providerName = xmlMethods.getXmlElementValue(officeApp, "ProviderName");
manifest.supportUrl = xmlMethods.getXmlElementAttributeValue(officeApp, "SupportUrl");
manifest.version = xmlMethods.getXmlElementValue(officeApp, "Version");
manifest.manifestType = manifestInfo_1.ManifestType.XML;
if (defaultSettingsXml) {
const defaultSettings = new manifestInfo_1.DefaultSettings();
defaultSettings.requestedHeight = xmlMethods.getXmlElementValue(defaultSettingsXml, "RequestedHeight");
defaultSettings.requestedWidth = xmlMethods.getXmlElementValue(defaultSettingsXml, "RequestedWidth");
defaultSettings.sourceLocation = xmlMethods.getXmlElementAttributeValue(defaultSettingsXml, "SourceLocation");
manifest.defaultSettings = defaultSettings;
}
}
return manifest;
});
}
parseXmlAsync() {
return __awaiter(this, void 0, void 0, function* () {
// Needed declaration as `this` does not work inside the new Promise expression
const fileData = yield this.readFromManifestFile();
const manifestPath = this.manifestPath;
return new Promise(function (resolve, reject) {
xml2js_1.default.parseString(fileData, function (parseError, xml) {
if (parseError) {
reject(new Error(`Unable to parse the manifest file: ${manifestPath}. \n${parseError}`));
}
else {
resolve(xml);
}
});
});
});
}
readFromManifestFile() {
return __awaiter(this, void 0, void 0, function* () {
try {
const fileData = yield util_1.default.promisify(fs_1.default.readFile)(this.manifestPath, {
encoding: "utf8",
});
return fileData;
}
catch (err) {
throw new Error(`Unable to read data for manifest file: ${this.manifestPath}.\n${err}`);
}
});
}
setModifiedXmlData(xml, guid, displayName) {
if (typeof guid !== "undefined") {
if (!guid || guid === "random") {
guid = (0, uuid_1.v4)();
}
xmlMethods.setXmlElementValue(xml, "Id", guid);
}
if (typeof displayName !== "undefined") {
xmlMethods.setXmlElementAttributeValue(xml, "DisplayName", displayName);
}
}
writeManifestData(manifestData) {
return __awaiter(this, void 0, void 0, function* () {
let xml;
try {
// Generate xml for the manifest data.
const builder = new xml2js_1.default.Builder();
xml = builder.buildObject(manifestData);
}
catch (err) {
throw new Error(`Unable to generate xml for the manifest.\n${err}`);
}
try {
// Write the xml back to the manifest file.
yield writeFileAsync(this.manifestPath, xml);
}
catch (err) {
throw new Error(`Unable to write to file. ${this.manifestPath} \n${err}`);
}
});
}
}
exports.ManifestHandlerXml = ManifestHandlerXml;
//# sourceMappingURL=manifestHandlerXml.js.map
@@ -0,0 +1 @@
{"version":3,"file":"manifestHandlerXml.js","sourceRoot":"","sources":["../../src/manifestHandler/manifestHandlerXml.ts"],"names":[],"mappings":";AAAA,4DAA4D;AAC5D,kCAAkC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAElC,4CAAoB;AACpB,gDAAwB;AACxB,+BAAoC;AACpC,oDAA4B;AAC5B,mDAAqC;AACrC,kDAA8E;AAC9E,uDAAoD;AACpD,MAAM,cAAc,GAAG,cAAI,CAAC,SAAS,CAAC,YAAE,CAAC,SAAS,CAAC,CAAC;AAGpD,MAAa,kBAAmB,SAAQ,iCAAe;IAC/C,cAAc,CAAC,IAAa,EAAE,WAAoB;;YACtD,IAAI;gBACF,MAAM,WAAW,GAAQ,MAAM,IAAI,CAAC,aAAa,EAAE,CAAC;gBACpD,IAAI,CAAC,kBAAkB,CAAC,WAAW,CAAC,SAAS,EAAE,IAAI,EAAE,WAAW,CAAC,CAAC;gBAClE,OAAO,WAAW,CAAC;aACpB;YAAC,OAAO,GAAG,EAAE;gBACZ,MAAM,IAAI,KAAK,CAAC,gDAAgD,IAAI,CAAC,YAAY,MAAM,GAAG,EAAE,CAAC,CAAC;aAC/F;QACH,CAAC;KAAA;IAEK,aAAa;;YACjB,MAAM,GAAG,GAAG,MAAM,IAAI,CAAC,aAAa,EAAE,CAAC;YACvC,MAAM,QAAQ,GAAiB,IAAI,2BAAY,EAAE,CAAC;YAClD,MAAM,SAAS,GAAQ,GAAG,CAAC,SAAS,CAAC;YAErC,IAAI,SAAS,EAAE;gBACb,MAAM,kBAAkB,GAAQ,UAAU,CAAC,aAAa,CAAC,SAAS,EAAE,iBAAiB,CAAC,CAAC;gBAEvF,QAAQ,CAAC,E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AuHC"}
+28
View File
@@ -0,0 +1,28 @@
export declare class DefaultSettings {
sourceLocation?: string;
requestedWidth?: string;
requestedHeight?: string;
}
export declare enum ManifestType {
JSON = "json",
XML = "xml"
}
export declare class ManifestInfo {
id?: string;
allowSnapshot?: string;
alternateId?: string;
appDomains?: string[];
defaultLocale?: string;
description?: string;
displayName?: string;
highResolutionIconUrl?: string;
hosts?: string[];
iconUrl?: string;
officeAppType?: string;
permissions?: string;
providerName?: string;
supportUrl?: string;
version?: string;
manifestType?: ManifestType;
defaultSettings?: DefaultSettings;
}
+17
View File
@@ -0,0 +1,17 @@
"use strict";
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT license.
Object.defineProperty(exports, "__esModule", { value: true });
exports.ManifestInfo = exports.ManifestType = exports.DefaultSettings = void 0;
class DefaultSettings {
}
exports.DefaultSettings = DefaultSettings;
var ManifestType;
(function (ManifestType) {
ManifestType["JSON"] = "json";
ManifestType["XML"] = "xml";
})(ManifestType = exports.ManifestType || (exports.ManifestType = {}));
class ManifestInfo {
}
exports.ManifestInfo = ManifestInfo;
//# sourceMappingURL=manifestInfo.js.map
+1
View File
@@ -0,0 +1 @@
{"version":3,"file":"manifestInfo.js","sourceRoot":"","sources":["../src/manifestInfo.ts"],"names":[],"mappings":";AAAA,4DAA4D;AAC5D,kCAAkC;;;AAElC,MAAa,eAAe;CAI3B;AAJD,0CAIC;AAED,IAAY,YAGX;AAHD,WAAY,YAAY;IACtB,6BAAa,CAAA;IACb,2BAAW,CAAA;AACb,CAAC,EAHW,YAAY,GAAZ,oBAAY,KAAZ,oBAAY,QAGvB;AAED,MAAa,YAAY;CAmBxB;AAnBD,oCAmBC"}
+5
View File
@@ -0,0 +1,5 @@
import { ManifestInfo } from "./manifestInfo";
export declare namespace OfficeAddinManifest {
function modifyManifestFile(manifestPath: string, guid?: string, displayName?: string): Promise<ManifestInfo>;
function readManifestFile(manifestPath: string): Promise<ManifestInfo>;
}
+78
View File
@@ -0,0 +1,78 @@
"use strict";
// 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.OfficeAddinManifest = void 0;
const defaults_1 = require("./defaults");
const manifestHandlerJson_1 = require("./manifestHandler/manifestHandlerJson");
const manifestHandlerXml_1 = require("./manifestHandler/manifestHandlerXml");
var OfficeAddinManifest;
(function (OfficeAddinManifest) {
function modifyManifestFile(manifestPath, guid, displayName) {
return __awaiter(this, void 0, void 0, function* () {
if (manifestPath) {
if (guid === undefined && displayName === undefined) {
throw new Error("You need to specify something to change in the manifest.");
}
else {
try {
const manifestHandler = yield getManifestHandler(manifestPath);
const manifestData = yield manifestHandler.modifyManifest(guid, displayName);
yield manifestHandler.writeManifestData(manifestData);
const manifestInfo = yield manifestHandler.parseManifest();
defaults_1.usageDataObject.reportSuccess("modifyManifestFile()");
return manifestInfo;
}
catch (err) {
defaults_1.usageDataObject.reportException("modifyManifestFile()", err);
throw err;
}
}
}
else {
throw new Error(`Please provide the path to the manifest file.`);
}
});
}
OfficeAddinManifest.modifyManifestFile = modifyManifestFile;
function readManifestFile(manifestPath) {
return __awaiter(this, void 0, void 0, function* () {
if (manifestPath) {
const manifestHandler = yield getManifestHandler(manifestPath);
const manifest = yield manifestHandler.parseManifest();
return manifest;
}
else {
throw new Error(`Please provide the path to the manifest file.`);
}
});
}
OfficeAddinManifest.readManifestFile = readManifestFile;
})(OfficeAddinManifest = exports.OfficeAddinManifest || (exports.OfficeAddinManifest = {}));
function getManifestHandler(manifestPath) {
var _a;
return __awaiter(this, void 0, void 0, function* () {
let manifestHandler;
if (manifestPath.endsWith(".json")) {
manifestHandler = new manifestHandlerJson_1.ManifestHandlerJson(manifestPath);
}
else if (manifestPath.endsWith(".xml")) {
manifestHandler = new manifestHandlerXml_1.ManifestHandlerXml(manifestPath);
}
else {
const extension = (_a = manifestPath.split(".").pop()) !== null && _a !== void 0 ? _a : "<no extension>";
throw new Error(`Manifest operations are not supported in .${extension}.\nThey are only supported in .xml and in .json.`);
}
return manifestHandler;
});
}
//# sourceMappingURL=manifestOperations.js.map
+1
View File
@@ -0,0 +1 @@
{"version":3,"file":"manifestOperations.js","sourceRoot":"","sources":["../src/manifestOperations.ts"],"names":[],"mappings":";AAAA,4DAA4D;AAC5D,kCAAkC;;;;;;;;;;;;AAElC,yCAA6C;AAG7C,+EAA4E;AAC5E,6EAA0E;AAE1E,IAAiB,mBAAmB,CAoCnC;AApCD,WAAiB,mBAAmB;IAClC,SAAsB,kBAAkB,CACtC,YAAoB,EACpB,IAAa,EACb,WAAoB;;YAEpB,IAAI,YAAY,EAAE;gBAChB,IAAI,IAAI,KAAK,SAAS,IAAI,WAAW,KAAK,SAAS,EAAE;oBACnD,MAAM,IAAI,KAAK,CAAC,0DAA0D,CAAC,CAAC;iBAC7E;qBAAM;oBACL,IAAI;wBACF,MAAM,eAAe,GAAoB,MAAM,kBAAkB,CAAC,YAAY,CAAC,CAAC;wBAChF,MAAM,YAAY,GAAG,MAAM,eAAe,CAAC,cAAc,CAAC,IAAI,EAAE,WAAW,CAAC,CAAC;wBAC7E,MAAM,eAAe,CAAC,iBAAiB,CAAC,YAAY,CAAC,CAAC;wBACtD,MAAM,YAAY,GAAiB,MAAM,eAAe,CAAC,aAAa,EAAE,CAAC;wBACzE,0BAAe,CAAC,aAAa,CAAC,sBAAsB,CAAC,CAAC;wBACtD,OAAO,YAAY,CAAC;qBACrB;oBAAC,OAAO,GAAQ,EAAE;wBACjB,0BAAe,CAAC,eAAe,CAAC,sBAAsB,EAAE,GAAG,CAAC,CAAC;wBAC7D,MAAM,GAAG,CAAC;qBACX;iBACF;aACF;iBAAM;gBACL,MAAM,IAAI,KAAK,CAAC,+CAA+C,CAAC,CAAC;aAClE;QACH,CAAC;KAAA;IAxBqB,sCAAkB,qBAwBvC,CAAA;IAED,SAAsB,gBAAgB,CAAC,YAAoB;;YACzD,IAAI,YAAY,EAAE;gBAChB,MAAM,eAAe,GAAoB,MAAM,kBAAkB,CAAC,YAAY,CAAC,CAAC;gBAChF,MAAM,QAAQ,GAAiB,MAAM,eAAe,CAAC,aAAa,EAAE,CAAC;gBACrE,OAAO,QAAQ,CAAC;aACjB;iBAAM;gBACL,MAAM,IAAI,KAAK,CAAC,+CAA+C,CAAC,CAAC;aAClE;QACH,CAAC;KAAA;IARqB,oCAAgB,mBAQrC,CAAA;AACH,CAAC,EApCgB,mBAAmB,GAAnB,2BAAmB,KAAnB,2BAAmB,QAoCnC;AAED,SAAe,kBAAkB,CAAC,YAAoB;;;QACpD,IAAI,eAAgC,CAAC;QACrC,IAAI,YAAY,CAAC,QAAQ,CAAC,OAAO,CAAC,EAAE;YAClC,eAAe,GAAG,IAAI,yCAAmB,CAAC,YAAY,CAAC,CAAC;SACzD;aAAM,IAAI,YAAY,CAAC,QAAQ,CAAC,MAAM,CAAC,EAAE;YACxC,eAAe,GAAG,IAAI,uCAAkB,CAAC,YAAY,CAAC,CAAC;SACxD;aAAM;YACL,MAAM,SAAS,GAAW,MAAA,YAAY,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,GAAG,EAAE,mCAAI,gBAAgB,CAAC;YAC5E,MAAM,IAAI,KAAK,CACb,6CAA6C,SAAS,kDAAkD,CACzG,CAAC;SACH;QACD,OAAO,eAAe,CAAC;;CACxB"}
+52
View File
@@ -0,0 +1,52 @@
/**
* The Office apps which can host Office Add-ins.
*/
export declare enum OfficeApp {
Excel = "excel",
OneNote = "onenote",
Outlook = "outlook",
PowerPoint = "powerpoint",
Project = "project",
Word = "word"
}
/**
* Get the Office app for the manifest Host name
* @param host Host name
*/
export declare function getOfficeAppForManifestHost(host: string): OfficeApp | undefined;
/**
* Gets the Office application name suitable for display.
* @param app Office app
*/
export declare function getOfficeAppName(app: OfficeApp): string;
/**
* Gets the Office application names suitable for display.
* @param apps Office apps
*/
export declare function getOfficeAppNames(apps: OfficeApp[]): string[];
/**
* Returns the Office apps that support Office add-ins.
*/
export declare function getOfficeApps(): OfficeApp[];
/**
* Get the Office apps for the manifest Host names.
* @param hosts Host names specified in the manifest.
*/
export declare function getOfficeAppsForManifestHosts(hosts?: string[]): OfficeApp[];
/**
* Converts the string to the OfficeApp enum value.
* @param value string
* @throws Error if the value is not a valid Office app.
*/
export declare function parseOfficeApp(value: string): OfficeApp;
/**
* Converts the strings to the OfficeApp enum values.
* @param input "all" for all Office apps, or a comma-separated list of one or more Office apps.
* @throws Error if a value is not a valid Office app.
*/
export declare function parseOfficeApps(input: string): OfficeApp[];
/**
* Returns the OfficeApp enum for the value, or undefined if not valid.
* @param value Office app string
*/
export declare function toOfficeApp(value: string): OfficeApp | undefined;
+153
View File
@@ -0,0 +1,153 @@
"use strict";
// copyright (c) Microsoft Corporation. All rights reserved.
// licensed under the MIT license.
Object.defineProperty(exports, "__esModule", { value: true });
exports.toOfficeApp = exports.parseOfficeApps = exports.parseOfficeApp = exports.getOfficeAppsForManifestHosts = exports.getOfficeApps = exports.getOfficeAppNames = exports.getOfficeAppName = exports.getOfficeAppForManifestHost = exports.OfficeApp = void 0;
/**
* The Office apps which can host Office Add-ins.
*/
var OfficeApp;
(function (OfficeApp) {
// the string values should be lowercase
OfficeApp["Excel"] = "excel";
OfficeApp["OneNote"] = "onenote";
OfficeApp["Outlook"] = "outlook";
OfficeApp["PowerPoint"] = "powerpoint";
OfficeApp["Project"] = "project";
OfficeApp["Word"] = "word";
// when adding new entries, update the toOfficeApp() function
// since there isn't an automatic reverse mapping from string to enum values
})(OfficeApp = exports.OfficeApp || (exports.OfficeApp = {}));
// initialized once since this list won't change
const officeApps = Object.keys(OfficeApp).map((key) => parseOfficeApp(key));
/**
* Get the Office app for the manifest Host name
* @param host Host name
*/
function getOfficeAppForManifestHost(host) {
switch (host.toLowerCase()) {
case "document":
return OfficeApp.Word;
case "mail":
return OfficeApp.Outlook;
case "mailbox":
return OfficeApp.Outlook;
case "notebook":
return OfficeApp.OneNote;
case "presentation":
return OfficeApp.PowerPoint;
case "project":
return OfficeApp.Project;
case "workbook":
return OfficeApp.Excel;
default:
return undefined;
}
}
exports.getOfficeAppForManifestHost = getOfficeAppForManifestHost;
/**
* Gets the Office application name suitable for display.
* @param app Office app
*/
function getOfficeAppName(app) {
switch (app) {
case OfficeApp.Excel:
return "Excel";
case OfficeApp.OneNote:
return "OneNote";
case OfficeApp.Outlook:
return "Outlook";
case OfficeApp.PowerPoint:
return "PowerPoint";
case OfficeApp.Project:
return "Project";
case OfficeApp.Word:
return "Word";
default:
throw new Error(`Unable to provide name for Office app "${app}"`);
}
}
exports.getOfficeAppName = getOfficeAppName;
/**
* Gets the Office application names suitable for display.
* @param apps Office apps
*/
function getOfficeAppNames(apps) {
return apps.map((app) => getOfficeAppName(app));
}
exports.getOfficeAppNames = getOfficeAppNames;
/**
* Returns the Office apps that support Office add-ins.
*/
function getOfficeApps() {
return officeApps;
}
exports.getOfficeApps = getOfficeApps;
/**
* Get the Office apps for the manifest Host names.
* @param hosts Host names specified in the manifest.
*/
function getOfficeAppsForManifestHosts(hosts) {
const apps = [];
if (hosts) {
hosts.forEach((host) => {
const app = getOfficeAppForManifestHost(host);
if (app) {
apps.push(app);
}
});
}
return apps;
}
exports.getOfficeAppsForManifestHosts = getOfficeAppsForManifestHosts;
/**
* Converts the string to the OfficeApp enum value.
* @param value string
* @throws Error if the value is not a valid Office app.
*/
function parseOfficeApp(value) {
const officeApp = toOfficeApp(value);
if (!officeApp) {
throw new Error(`"${value}" is not a valid Office app.`);
}
return officeApp;
}
exports.parseOfficeApp = parseOfficeApp;
/**
* Converts the strings to the OfficeApp enum values.
* @param input "all" for all Office apps, or a comma-separated list of one or more Office apps.
* @throws Error if a value is not a valid Office app.
*/
function parseOfficeApps(input) {
if (input.trim().toLowerCase() === "all") {
return getOfficeApps();
}
else {
return input.split(",").map((appString) => parseOfficeApp(appString));
}
}
exports.parseOfficeApps = parseOfficeApps;
/**
* Returns the OfficeApp enum for the value, or undefined if not valid.
* @param value Office app string
*/
function toOfficeApp(value) {
switch (value ? value.trim().toLowerCase() : value) {
case OfficeApp.Excel:
return OfficeApp.Excel;
case OfficeApp.OneNote:
return OfficeApp.OneNote;
case OfficeApp.Outlook:
return OfficeApp.Outlook;
case OfficeApp.PowerPoint:
return OfficeApp.PowerPoint;
case OfficeApp.Project:
return OfficeApp.Project;
case OfficeApp.Word:
return OfficeApp.Word;
default:
return undefined;
}
}
exports.toOfficeApp = toOfficeApp;
//# sourceMappingURL=officeApp.js.map
+1
View File
@@ -0,0 +1 @@
{"version":3,"file":"officeApp.js","sourceRoot":"","sources":["../src/officeApp.ts"],"names":[],"mappings":";AAAA,4DAA4D;AAC5D,kCAAkC;;;AAElC;;GAEG;AACH,IAAY,SAUX;AAVD,WAAY,SAAS;IACnB,wCAAwC;IACxC,4BAAe,CAAA;IACf,gCAAmB,CAAA;IACnB,gCAAmB,CAAA;IACnB,sCAAyB,CAAA;IACzB,gCAAmB,CAAA;IACnB,0BAAa,CAAA;IACb,6DAA6D;IAC7D,4EAA4E;AAC9E,CAAC,EAVW,SAAS,GAAT,iBAAS,KAAT,iBAAS,QAUpB;AAED,gDAAgD;AAChD,MAAM,UAAU,GAAgB,MAAM,CAAC,IAAI,CAAC,SAAS,CAAC,CAAC,GAAG,CAAY,CAAC,GAAG,EAAE,EAAE,CAAC,cAAc,CAAC,GAAG,CAAC,CAAC,CAAC;AAEpG;;;GAGG;AACH,SAAgB,2BAA2B,CAAC,IAAY;IACtD,QAAQ,IAAI,CAAC,WAAW,EAAE,EAAE;QAC1B,KAAK,UAAU;YACb,OAAO,SAAS,CAAC,I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,CAAC,UAAU;YACvB,OAAO,SAAS,CAAC,UAAU,CAAC;QAC9B,KAAK,SAAS,CAAC,OAAO;YACpB,OAAO,SAAS,CAAC,OAAO,CAAC;QAC3B,KAAK,SAAS,CAAC,IAAI;YACjB,OAAO,SAAS,CAAC,IAAI,CAAC;QACxB;YACE,OAAO,SAAS,CAAC;KACpB;AACH,CAAC;AAjBD,kCAiBC"}
+49
View File
@@ -0,0 +1,49 @@
export declare class ManifestValidationDetails {
adminInstallOnly?: boolean;
capabilities?: object;
defaultLocale?: string;
description?: string;
displayName?: string;
hosts?: string[];
iconUrl?: string;
localizedDescriptions?: object;
localizedIconUrls?: object;
localizedRootSourceUrls?: object;
productId?: string;
providerName?: string;
requirements?: string;
rootSourceUrl?: string;
subtype?: string;
supportedLanguages?: string[];
supportedProducts?: ManifestValidationProduct[];
type?: string;
version?: string;
}
export declare class ManifestValidationIssue {
code?: string;
column?: number;
line?: number;
title?: string;
content?: string;
helpUrl?: string;
}
export declare class ManifestValidationProduct {
code?: string;
title?: string;
version?: string;
}
export declare class ManifestValidationReport {
status?: string;
errors?: ManifestValidationIssue[];
warnings?: ManifestValidationIssue[];
notes?: ManifestValidationIssue[];
addInDetails?: ManifestValidationDetails;
}
export declare class ManifestValidation {
isValid: boolean;
report?: ManifestValidationReport;
status?: number;
statusText?: string;
constructor();
}
export declare function validateManifest(manifestPath: string, verifyProduction?: boolean): Promise<ManifestValidation>;
+113
View File
@@ -0,0 +1,113 @@
"use strict";
// 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());
});
};
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
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 = __importDefault(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
+1
View File
@@ -0,0 +1 @@
{"version":3,"file":"validate.js","sourceRoot":"","sources":["../src/validate.ts"],"names":[],"mappings":";AAAA,4DAA4D;AAC5D,kCAAkC;;;;;;;;;;;;;;;AAElC,2BAAsC;AACtC,8DAAqE;AACrE,4DAA+B;AAC/B,6DAA2D;AAC3D,yCAA6C;AAE7C,MAAa,yBAAyB;CAoBrC;AApBD,8DAoBC;AAED,MAAa,uBAAuB;CAOnC;AAPD,0DAOC;AAED,MAAa,yBAAyB;CAIrC;AAJD,8DAIC;AAED,MAAa,wBAAwB;CAMpC;AAND,4DAMC;AAED,MAAa,kBAAkB;IAM7B;QACE,IAAI,CAAC,OAAO,GAAG,KAAK,CAAC;IACvB,CAAC;CACF;AATD,gDASC;AAED,SAAsB,gBAAgB,CACpC,YAAoB,EACpB,mBAA4B,KAAK;;QAEjC,IAAI;YACF,MAAM,UAAU,GAAuB,IAAI,kBAAkB,EAAE,CAAC;YAEhE,0DAA0D;YAC1D,MAAM,wCAAmB,CAAC,gBAAgB,CAAC,YAAY,CAAC,CAAC;YAEzD,IAAI,YAAY,CAAC,QAAQ,CAAC,OAAO,CAAC,EAAE;gBAClC,MAAM,QAAQ,GAAgC,MAAM,6BAAY,CAAC,YAAY,CAAC,YAAY,CAAC,CAAC;gBAC5F,MAAM,gBAAgB,GAAa,MAAM,6BAAY,CAAC,gBAAgB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C,UAAU,CAAC;gBAE5C,MAAM,IAAI,GAAG,MAAM,QAAQ,CAAC,IAAI,EAAE,CAAC;gBAEnC,IAAI;oBACF,MAAM,IAAI,GAAG,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,IAAI,EAAE,CAAC,CAAC;oBACrC,IAAI,IAAI,EAAE;wBACR,UAAU,CAAC,MAAM,GAAG,IAAI,CAAC;qBAC1B;iBACF;gBAAC,WAAM,GAAE,CAAC,+BAA+B;gBAE1C,IAAI,UAAU,CAAC,MAAM,EAAE;oBACrB,MAAM,MAAM,GAAG,UAAU,CAAC,MAAM,CAAC,MAAM,CAAC;oBAExC,IAAI,MAAM,EAAE;wBACV,QAAQ,MAAM,CAAC,WAAW,EAAE,EAAE;4BAC5B,KAAK,UAAU;gCACb,UAAU,CAAC,OAAO,GAAG,IAAI,CAAC;gCAC1B,MAAM;yBACT;qBACF;iBACF;aACF;YACD,OAAO,UAAU,CAAC;SACnB;QAAC,OAAO,GAAQ,EAAE;YACjB,0BAAe,CAAC,eAAe,CAAC,oBAAoB,EAAE,GAAG,CAAC,CAAC;YAC3D,MAAM,GAAG,CAAC;SACX;IACH,CAAC;CAAA;AA7ED,4CA6EC"}
+94
View File
@@ -0,0 +1,94 @@
export type Xml = any;
/**
* Given an xml element, returns the value of the attribute with the specified name.
* @param xml Xml object
* @param name Attribute name
* @returns The attribute value or undefined
* @example Given the the following xml, the attribute name "DefaultValue" will return the value "abc".
* <First DefaultValue="abc">1</First>
*/
export declare function getXmlAttributeValue(xml: Xml, name: string): string | undefined;
/**
* Given an xml object, returns the first inner element with the specified name, or undefined.
* @param xml Xml object
* @param name Element name
* @returns Xml object or undefined
* @example Given the the following xml, the name "Second" will return the xml object for <Second>...</Second>.
* <Current>
* <First>1</First>
* <Second>2</Second>
* </Current>
*/
export declare function getXmlElement(xml: Xml, name: string): Xml | undefined;
/**
* Given an xml object, returns the attribute value for the first inner element with the specified name, or undefined.
* @param xml Xml object
* @param elementName Element name
* @param attributeName Attribute name
* @example Given the the following xml, the element name "First" and attribute name "DefaultValue" will return the value "abc".
* <Current>
* <First DefaultValue="abc">1</First>
* </Current>
*/
export declare function getXmlElementAttributeValue(xml: Xml, elementName: string, attributeName?: string): string | undefined;
/**
* Given an xml object, returns an array with the inner elements with the specified name.
* @param xml Xml object
* @param name Element name
* @returns Array of xml objects;
* @example Given the the following xml, the name "Item" will return an array with the two items.
* <Items>
* <Item>1</Item>
* <Item>2</Item>
* </Items>
*/
export declare function getXmlElements(xml: Xml, name: string): Xml[];
/**
* Given an xml object, for the specified element, returns the values of the inner elements with the specified item element name.
* @param xml The xml object.
* @param name The name of the inner xml element.
* @example Given the the following xml, the container name "Items" and item name "Item" will return ["One", "Two"].
* If the attributeName is "AnotherValue", then it will return ["First", "Second"].
* <Items>
* <Item DefaultValue="One" AnotherValue="First">1</Item>
* <Item DefaultValue="Two" AnotherValue="Second">2</Item>
* </Current>
*/
export declare function getXmlElementsAttributeValue(xml: Xml, name: string, itemElementName: string, attributeName?: string): string[];
/**
* Given an xml object, for the specified element, returns the values of the inner elements with the specified item element name.
* @param xml The xml object.
* @param name The name of the inner xml element.
* @example Given the the following xml, the container name "Items" and item name "Item" will return ["1", "2"].
* <Items>
* <Item>1</Item>
* <Item>2</Item>
* </Current>
*/
export declare function getXmlElementsValue(xml: Xml, name: string, itemElementName: string): string[];
/**
* Returns the value of the first inner xml element with the specified name.
* @param xml The xml object.
* @param name The name of the inner xml element.
* @example Given the the following xml, the name "Second" will return the value "2".
* <Current>
* <First>1</First>
* <Second>2</Second>
* </Current>
*/
export declare function getXmlElementValue(xml: Xml, name: string): string | undefined;
/**
* Given an xml object, set the attribute value for the specified element name.
* @param xml Xml object
* @param elementName Element name
* @param attributeValue Attribute value
* @param attributeName Attribute name
*/
export declare function setXmlElementAttributeValue(xml: Xml, elementName: string, attributeValue: string | undefined, attributeName?: string): void;
/**
* Given an xml object, set the inner xml element
* @param xml Xml object
* @param elementName Element name
* @param elementValue Element value
*/
export declare function setXmlElementValue(xml: Xml, elementName: string, elementValue: any): void;
+179
View File
@@ -0,0 +1,179 @@
"use strict";
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT license.
Object.defineProperty(exports, "__esModule", { value: true });
exports.setXmlElementValue = exports.setXmlElementAttributeValue = exports.getXmlElementValue = exports.getXmlElementsValue = exports.getXmlElementsAttributeValue = exports.getXmlElements = exports.getXmlElementAttributeValue = exports.getXmlElement = exports.getXmlAttributeValue = void 0;
/**
* Given an xml element, returns the value of the attribute with the specified name.
* @param xml Xml object
* @param name Attribute name
* @returns The attribute value or undefined
* @example Given the the following xml, the attribute name "DefaultValue" will return the value "abc".
* <First DefaultValue="abc">1</First>
*/
function getXmlAttributeValue(xml, name) {
try {
return xml.$[name];
}
catch (_a) {
// reading xml values is resilient to errors but you can uncomment the next line for debugging if attributes are missing
// console.error(`Unable to get xml attribute value "${name}". ${err}`);
}
}
exports.getXmlAttributeValue = getXmlAttributeValue;
/**
* Given an xml object, returns the first inner element with the specified name, or undefined.
* @param xml Xml object
* @param name Element name
* @returns Xml object or undefined
* @example Given the the following xml, the name "Second" will return the xml object for <Second>...</Second>.
* <Current>
* <First>1</First>
* <Second>2</Second>
* </Current>
*/
function getXmlElement(xml, name) {
try {
const element = xml[name];
if (element instanceof Array) {
return element[0];
}
}
catch (_a) {
// reading xml values is resilient to errors but you can uncomment the next line for debugging if elements are missing
// console.error(`Unable to get xml element "${name}". ${err}`);
}
}
exports.getXmlElement = getXmlElement;
/**
* Given an xml object, returns the attribute value for the first inner element with the specified name, or undefined.
* @param xml Xml object
* @param elementName Element name
* @param attributeName Attribute name
* @example Given the the following xml, the element name "First" and attribute name "DefaultValue" will return the value "abc".
* <Current>
* <First DefaultValue="abc">1</First>
* </Current>
*/
function getXmlElementAttributeValue(xml, elementName, attributeName = "DefaultValue") {
const element = getXmlElement(xml, elementName);
if (element) {
return getXmlAttributeValue(element, attributeName);
}
}
exports.getXmlElementAttributeValue = getXmlElementAttributeValue;
/**
* Given an xml object, returns an array with the inner elements with the specified name.
* @param xml Xml object
* @param name Element name
* @returns Array of xml objects;
* @example Given the the following xml, the name "Item" will return an array with the two items.
* <Items>
* <Item>1</Item>
* <Item>2</Item>
* </Items>
*/
function getXmlElements(xml, name) {
try {
const elements = xml[name];
return elements instanceof Array ? elements : [];
}
catch (_a) {
return [];
}
}
exports.getXmlElements = getXmlElements;
/**
* Given an xml object, for the specified element, returns the values of the inner elements with the specified item element name.
* @param xml The xml object.
* @param name The name of the inner xml element.
* @example Given the the following xml, the container name "Items" and item name "Item" will return ["One", "Two"].
* If the attributeName is "AnotherValue", then it will return ["First", "Second"].
* <Items>
* <Item DefaultValue="One" AnotherValue="First">1</Item>
* <Item DefaultValue="Two" AnotherValue="Second">2</Item>
* </Current>
*/
function getXmlElementsAttributeValue(xml, name, itemElementName, attributeName = "DefaultValue") {
const values = [];
try {
const xmlElements = xml[name][0][itemElementName];
xmlElements.forEach((xmlElement) => {
const elementValue = getXmlAttributeValue(xmlElement, attributeName);
if (elementValue !== undefined) {
values.push(elementValue);
}
});
}
catch (_a) {
// do nothing
}
return values;
}
exports.getXmlElementsAttributeValue = getXmlElementsAttributeValue;
/**
* Given an xml object, for the specified element, returns the values of the inner elements with the specified item element name.
* @param xml The xml object.
* @param name The name of the inner xml element.
* @example Given the the following xml, the container name "Items" and item name "Item" will return ["1", "2"].
* <Items>
* <Item>1</Item>
* <Item>2</Item>
* </Current>
*/
function getXmlElementsValue(xml, name, itemElementName) {
const values = [];
getXmlElements(xml, name).forEach((xmlElement) => {
const elementValue = getXmlElementValue(xmlElement, itemElementName);
if (elementValue !== undefined) {
values.push(elementValue);
}
});
return values;
}
exports.getXmlElementsValue = getXmlElementsValue;
/**
* Returns the value of the first inner xml element with the specified name.
* @param xml The xml object.
* @param name The name of the inner xml element.
* @example Given the the following xml, the name "Second" will return the value "2".
* <Current>
* <First>1</First>
* <Second>2</Second>
* </Current>
*/
function getXmlElementValue(xml, name) {
try {
const element = xml[name];
if (element instanceof Array) {
return element[0];
}
}
catch (_a) {
// reading xml values is resilient to errors but you can uncomment the next line for debugging if elements are missing
// console.error(`Unable to get xml element value "${name}". ${err}`);
}
}
exports.getXmlElementValue = getXmlElementValue;
/**
* Given an xml object, set the attribute value for the specified element name.
* @param xml Xml object
* @param elementName Element name
* @param attributeValue Attribute value
* @param attributeName Attribute name
*/
function setXmlElementAttributeValue(xml, elementName, attributeValue, attributeName = "DefaultValue") {
xml[elementName][0].$[attributeName] = attributeValue;
}
exports.setXmlElementAttributeValue = setXmlElementAttributeValue;
/**
* Given an xml object, set the inner xml element
* @param xml Xml object
* @param elementName Element name
* @param elementValue Element value
*/
function setXmlElementValue(xml, elementName, elementValue) {
xml[elementName] = elementValue;
}
exports.setXmlElementValue = setXmlElementValue;
//# sourceMappingURL=xml.js.map
+1
View File
@@ -0,0 +1 @@
{"version":3,"file":"xml.js","sourceRoot":"","sources":["../src/xml.ts"],"names":[],"mappings":";AAAA,4DAA4D;AAC5D,kCAAkC;;;AAIlC;;;;;;;GAOG;AACH,SAAgB,oBAAoB,CAAC,GAAQ,EAAE,IAAY;IACzD,IAAI;QACF,OAAO,GAAG,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC;KACpB;IAAC,WAAM;QACN,wHAAwH;QACxH,wEAAwE;KACzE;AACH,CAAC;AAPD,oDAOC;AAED;;;;;;;;;;GAUG;AACH,SAAgB,aAAa,CAAC,GAAQ,EAAE,IAAY;IAClD,IAAI;QACF,MAAM,OAAO,GAAG,GAAG,CAAC,IAAI,CAAC,CAAC;QAE1B,IAAI,OAAO,YAAY,KAAK,EAAE;YAC5B,OAAO,OAAO,CAAC,CAAC,CAAC,CAAC;SACnB;KACF;IAAC,WAAM;QACN,sHAAsH;QACtH,gEAAgE;KACjE;AACH,CAAC;AAXD,sCAWC;AAED;;;;;;;;;GASG;AACH,SAAgB,2BAA2B,CACzC,GAAQ,EACR,WAAmB,EACnB,gBAAwB,cAAc;IAEtC,MAAM,OAAO,GAAQ,aA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