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