@pnp/sp
Version:
pnp - provides a fluent api for working with SharePoint REST
122 lines • 4.88 kB
JavaScript
import { __decorate } from "tslib";
import { _SPCollection, spInvokableFactory, _SPInstance, SPCollection, } from "../spqueryable.js";
import { spPost } from "../operations.js";
import { odataUrlFrom } from "../utils/odata-url-from.js";
import { extractWebUrl } from "../utils/extract-web-url.js";
import { File } from "../files/types.js";
import { combine } from "@pnp/core";
import { defaultPath } from "../decorators.js";
let _AppCatalog = class _AppCatalog extends _SPCollection {
constructor(base, path) {
super(base, null);
this._url = combine(extractWebUrl(this._url), path);
}
/**
* Get details of specific app from the app catalog
* @param id - Specify the guid of the app
*/
getAppById(id) {
return App(this, `getById('${id}')`);
}
/**
* Synchronize a solution to the Microsoft Teams App Catalog
* @param id - Specify the guid of the app
* @param useSharePointItemId (optional) - By default this REST call requires the SP Item id of the app, not the app id.
* PnPjs will try to fetch the item id by default, you can still use this parameter to pass your own item id in the first parameter
*/
async syncSolutionToTeams(id, useSharePointItemId = false) {
// This REST call requires that you refer the list item id of the solution in the app catalog site.
let appId = null;
const webUrl = extractWebUrl(this.toUrl()) + "_api/web";
if (useSharePointItemId) {
appId = id;
}
else {
const listId = (await SPCollection([this, webUrl], "lists").select("Id").filter("EntityTypeName eq 'AppCatalog'")())[0].Id;
const listItems = await SPCollection([this, webUrl], `lists/getById('${listId}')/items`).select("Id").filter(`AppProductID eq '${id}'`).top(1)();
if (listItems && listItems.length > 0) {
appId = listItems[0].Id;
}
else {
throw Error(`Did not find the app with id ${id} in the appcatalog.`);
}
}
const poster = AppCatalog([this, webUrl], `/tenantappcatalog/SyncSolutionToTeams(id=${appId})`);
return await spPost(poster);
}
/**
* Uploads an app package. Not supported for batching
*
* @param filename Filename to create.
* @param content app package data (eg: the .app or .sppkg file).
* @param shouldOverWrite Should an app with the same name in the same location be overwritten? (default: true)
* @returns Promise<IAppAddResult>
*/
async add(filename, content, shouldOverWrite = true) {
// you don't add to the availableapps collection
const adder = AppCatalog([this, extractWebUrl(this.toUrl())], `_api/web/tenantappcatalog/add(overwrite=${shouldOverWrite},url='${filename}')`);
const r = await spPost(adder, {
body: content, headers: {
"binaryStringRequestBody": "true",
},
});
return {
data: r,
file: File([this, odataUrlFrom(r)]),
};
}
};
_AppCatalog = __decorate([
defaultPath("_api/web/tenantappcatalog/AvailableApps")
], _AppCatalog);
export { _AppCatalog };
export const AppCatalog = spInvokableFactory(_AppCatalog);
export class _App extends _SPInstance {
/**
* This method deploys an app on the app catalog. It must be called in the context
* of the tenant app catalog web or it will fail.
*
* @param skipFeatureDeployment Deploy the app to the entire tenant
*/
deploy(skipFeatureDeployment = false) {
return this.do(`Deploy(${skipFeatureDeployment})`);
}
/**
* This method retracts a deployed app on the app catalog. It must be called in the context
* of the tenant app catalog web or it will fail.
*/
retract() {
return this.do("Retract");
}
/**
* This method allows an app which is already deployed to be installed on a web
*/
install() {
return this.do("Install");
}
/**
* This method allows an app which is already installed to be uninstalled on a web
* Note: when you use the REST API to uninstall a solution package from the site, it is not relocated to the recycle bin
*/
uninstall() {
return this.do("Uninstall");
}
/**
* This method allows an app which is already installed to be upgraded on a web
*/
upgrade() {
return this.do("Upgrade");
}
/**
* This method removes an app from the app catalog. It must be called in the context
* of the tenant app catalog web or it will fail.
*/
remove() {
return this.do("Remove");
}
do(path) {
return spPost(App(this, path));
}
}
export const App = spInvokableFactory(_App);
//# sourceMappingURL=types.js.map