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 | let _AppCatalog = class _AppCatalog extends _SPCollection {
|
10 | constructor(base, path) {
|
11 | super(base, null);
|
12 | this._url = combine(extractWebUrl(this._url), path);
|
13 | }
|
14 | |
15 |
|
16 |
|
17 |
|
18 | getAppById(id) {
|
19 | return App(this, `getById('${id}')`);
|
20 | }
|
21 | |
22 |
|
23 |
|
24 |
|
25 |
|
26 |
|
27 | async syncSolutionToTeams(id, useSharePointItemId = false) {
|
28 |
|
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 |
|
49 |
|
50 |
|
51 |
|
52 |
|
53 |
|
54 |
|
55 | async add(filename, content, shouldOverWrite = true) {
|
56 |
|
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);
|
72 | export { _AppCatalog };
|
73 | export const AppCatalog = spInvokableFactory(_AppCatalog);
|
74 | export class _App extends _SPInstance {
|
75 | |
76 |
|
77 |
|
78 |
|
79 |
|
80 |
|
81 | deploy(skipFeatureDeployment = false) {
|
82 | return this.do(`Deploy(${skipFeatureDeployment})`);
|
83 | }
|
84 | |
85 |
|
86 |
|
87 |
|
88 | retract() {
|
89 | return this.do("Retract");
|
90 | }
|
91 | |
92 |
|
93 |
|
94 | install() {
|
95 | return this.do("Install");
|
96 | }
|
97 | |
98 |
|
99 |
|
100 |
|
101 | uninstall() {
|
102 | return this.do("Uninstall");
|
103 | }
|
104 | |
105 |
|
106 |
|
107 | upgrade() {
|
108 | return this.do("Upgrade");
|
109 | }
|
110 | |
111 |
|
112 |
|
113 |
|
114 | remove() {
|
115 | return this.do("Remove");
|
116 | }
|
117 | do(path) {
|
118 | return spPost(App(this, path));
|
119 | }
|
120 | }
|
121 | export const App = spInvokableFactory(_App);
|
122 |
|
\ | No newline at end of file |