UNPKG

4.84 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 return spPost(AppCatalog([this, webUrl], `/tenantappcatalog/SyncSolutionToTeams(id=${appId})`));
45 }
46 /**
47 * Uploads an app package. Not supported for batching
48 *
49 * @param filename Filename to create.
50 * @param content app package data (eg: the .app or .sppkg file).
51 * @param shouldOverWrite Should an app with the same name in the same location be overwritten? (default: true)
52 * @returns Promise<IAppAddResult>
53 */
54 async add(filename, content, shouldOverWrite = true) {
55 // you don't add to the availableapps collection
56 const adder = AppCatalog([this, extractWebUrl(this.toUrl())], `_api/web/tenantappcatalog/add(overwrite=${shouldOverWrite},url='${filename}')`);
57 const r = await spPost(adder, {
58 body: content, headers: {
59 "binaryStringRequestBody": "true",
60 },
61 });
62 return {
63 data: r,
64 file: File([this, odataUrlFrom(r)]),
65 };
66 }
67};
68_AppCatalog = __decorate([
69 defaultPath("_api/web/tenantappcatalog/AvailableApps")
70], _AppCatalog);
71export { _AppCatalog };
72export const AppCatalog = spInvokableFactory(_AppCatalog);
73export class _App extends _SPInstance {
74 /**
75 * This method deploys an app on the app catalog. It must be called in the context
76 * of the tenant app catalog web or it will fail.
77 *
78 * @param skipFeatureDeployment Deploy the app to the entire tenant
79 */
80 deploy(skipFeatureDeployment = false) {
81 return this.do(`Deploy(${skipFeatureDeployment})`);
82 }
83 /**
84 * This method retracts a deployed app on the app catalog. It must be called in the context
85 * of the tenant app catalog web or it will fail.
86 */
87 retract() {
88 return this.do("Retract");
89 }
90 /**
91 * This method allows an app which is already deployed to be installed on a web
92 */
93 install() {
94 return this.do("Install");
95 }
96 /**
97 * This method allows an app which is already installed to be uninstalled on a web
98 * Note: when you use the REST API to uninstall a solution package from the site, it is not relocated to the recycle bin
99 */
100 uninstall() {
101 return this.do("Uninstall");
102 }
103 /**
104 * This method allows an app which is already installed to be upgraded on a web
105 */
106 upgrade() {
107 return this.do("Upgrade");
108 }
109 /**
110 * This method removes an app from the app catalog. It must be called in the context
111 * of the tenant app catalog web or it will fail.
112 */
113 remove() {
114 return this.do("Remove");
115 }
116 do(path) {
117 return spPost(App(this, path));
118 }
119}
120export const App = spInvokableFactory(_App);
121//# sourceMappingURL=types.js.map
\No newline at end of file