1 | import { __decorate } from "tslib";
|
2 | import { _SPCollection, spInvokableFactory, _SPInstance, SPCollection, } from "../spqueryable.js";
|
3 | import { spPost } from "../operations.js";
|
4 | import { odataUrlFrom } from "../utils/odata-url-from.js";
|
5 | import { extractWebUrl } from "../utils/extract-web-url.js";
|
6 | import { File } from "../files/types.js";
|
7 | import { combine } from "@pnp/core";
|
8 | import { defaultPath } from "../decorators.js";
|
9 | function getAppCatalogPath(base, path) {
|
10 | const paths = ["_api/web/tenantappcatalog/", "_api/web/sitecollectionappcatalog/"];
|
11 | for (let i = 0; i < paths.length; i++) {
|
12 | const index = base.indexOf(paths[i]);
|
13 | if (index > -1) {
|
14 | return combine(base.substring(index, index + paths[i].length), path);
|
15 | }
|
16 | }
|
17 | return combine(base, path);
|
18 | }
|
19 | let _AppCatalog = class _AppCatalog extends _SPCollection {
|
20 | constructor(base, path) {
|
21 | super(base, null);
|
22 | this._url = combine(extractWebUrl(this._url), path);
|
23 | }
|
24 | |
25 |
|
26 |
|
27 |
|
28 | getAppById(id) {
|
29 | return App(this, `getById('${id}')`);
|
30 | }
|
31 | |
32 |
|
33 |
|
34 |
|
35 |
|
36 |
|
37 | async syncSolutionToTeams(id, useSharePointItemId = false) {
|
38 |
|
39 | let appId = null;
|
40 | const webUrl = combine(extractWebUrl(this.toUrl()), "_api/web");
|
41 | if (useSharePointItemId) {
|
42 | appId = id;
|
43 | }
|
44 | else {
|
45 | const listId = (await SPCollection([this, webUrl], "lists").select("Id").filter("EntityTypeName eq 'AppCatalog'")())[0].Id;
|
46 | const listItems = await SPCollection([this, webUrl], `lists/getById('${listId}')/items`).select("Id").filter(`AppProductID eq '${id}'`).top(1)();
|
47 | if (listItems && listItems.length > 0) {
|
48 | appId = listItems[0].Id;
|
49 | }
|
50 | else {
|
51 | throw Error(`Did not find the app with id ${id} in the appcatalog.`);
|
52 | }
|
53 | }
|
54 | return spPost(AppCatalog(this, getAppCatalogPath(this.toUrl(), `SyncSolutionToTeams(id=${appId})`)));
|
55 | }
|
56 | |
57 |
|
58 |
|
59 |
|
60 |
|
61 |
|
62 |
|
63 |
|
64 | async add(filename, content, shouldOverWrite = true) {
|
65 |
|
66 | const adder = AppCatalog(this, getAppCatalogPath(this.toUrl(), `add(overwrite=${shouldOverWrite},url='${filename}')`));
|
67 | const r = await spPost(adder, {
|
68 | body: content, headers: {
|
69 | "binaryStringRequestBody": "true",
|
70 | },
|
71 | });
|
72 | return {
|
73 | data: r,
|
74 | file: File([this, odataUrlFrom(r)]),
|
75 | };
|
76 | }
|
77 | };
|
78 | _AppCatalog = __decorate([
|
79 | defaultPath("_api/web/tenantappcatalog/AvailableApps")
|
80 | ], _AppCatalog);
|
81 | export { _AppCatalog };
|
82 | export const AppCatalog = spInvokableFactory(_AppCatalog);
|
83 | export class _App extends _SPInstance {
|
84 | |
85 |
|
86 |
|
87 |
|
88 |
|
89 |
|
90 | deploy(skipFeatureDeployment = false) {
|
91 | return this.do(`Deploy(${skipFeatureDeployment})`);
|
92 | }
|
93 | |
94 |
|
95 |
|
96 |
|
97 | retract() {
|
98 | return this.do("Retract");
|
99 | }
|
100 | |
101 |
|
102 |
|
103 | install() {
|
104 | return this.do("Install");
|
105 | }
|
106 | |
107 |
|
108 |
|
109 |
|
110 | uninstall() {
|
111 | return this.do("Uninstall");
|
112 | }
|
113 | |
114 |
|
115 |
|
116 | upgrade() {
|
117 | return this.do("Upgrade");
|
118 | }
|
119 | |
120 |
|
121 |
|
122 |
|
123 | remove() {
|
124 | return this.do("Remove");
|
125 | }
|
126 | do(path) {
|
127 | return spPost(App(this, path));
|
128 | }
|
129 | }
|
130 | export const App = spInvokableFactory(_App);
|
131 |
|
\ | No newline at end of file |