UNPKG

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