1 | import { __decorate } from "tslib";
|
2 | import { _SPInstance, spInvokableFactory } from "../spqueryable.js";
|
3 | import { defaultPath } from "../decorators.js";
|
4 | import { Web } from "../webs/types.js";
|
5 | import { combine, hOP, isArray } from "@pnp/core";
|
6 | import { body, TextParse } from "@pnp/queryable";
|
7 | import { odataUrlFrom } from "../utils/odata-url-from.js";
|
8 | import { spPost } from "../operations.js";
|
9 | import { escapeQueryStrValue } from "../utils/escape-query-str.js";
|
10 | import { extractWebUrl } from "../utils/extract-web-url.js";
|
11 | import { emptyGuid } from "../types.js";
|
12 |
|
13 |
|
14 |
|
15 |
|
16 |
|
17 |
|
18 | function rebaseSiteUrl(candidate, path) {
|
19 | let replace = "_api/site";
|
20 |
|
21 |
|
22 |
|
23 |
|
24 | const matches = /(_api[/|\\](site|web))/i.exec(candidate);
|
25 | if ((matches === null || matches === void 0 ? void 0 : matches.length) > 0) {
|
26 |
|
27 | candidate = extractWebUrl(candidate);
|
28 |
|
29 | replace = matches[1];
|
30 | }
|
31 |
|
32 | if ((path === null || path === void 0 ? void 0 : path.indexOf("_api")) < 0) {
|
33 | candidate = combine(candidate, replace);
|
34 | }
|
35 | return candidate;
|
36 | }
|
37 | let _Site = class _Site extends _SPInstance {
|
38 | constructor(base, path) {
|
39 | if (typeof base === "string") {
|
40 | base = rebaseSiteUrl(base, path);
|
41 | }
|
42 | else if (isArray(base)) {
|
43 | base = [base[0], rebaseSiteUrl(base[1], path)];
|
44 | }
|
45 | else {
|
46 | base = [base, rebaseSiteUrl(base.toUrl(), path)];
|
47 | }
|
48 | super(base, path);
|
49 | }
|
50 | |
51 |
|
52 |
|
53 |
|
54 | get rootWeb() {
|
55 | return Web(this, "rootweb");
|
56 | }
|
57 | |
58 |
|
59 |
|
60 |
|
61 |
|
62 | getChanges(query) {
|
63 | const postBody = body({ query });
|
64 | return spPost(Web(this, "getchanges"), postBody);
|
65 | }
|
66 | |
67 |
|
68 |
|
69 |
|
70 |
|
71 | async openWebById(webId) {
|
72 | const data = await spPost(Site(this, `openWebById('${webId}')`));
|
73 | return {
|
74 | data,
|
75 | web: Web([this, extractWebUrl(odataUrlFrom(data))]),
|
76 | };
|
77 | }
|
78 | |
79 |
|
80 |
|
81 |
|
82 | async getRootWeb() {
|
83 | const web = await this.rootWeb.select("Url")();
|
84 | return Web([this, web.Url]);
|
85 | }
|
86 | |
87 |
|
88 |
|
89 | async getContextInfo() {
|
90 | const data = await spPost(Site([this, this.parentUrl], "_api/contextinfo"));
|
91 | if (hOP(data, "GetContextWebInformation")) {
|
92 | const info = data.GetContextWebInformation;
|
93 | info.SupportedSchemaVersions = info.SupportedSchemaVersions.results;
|
94 | return info;
|
95 | }
|
96 | else {
|
97 | return data;
|
98 | }
|
99 | }
|
100 | |
101 |
|
102 |
|
103 |
|
104 | async delete() {
|
105 | const site = await Site(this, "").select("Id")();
|
106 | const q = Site([this, this.parentUrl], "_api/SPSiteManager/Delete");
|
107 | await spPost(q, body({ siteId: site.Id }));
|
108 | }
|
109 | |
110 |
|
111 |
|
112 |
|
113 |
|
114 | async getDocumentLibraries(absoluteWebUrl) {
|
115 | const q = Site([this, this.parentUrl], "_api/sp.web.getdocumentlibraries(@v)");
|
116 | q.query.set("@v", `'${escapeQueryStrValue(absoluteWebUrl)}'`);
|
117 | const data = await q();
|
118 | return hOP(data, "GetDocumentLibraries") ? data.GetDocumentLibraries : data;
|
119 | }
|
120 | |
121 |
|
122 |
|
123 |
|
124 |
|
125 | async getWebUrlFromPageUrl(absolutePageUrl) {
|
126 | const q = Site([this, this.parentUrl], "_api/sp.web.getweburlfrompageurl(@v)");
|
127 | q.query.set("@v", `'${escapeQueryStrValue(absolutePageUrl)}'`);
|
128 | const data = await q();
|
129 | return hOP(data, "GetWebUrlFromPageUrl") ? data.GetWebUrlFromPageUrl : data;
|
130 | }
|
131 | |
132 |
|
133 |
|
134 |
|
135 |
|
136 |
|
137 |
|
138 |
|
139 |
|
140 |
|
141 |
|
142 |
|
143 |
|
144 |
|
145 |
|
146 |
|
147 |
|
148 | async createCommunicationSite(title, lcid = 1033, shareByEmailEnabled = false, url, description, classification, siteDesignId, hubSiteId, owner) {
|
149 | return this.createCommunicationSiteFromProps({
|
150 | Classification: classification,
|
151 | Description: description,
|
152 | HubSiteId: hubSiteId,
|
153 | Lcid: lcid,
|
154 | Owner: owner,
|
155 | ShareByEmailEnabled: shareByEmailEnabled,
|
156 | SiteDesignId: siteDesignId,
|
157 | Title: title,
|
158 | Url: url,
|
159 | });
|
160 | }
|
161 | async createCommunicationSiteFromProps(props) {
|
162 |
|
163 | const request = {
|
164 | Classification: "",
|
165 | Description: "",
|
166 | HubSiteId: emptyGuid,
|
167 | Lcid: 1033,
|
168 | ShareByEmailEnabled: false,
|
169 | SiteDesignId: emptyGuid,
|
170 | WebTemplate: "SITEPAGEPUBLISHING#0",
|
171 | WebTemplateExtensionId: emptyGuid,
|
172 | ...props,
|
173 | };
|
174 | return spPost(Site([this, extractWebUrl(this.toUrl())], "/_api/SPSiteManager/Create"), body({ request }));
|
175 | }
|
176 | |
177 |
|
178 |
|
179 |
|
180 | async exists(url) {
|
181 | return spPost(Site([this, extractWebUrl(this.toUrl())], "/_api/SP.Site.Exists"), body({ url }));
|
182 | }
|
183 | |
184 |
|
185 |
|
186 |
|
187 |
|
188 |
|
189 |
|
190 |
|
191 |
|
192 |
|
193 |
|
194 | async createModernTeamSite(displayName, alias, isPublic, lcid, description, classification, owners, hubSiteId, siteDesignId) {
|
195 | return this.createModernTeamSiteFromProps({
|
196 | alias,
|
197 | classification,
|
198 | description,
|
199 | displayName,
|
200 | hubSiteId,
|
201 | isPublic,
|
202 | lcid,
|
203 | owners,
|
204 | siteDesignId,
|
205 | });
|
206 | }
|
207 | async createModernTeamSiteFromProps(props) {
|
208 |
|
209 | const p = Object.assign({}, {
|
210 | classification: "",
|
211 | description: "",
|
212 | hubSiteId: emptyGuid,
|
213 | isPublic: true,
|
214 | lcid: 1033,
|
215 | owners: [],
|
216 | }, props);
|
217 | const postBody = {
|
218 | alias: p.alias,
|
219 | displayName: p.displayName,
|
220 | isPublic: p.isPublic,
|
221 | optionalParams: {
|
222 | Classification: p.classification,
|
223 | CreationOptions: [`SPSiteLanguage:${p.lcid}`, `HubSiteId:${p.hubSiteId}`],
|
224 | Description: p.description,
|
225 | Owners: p.owners,
|
226 | },
|
227 | };
|
228 | if (p.siteDesignId) {
|
229 | postBody.optionalParams.CreationOptions.push(`implicit_formula_292aa8a00786498a87a5ca52d9f4214a_${p.siteDesignId}`);
|
230 | }
|
231 | return spPost(Site([this, extractWebUrl(this.toUrl())], "/_api/GroupSiteManager/CreateGroupEx").using(TextParse()), body(postBody));
|
232 | }
|
233 | };
|
234 | _Site = __decorate([
|
235 | defaultPath("_api/site")
|
236 | ], _Site);
|
237 | export { _Site };
|
238 | export const Site = spInvokableFactory(_Site);
|
239 |
|
\ | No newline at end of file |