1 | import { __decorate } from "tslib";
|
2 | import { body } from "@pnp/queryable";
|
3 | import { _SPCollection, spInvokableFactory, _SPInstance, SPCollection, SPInstance, deleteable, } from "../spqueryable.js";
|
4 | import { defaultPath } from "../decorators.js";
|
5 | import { odataUrlFrom } from "../utils/odata-url-from.js";
|
6 | import { spPost, spPostMerge } from "../operations.js";
|
7 | import { escapeQueryStrValue } from "../utils/escape-query-str.js";
|
8 | import { extractWebUrl } from "../index.js";
|
9 | import { combine, isArray } from "@pnp/core";
|
10 | let _Webs = class _Webs extends _SPCollection {
|
11 | /**
|
12 | * Adds a new web to the collection
|
13 | *
|
14 | * @param title The new web's title
|
15 | * @param url The new web's relative url
|
16 | * @param description The new web's description
|
17 | * @param template The new web's template internal name (default = STS)
|
18 | * @param language The locale id that specifies the new web's language (default = 1033 [English, US])
|
19 | * @param inheritPermissions When true, permissions will be inherited from the new web's parent (default = true)
|
20 | */
|
21 | async add(Title, Url, Description = "", WebTemplate = "STS", Language = 1033, UseSamePermissionsAsParentSite = true) {
|
22 | const postBody = body({
|
23 | "parameters": {
|
24 | Description,
|
25 | Language,
|
26 | Title,
|
27 | Url,
|
28 | UseSamePermissionsAsParentSite,
|
29 | WebTemplate,
|
30 | },
|
31 | });
|
32 | const data = await spPost(Webs(this, "add"), postBody);
|
33 | return {
|
34 | data,
|
35 | web: Web([this, odataUrlFrom(data).replace(/_api\/web\/?/i, "")]),
|
36 | };
|
37 | }
|
38 | };
|
39 | _Webs = __decorate([
|
40 | defaultPath("webs")
|
41 | ], _Webs);
|
42 | export { _Webs };
|
43 | export const Webs = spInvokableFactory(_Webs);
|
44 | /**
|
45 | * Ensures the url passed to the constructor is correctly rebased to a web url
|
46 | *
|
47 | * @param candidate The candidate web url
|
48 | * @param path The caller supplied path, which may contain _api, meaning we don't append _api/web
|
49 | */
|
50 | function rebaseWebUrl(candidate, path) {
|
51 | let replace = "_api/web";
|
52 | // this allows us to both:
|
53 | // - test if `candidate` already has an api path
|
54 | // - ensure that we append the correct one as sometimes a web is not defined
|
55 | // by _api/web, in the case of _api/site/rootweb for example
|
56 | const matches = /(_api[/|\\](site|web))/i.exec(candidate);
|
57 | if ((matches === null || matches === void 0 ? void 0 : matches.length) > 0) {
|
58 | // we want just the base url part (before the _api)
|
59 | candidate = extractWebUrl(candidate);
|
60 | // we want to ensure we put back the correct string
|
61 | replace = matches[1];
|
62 | }
|
63 | // we only need to append the _api part IF `path` doesn't already include it.
|
64 | if ((path === null || path === void 0 ? void 0 : path.indexOf("_api")) < 0) {
|
65 | candidate = combine(candidate, replace);
|
66 | }
|
67 | return candidate;
|
68 | }
|
69 | /**
|
70 | * Describes a web
|
71 | *
|
72 | */
|
73 | let _Web = class _Web extends _SPInstance {
|
74 | constructor(base, path) {
|
75 | if (typeof base === "string") {
|
76 | base = rebaseWebUrl(base, path);
|
77 | }
|
78 | else if (isArray(base)) {
|
79 | base = [base[0], rebaseWebUrl(base[1], path)];
|
80 | }
|
81 | else {
|
82 | base = [base, rebaseWebUrl(base.toUrl(), path)];
|
83 | }
|
84 | super(base, path);
|
85 | this.delete = deleteable();
|
86 | }
|
87 | /**
|
88 | * Gets this web's subwebs
|
89 | *
|
90 | */
|
91 | get webs() {
|
92 | return Webs(this);
|
93 | }
|
94 | /**
|
95 | * Allows access to the web's all properties collection
|
96 | */
|
97 | get allProperties() {
|
98 | return SPInstance(this, "allproperties");
|
99 | }
|
100 | /**
|
101 | * Gets a collection of WebInfos for this web's subwebs
|
102 | *
|
103 | */
|
104 | get webinfos() {
|
105 | return SPCollection(this, "webinfos");
|
106 | }
|
107 | /**
|
108 | * Gets this web's parent web and data
|
109 | *
|
110 | */
|
111 | async getParentWeb() {
|
112 | const { Url, ParentWeb } = await this.select("Url", "ParentWeb/ServerRelativeUrl").expand("ParentWeb")();
|
113 | if (ParentWeb === null || ParentWeb === void 0 ? void 0 : ParentWeb.ServerRelativeUrl) {
|
114 | return Web([this, Url.substring(0, Url.indexOf(ParentWeb.ServerRelativeUrl) + ParentWeb.ServerRelativeUrl.length)]);
|
115 | }
|
116 | return null;
|
117 | }
|
118 | /**
|
119 | * Updates this web instance with the supplied properties
|
120 | *
|
121 | * @param properties A plain object hash of values to update for the web
|
122 | */
|
123 | async update(properties) {
|
124 | return spPostMerge(this, body(properties));
|
125 | }
|
126 | /**
|
127 | * Applies the theme specified by the contents of each of the files specified in the arguments to the site
|
128 | *
|
129 | * @param colorPaletteUrl The server-relative URL of the color palette file
|
130 | * @param fontSchemeUrl The server-relative URL of the font scheme
|
131 | * @param backgroundImageUrl The server-relative URL of the background image
|
132 | * @param shareGenerated When true, the generated theme files are stored in the root site. When false, they are stored in this web
|
133 | */
|
134 | applyTheme(colorPaletteUrl, fontSchemeUrl, backgroundImageUrl, shareGenerated) {
|
135 | const postBody = body({
|
136 | backgroundImageUrl,
|
137 | colorPaletteUrl,
|
138 | fontSchemeUrl,
|
139 | shareGenerated,
|
140 | });
|
141 | return spPost(Web(this, "applytheme"), postBody);
|
142 | }
|
143 | /**
|
144 | * Applies the specified site definition or site template to the Web site that has no template applied to it
|
145 | *
|
146 | * @param template Name of the site definition or the name of the site template
|
147 | */
|
148 | applyWebTemplate(template) {
|
149 | return spPost(Web(this, `applywebtemplate(webTemplate='${escapeQueryStrValue(template)}')`));
|
150 | }
|
151 | /**
|
152 | * Returns the collection of changes from the change log that have occurred within the list, based on the specified query
|
153 | *
|
154 | * @param query The change query
|
155 | */
|
156 | getChanges(query) {
|
157 | return spPost(Web(this, "getchanges"), body({ query }));
|
158 | }
|
159 | /**
|
160 | * Returns the name of the image file for the icon that is used to represent the specified file
|
161 | *
|
162 | * @param filename The file name. If this parameter is empty, the server returns an empty string
|
163 | * @param size The size of the icon: 16x16 pixels = 0, 32x32 pixels = 1 (default = 0)
|
164 | * @param progId The ProgID of the application that was used to create the file, in the form OLEServerName.ObjectName
|
165 | */
|
166 | mapToIcon(filename, size = 0, progId = "") {
|
167 | return Web(this, `maptoicon(filename='${escapeQueryStrValue(filename)}',progid='${escapeQueryStrValue(progId)}',size=${size})`)();
|
168 | }
|
169 | /**
|
170 | * Returns the tenant property corresponding to the specified key in the app catalog site
|
171 | *
|
172 | * @param key Id of storage entity to be set
|
173 | */
|
174 | getStorageEntity(key) {
|
175 | return Web(this, `getStorageEntity('${escapeQueryStrValue(key)}')`)();
|
176 | }
|
177 | /**
|
178 | * This will set the storage entity identified by the given key (MUST be called in the context of the app catalog)
|
179 | *
|
180 | * @param key Id of storage entity to be set
|
181 | * @param value Value of storage entity to be set
|
182 | * @param description Description of storage entity to be set
|
183 | * @param comments Comments of storage entity to be set
|
184 | */
|
185 | setStorageEntity(key, value, description = "", comments = "") {
|
186 | return spPost(Web(this, "setStorageEntity"), body({
|
187 | comments,
|
188 | description,
|
189 | key,
|
190 | value,
|
191 | }));
|
192 | }
|
193 | /**
|
194 | * This will remove the storage entity identified by the given key
|
195 | *
|
196 | * @param key Id of storage entity to be removed
|
197 | */
|
198 | removeStorageEntity(key) {
|
199 | return spPost(Web(this, `removeStorageEntity('${escapeQueryStrValue(key)}')`));
|
200 | }
|
201 | /**
|
202 | * Returns a collection of objects that contain metadata about subsites of the current site in which the current user is a member.
|
203 | *
|
204 | * @param nWebTemplateFilter Specifies the site definition (default = -1)
|
205 | * @param nConfigurationFilter A 16-bit integer that specifies the identifier of a configuration (default = -1)
|
206 | */
|
207 | getSubwebsFilteredForCurrentUser(nWebTemplateFilter = -1, nConfigurationFilter = -1) {
|
208 | return SPCollection(this, `getSubwebsFilteredForCurrentUser(nWebTemplateFilter=${nWebTemplateFilter},nConfigurationFilter=${nConfigurationFilter})`);
|
209 | }
|
210 | /**
|
211 | * Returns a collection of site templates available for the site
|
212 | *
|
213 | * @param language The locale id of the site templates to retrieve (default = 1033 [English, US])
|
214 | * @param includeCrossLanguage When true, includes language-neutral site templates; otherwise false (default = true)
|
215 | */
|
216 | availableWebTemplates(language = 1033, includeCrossLanugage = true) {
|
217 | return SPCollection(this, `getavailablewebtemplates(lcid=${language},doincludecrosslanguage=${includeCrossLanugage})`);
|
218 | }
|
219 | };
|
220 | _Web = __decorate([
|
221 | defaultPath("_api/web")
|
222 | ], _Web);
|
223 | export { _Web };
|
224 | export const Web = spInvokableFactory(_Web);
|
225 | //# sourceMappingURL=types.js.map |
\ | No newline at end of file |