UNPKG

4.88 kBJavaScriptView Raw
1import { __decorate } from "tslib";
2import { _SPCollection, spInvokableFactory, _SPInstance, SPCollection, } from "../spqueryable.js";
3import { spPost } from "../operations.js";
4import { odataUrlFrom } from "../utils/odata-url-from.js";
5import { extractWebUrl } from "../utils/extract-web-url.js";
6import { File } from "../files/types.js";
7import { combine } from "@pnp/core";
8import { defaultPath } from "../decorators.js";
9let _AppCatalog = class _AppCatalog extends _SPCollection {
10 constructor(base, path) {
11 super(base, null);
12 this._url = combine(extractWebUrl(this._url), path);
13 }
14 /**
15 * Get details of specific app from the app catalog
16 * @param id - Specify the guid of the app
17 */
18 getAppById(id) {
19 return App(this, `getById('${id}')`);
20 }
21 /**
22 * Synchronize a solution to the Microsoft Teams App Catalog
23 * @param id - Specify the guid of the app
24 * @param useSharePointItemId (optional) - By default this REST call requires the SP Item id of the app, not the app id.
25 * 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
26 */
27 async syncSolutionToTeams(id, useSharePointItemId = false) {
28 // This REST call requires that you refer the list item id of the solution in the app catalog site.
29 let appId = null;
30 const webUrl = extractWebUrl(this.toUrl()) + "_api/web";
31 if (useSharePointItemId) {
32 appId = id;
33 }
34 else {
35 const listId = (await SPCollection([this, webUrl], "lists").select("Id").filter("EntityTypeName eq 'AppCatalog'")())[0].Id;
36 const listItems = await SPCollection([this, webUrl], `lists/getById('${listId}')/items`).select("Id").filter(`AppProductID eq '${id}'`).top(1)();
37 if (listItems && listItems.length > 0) {
38 appId = listItems[0].Id;
39 }
40 else {
41 throw Error(`Did not find the app with id ${id} in the appcatalog.`);
42 }
43 }
44 const poster = AppCatalog([this, webUrl], `/tenantappcatalog/SyncSolutionToTeams(id=${appId})`);
45 return await spPost(poster);
46 }
47 /**
48 * Uploads an app package. Not supported for batching
49 *
50 * @param filename Filename to create.
51 * @param content app package data (eg: the .app or .sppkg file).
52 * @param shouldOverWrite Should an app with the same name in the same location be overwritten? (default: true)
53 * @returns Promise<IAppAddResult>
54 */
55 async add(filename, content, shouldOverWrite = true) {
56 // you don't add to the availableapps collection
57 const adder = AppCatalog([this, extractWebUrl(this.toUrl())], `_api/web/tenantappcatalog/add(overwrite=${shouldOverWrite},url='${filename}')`);
58 const r = await spPost(adder, {
59 body: content, headers: {
60 "binaryStringRequestBody": "true",
61 },
62 });
63 return {
64 data: r,
65 file: File([this, odataUrlFrom(r)]),
66 };
67 }
68};
69_AppCatalog = __decorate([
70 defaultPath("_api/web/tenantappcatalog/AvailableApps")
71], _AppCatalog);
72export { _AppCatalog };
73export const AppCatalog = spInvokableFactory(_AppCatalog);
74export class _App extends _SPInstance {
75 /**
76 * This method deploys an app on the app catalog. It must be called in the context
77 * of the tenant app catalog web or it will fail.
78 *
79 * @param skipFeatureDeployment Deploy the app to the entire tenant
80 */
81 deploy(skipFeatureDeployment = false) {
82 return this.do(`Deploy(${skipFeatureDeployment})`);
83 }
84 /**
85 * This method retracts a deployed app on the app catalog. It must be called in the context
86 * of the tenant app catalog web or it will fail.
87 */
88 retract() {
89 return this.do("Retract");
90 }
91 /**
92 * This method allows an app which is already deployed to be installed on a web
93 */
94 install() {
95 return this.do("Install");
96 }
97 /**
98 * This method allows an app which is already installed to be uninstalled on a web
99 * Note: when you use the REST API to uninstall a solution package from the site, it is not relocated to the recycle bin
100 */
101 uninstall() {
102 return this.do("Uninstall");
103 }
104 /**
105 * This method allows an app which is already installed to be upgraded on a web
106 */
107 upgrade() {
108 return this.do("Upgrade");
109 }
110 /**
111 * This method removes an app from the app catalog. It must be called in the context
112 * of the tenant app catalog web or it will fail.
113 */
114 remove() {
115 return this.do("Remove");
116 }
117 do(path) {
118 return spPost(App(this, path));
119 }
120}
121export const App = spInvokableFactory(_App);
122//# sourceMappingURL=types.js.map
\No newline at end of file