UNPKG

4.76 kBJavaScriptView Raw
1import { body } from "@pnp/queryable";
2import { spPost } from "../operations.js";
3import { _SPQueryable } from "../spqueryable.js";
4import { extractWebUrl } from "../utils/extract-web-url.js";
5import { escapeQueryStrValue } from "../utils/escape-query-str.js";
6import { combine } from "@pnp/core";
7export class _SiteScripts extends _SPQueryable {
8 constructor(base, methodName = "") {
9 super(base);
10 this._url = combine(extractWebUrl(this._url), `_api/Microsoft.Sharepoint.Utilities.WebTemplateExtensions.SiteScriptUtility.${methodName}`);
11 }
12 run(props) {
13 return spPost(this, body(props));
14 }
15 /**
16 * Gets a list of information on all existing site scripts.
17 */
18 getSiteScripts() {
19 return SiteScriptsCloneFactory(this, "GetSiteScripts").run({});
20 }
21 /**
22 * Creates a new site script.
23 *
24 * @param title The display name of the site script.
25 * @param content JSON value that describes the script. For more information, see JSON reference.
26 */
27 createSiteScript(title, description, content) {
28 return SiteScriptsCloneFactory(this, `CreateSiteScript(Title=@title,Description=@desc)?@title='${escapeQueryStrValue(title)}'&@desc='${escapeQueryStrValue(description)}'`)
29 .run(content);
30 }
31 /**
32 * Gets information about a specific site script. It also returns the JSON of the script.
33 *
34 * @param id The ID of the site script to get information about.
35 */
36 getSiteScriptMetadata(id) {
37 return SiteScriptsCloneFactory(this, "GetSiteScriptMetadata").run({ id });
38 }
39 /**
40 * Deletes a site script.
41 *
42 * @param id The ID of the site script to delete.
43 */
44 deleteSiteScript(id) {
45 return SiteScriptsCloneFactory(this, "DeleteSiteScript").run({ id });
46 }
47 /**
48 * Updates a site script with new values. In the REST call, all parameters are optional except the site script Id.
49 *
50 * @param siteScriptUpdateInfo Object that contains the information to update a site script.
51 * Make sure you stringify the content object or pass it in the second 'content' parameter
52 * @param content (Optional) A new JSON script defining the script actions. For more information, see Site design JSON schema.
53 */
54 updateSiteScript(updateInfo, content) {
55 if (content) {
56 updateInfo.Content = JSON.stringify(content);
57 }
58 return SiteScriptsCloneFactory(this, "UpdateSiteScript").run({ updateInfo });
59 }
60 /**
61 * Gets the site script syntax (JSON) for a specific list
62 * @param listUrl The absolute url of the list to retrieve site script
63 */
64 getSiteScriptFromList(listUrl) {
65 return SiteScriptsCloneFactory(this, "GetSiteScriptFromList").run({ listUrl });
66 }
67 /**
68 * Gets the site script syntax (JSON) for a specific web
69 * @param webUrl The absolute url of the web to retrieve site script
70 * @param extractInfo configuration object to specify what to extract
71 */
72 getSiteScriptFromWeb(webUrl, info) {
73 return SiteScriptsCloneFactory(this, "getSiteScriptFromWeb").run({ webUrl, info });
74 }
75 /**
76 * Executes the indicated site design action on the indicated web.
77 *
78 * @param webUrl The absolute url of the web to retrieve site script
79 * @param extractInfo configuration object to specify what to extract
80 */
81 executeSiteScriptAction(actionDefinition) {
82 return SiteScriptsCloneFactory(this, "executeSiteScriptAction").run({ actionDefinition });
83 }
84}
85export const SiteScripts = (baseUrl, methodName) => new _SiteScripts(baseUrl, methodName);
86const SiteScriptsCloneFactory = (baseUrl, methodName = "") => SiteScripts(baseUrl, methodName);
87export var SiteScriptActionOutcome;
88(function (SiteScriptActionOutcome) {
89 /**
90 * The stage was deemed to have completed successfully.
91 */
92 SiteScriptActionOutcome[SiteScriptActionOutcome["Success"] = 0] = "Success";
93 /**
94 * The stage was deemed to have failed to complete successfully (non-blocking, rest of recipe
95 * execution should still be able to proceed).
96 */
97 SiteScriptActionOutcome[SiteScriptActionOutcome["Failure"] = 1] = "Failure";
98 /**
99 * No action was taken for this stage / this stage was skipped.
100 */
101 SiteScriptActionOutcome[SiteScriptActionOutcome["NoOp"] = 2] = "NoOp";
102 /**
103 * There was an exception but the operation succeeded. This is analagous to the operation completing
104 * in a "yellow" state.
105 */
106 SiteScriptActionOutcome[SiteScriptActionOutcome["SucceededWithException"] = 3] = "SucceededWithException";
107})(SiteScriptActionOutcome || (SiteScriptActionOutcome = {}));
108//# sourceMappingURL=types.js.map
\No newline at end of file