From 6df95d490e18579e43f7fdc9378e678259403a65 Mon Sep 17 00:00:00 2001 From: Gunjan Datta Date: Sat, 26 Jan 2019 14:00:07 -0500 Subject: [PATCH 01/12] Updated the intellisense to not include an internal method. --- src/utils/types/base.d.ts | 12 +++++------- test/test.ts | 15 +++++++++++++++ 2 files changed, 20 insertions(+), 7 deletions(-) diff --git a/src/utils/types/base.d.ts b/src/utils/types/base.d.ts index 98250985..fa5c3747 100644 --- a/src/utils/types/base.d.ts +++ b/src/utils/types/base.d.ts @@ -73,13 +73,6 @@ export interface IBaseExecution * Method to get the request information. */ getInfo(): IRequestInfo; - - /** - * Method to wait for the parent requests to complete - * @param callback - The callback method. - * @param requestIdx - The request index. - */ - waitForRequestsToComplete(callback: () => void, requestIdx?: number); } /** @@ -182,6 +175,11 @@ export interface IBase extends /** Updates the metdata uri. */ updateMetadataUri(metadata, targetInfo: ITargetInfoProps); + + /** + * Method to wait for the parent requests to complete + */ + waitForRequestsToComplete(callback: () => void, requestIdx?: number); } /** diff --git a/test/test.ts b/test/test.ts index 9e0a7a76..7e64cd72 100644 --- a/test/test.ts +++ b/test/test.ts @@ -4,6 +4,21 @@ import { Helper.SP.ModalDialog.showWaitScreenWithNoClose("Title", "Loading the Form"); +$REST.Web().Lists().execute(r => { + let title = r.results[0].Title; + + r.next().execute(n => { + let title = n.results[0].Title; + n.next().execute(n => { + n.results[0].Items().execute(i => { + i.results[0].File().execute(f => { + let name = f.Name; + }) + }) + }); + }); +}) + $REST.List("").execute(l => { l.getItemById(3).execute(item => { let file = item.File; From 84b389ff6b54d9d38c4d1f88a5294e5088f50677 Mon Sep 17 00:00:00 2001 From: Gunjan Datta Date: Sat, 26 Jan 2019 19:15:03 -0500 Subject: [PATCH 02/12] Added I[Type]QueryResults interfaces. --- build/helper/spCfg.js | 47 ++++--- build/rest.js | 2 +- dist/gd-sprest.d.ts | 159 +++++++++++++++++------- dist/gd-sprest.js | 4 +- dist/gd-sprest.min.js | 2 +- package.json | 2 +- src/helper/listForm.ts | 5 +- src/helper/spCfg.ts | 56 ++++++--- src/intellisense/contentTypes.d.ts | 5 + src/intellisense/eventReceivers.d.ts | 5 + src/intellisense/fields.d.ts | 5 + src/intellisense/files.d.ts | 5 + src/intellisense/folders.d.ts | 5 + src/intellisense/groups.d.ts | 5 + src/intellisense/items.d.ts | 5 + src/intellisense/lists.d.ts | 5 + src/intellisense/roleAssignments.d.ts | 5 + src/intellisense/roleDefinitions.d.ts | 5 + src/intellisense/userCustomActions.d.ts | 5 + src/intellisense/users.d.ts | 12 +- src/intellisense/views.d.ts | 5 + src/intellisense/webs.d.ts | 5 + src/rest.ts | 2 +- src/utils/types/base.d.ts | 76 +++++------ test/test.ts | 2 +- 25 files changed, 294 insertions(+), 140 deletions(-) diff --git a/build/helper/spCfg.js b/build/helper/spCfg.js index bfef8240..8cd6dba7 100644 --- a/build/helper/spCfg.js +++ b/build/helper/spCfg.js @@ -19,7 +19,8 @@ exports.SPConfig = function (cfg, webUrl) { * Methods */ // Method to create the content types - var createContentTypes = function (contentTypes, cfgContentTypes) { + var createContentTypes = function (collection, cfgContentTypes) { + var contentTypes = collection; // Return a promise return new Promise(function (resolve, reject) { // Ensure fields exist @@ -31,7 +32,7 @@ exports.SPConfig = function (cfg, webUrl) { var _loop_1 = function (i) { var cfgContentType = cfgContentTypes[i]; // See if this content type already exists - var ct = isInCollection("Name", cfgContentType.Name, contentTypes.results); + var ct = isInCollection("Name", cfgContentType.Name, collection.results); if (ct) { // Log console.log("[gd-sprest][Content Type] The content type '" + cfgContentType.Name + "' already exists."); @@ -210,7 +211,8 @@ exports.SPConfig = function (cfg, webUrl) { }); }; // Method to create the fields` - var createFields = function (fields, cfgFields) { + var createFields = function (collection, cfgFields) { + var fields = collection; // Return a promise return new Promise(function (resolve, reject) { // Ensure fields exist @@ -222,7 +224,7 @@ exports.SPConfig = function (cfg, webUrl) { var _loop_3 = function (i) { var cfgField = cfgFields[i]; // See if this field already exists - var field = isInCollection("InternalName", cfgField.name, fields.results); + var field = isInCollection("InternalName", cfgField.name, collection.results); if (field) { // Log console.log("[gd-sprest][Field] The field '" + cfgField.name + "' already exists."); @@ -270,7 +272,8 @@ exports.SPConfig = function (cfg, webUrl) { }); }; // Method to create the lists - var createLists = function (lists, cfgLists) { + var createLists = function (collection, cfgLists) { + var lists = collection; // Return a promise return new Promise(function (resolve, reject) { var _loop_4 = function (i) { @@ -283,7 +286,7 @@ exports.SPConfig = function (cfg, webUrl) { } } // See if this content type already exists - var list = isInCollection("Title", cfgList.ListInformation.Title, lists.results); + var list = isInCollection("Title", cfgList.ListInformation.Title, collection.results); if (list) { // Log console.log("[gd-sprest][List] The list '" + cfgList.ListInformation.Title + "' already exists."); @@ -341,7 +344,8 @@ exports.SPConfig = function (cfg, webUrl) { }); }; // Method to create the user custom actions - var createUserCustomActions = function (customActions, cfgCustomActions) { + var createUserCustomActions = function (collection, cfgCustomActions) { + var customActions = collection; // Return a promise return new Promise(function (resolve, reject) { // See if the configuration type exists @@ -372,7 +376,7 @@ exports.SPConfig = function (cfg, webUrl) { } } // See if this custom action already exists - if (isInCollection("Name", cfgCustomAction.Name, customActions.results)) { + if (isInCollection("Name", cfgCustomAction.Name, collection.results)) { // Log console.log("[gd-sprest][Custom Action] The custom action '" + cfgCustomAction.Name + "' already exists."); } @@ -405,7 +409,8 @@ exports.SPConfig = function (cfg, webUrl) { }); }; // Method to create the list views - var createViews = function (views, cfgViews) { + var createViews = function (collection, cfgViews) { + var views = collection; // Return a promise return new Promise(function (resolve, reject) { // Ensure the list views exist @@ -417,7 +422,7 @@ exports.SPConfig = function (cfg, webUrl) { var _loop_5 = function (i) { var cfgView = cfgViews[i]; // See if this view exists - var view = isInCollection("Title", cfgView.ViewName, views.results); + var view = isInCollection("Title", cfgView.ViewName, collection.results); if (view) { // Log console.log("[gd-sprest][View] The view '" + cfgView.ViewName + "' already exists."); @@ -450,7 +455,7 @@ exports.SPConfig = function (cfg, webUrl) { // Wait for the requests to complete views.done(function () { // Update the views - updateViews(views, cfgViews).then(function () { + updateViews(collection, cfgViews).then(function () { // Resolve the promise resolve(); }); @@ -566,7 +571,8 @@ exports.SPConfig = function (cfg, webUrl) { return false; }; // Method to remove the content type - var removeContentTypes = function (contentTypes, cfgContentTypes) { + var removeContentTypes = function (collection, cfgContentTypes) { + var contentTypes = collection; // Return a promise return new Promise(function (resolve, reject) { // Ensure the content types exist @@ -578,7 +584,7 @@ exports.SPConfig = function (cfg, webUrl) { var _loop_7 = function (i) { var cfgContentType = cfgContentTypes[i]; // Get the field - var ct = isInCollection("Name", cfgContentType.Name, contentTypes.results); + var ct = isInCollection("Name", cfgContentType.Name, collection.results); if (ct) { // Remove the field ct.delete().execute(function () { @@ -599,7 +605,8 @@ exports.SPConfig = function (cfg, webUrl) { }); }; // Method to remove the fields - var removeFields = function (fields, cfgFields) { + var removeFields = function (collection, cfgFields) { + var fields = collection; // Return a promise return new Promise(function (resolve, reject) { // Ensure the fields exist @@ -611,7 +618,7 @@ exports.SPConfig = function (cfg, webUrl) { var _loop_8 = function (i) { var cfgField = cfgFields[i]; // Get the field - var field = isInCollection("InternalName", cfgField.name, fields.results); + var field = isInCollection("InternalName", cfgField.name, collection.results); if (field) { // Remove the field field.delete().execute(function () { @@ -632,7 +639,8 @@ exports.SPConfig = function (cfg, webUrl) { }); }; // Method to remove the lists - var removeLists = function (lists, cfgLists) { + var removeLists = function (collection, cfgLists) { + var lists = collection; // Return a promise return new Promise(function (resolve, reject) { // See if the configuration type exists @@ -660,7 +668,7 @@ exports.SPConfig = function (cfg, webUrl) { } } // Get the list - var list = isInCollection("Title", cfgList.ListInformation.Title, lists.results); + var list = isInCollection("Title", cfgList.ListInformation.Title, collection.results); if (list) { // Remove the list list.delete().execute(function () { @@ -681,7 +689,8 @@ exports.SPConfig = function (cfg, webUrl) { }); }; // Method to remove the user custom actions - var removeUserCustomActions = function (customActions, cfgCustomActions) { + var removeUserCustomActions = function (collection, cfgCustomActions) { + var customActions = collection; // Return a promise return new Promise(function (resolve, reject) { // See if the configuration type exists @@ -710,7 +719,7 @@ exports.SPConfig = function (cfg, webUrl) { } } // Get the custom action - var ca = isInCollection("Name", cfgCustomAction.Name, customActions.results); + var ca = isInCollection("Name", cfgCustomAction.Name, collection.results); if (ca) { // Remove the custom action ca.delete().execute(function () { diff --git a/build/rest.js b/build/rest.js index bd3461b4..48f7e5cb 100644 --- a/build/rest.js +++ b/build/rest.js @@ -7,7 +7,7 @@ var Mapper = require("./mapper"); * SharePoint REST Library */ exports.$REST = { - __ver: 4.52, + __ver: 4.53, AppContext: function (siteUrl) { return Lib.Site.getAppContext(siteUrl); }, ContextInfo: Lib.ContextInfo, DefaultRequestToHostFl: false, diff --git a/dist/gd-sprest.d.ts b/dist/gd-sprest.d.ts index 9e7dfcc3..9e145291 100644 --- a/dist/gd-sprest.d.ts +++ b/dist/gd-sprest.d.ts @@ -4250,6 +4250,11 @@ declare module 'gd-sprest/intellisense/contentTypes' { */ export interface IContentTypes extends IContentTypesMethods, IBaseCollection { } + /** + * Content Type Event ReceiverResults + */ + export interface IContentTypeQueryResults extends IContentTypesMethods, IBaseCollectionResult { } + /** * Content Type Results */ @@ -4361,6 +4366,11 @@ declare module 'gd-sprest/intellisense/eventReceivers' { */ export interface IEventReceivers extends IEventReceiversMethods, IBaseCollection { } + /** + * Event Receiver Query Results + */ + export interface IEventReceiverQueryResults extends IEventReceiversMethods, IBaseCollectionResult { } + /** * Event Receiver Results */ @@ -4892,6 +4902,11 @@ declare module 'gd-sprest/intellisense/fields' { */ export interface IFields extends IFieldsMethods, IBaseCollection { } + /** + * Field Query Results + */ + export interface IFieldQueryResults extends IFieldsMethods, IBaseCollectionResult { } + /** * Field Results */ @@ -5177,6 +5192,11 @@ declare module 'gd-sprest/intellisense/files' { */ export interface IFiles extends IFilesMethods, IBaseCollection { } + /** + * File Query Results + */ + export interface IFileQueryResults extends IFilesMethods, IBaseCollectionResult { } + /** * File Results */ @@ -5391,6 +5411,11 @@ declare module 'gd-sprest/intellisense/folders' { */ export interface IFolders extends IFoldersMethods, IBaseCollection { } + /** + * Folder Query Results + */ + export interface IFolderQueryResults extends IFoldersMethods, IBaseCollectionResult { } + /** * Folder Results */ @@ -5846,6 +5871,11 @@ declare module 'gd-sprest/intellisense/groups' { */ export interface ISiteGroups extends ISiteGroupsMethods, IBaseCollection { } + /** + * Site Group Query Results + */ + export interface ISiteGroupQueryResults extends ISiteGroupsMethods, IBaseCollectionResult { } + /** * Site Group Results */ @@ -5878,6 +5908,11 @@ declare module 'gd-sprest/intellisense/items' { */ export interface IListItems extends IListItemsMethods, IBaseCollection { } + /** + * List Item Query Results + */ + export interface IListItemQueryResults extends IListItemsMethods, IBaseCollectionResult { } + /** * List Item Results */ @@ -6492,6 +6527,11 @@ declare module 'gd-sprest/intellisense/lists' { */ export interface ILists extends IListsMethods, IBaseCollection { } + /** + * List Query Results + */ + export interface IListQueryResults extends IListsMethods, IBaseCollectionResult { } + /** * List Results */ @@ -7252,6 +7292,11 @@ declare module 'gd-sprest/intellisense/roleAssignments' { */ export interface IRoleAssignments extends IRoleAssignmentsMethods, IBaseCollection { } + /** + * Role Assignment Query Results + */ + export interface IRoleAssignmentQueryResults extends IRoleAssignmentsMethods, IBaseCollectionResult { } + /** * Role Assignment Results */ @@ -7325,6 +7370,11 @@ declare module 'gd-sprest/intellisense/roleDefinitions' { */ export interface IRoleDefinitions extends IRoleDefinitionsMethods, IBaseCollection { } + /** + * Role Definition Query Results + */ + export interface IRoleDefinitionQueryResults extends IRoleDefinitionsMethods, IBaseCollectionResult { } + /** * Role Definition Results */ @@ -8013,6 +8063,11 @@ declare module 'gd-sprest/intellisense/userCustomActions' { export interface IUserCustomActions extends IUserCustomActionsMethods, IBaseCollection { } + /** + * User Custom Action Query Results + */ + export interface IUserCustomActionQueryResults extends IUserCustomActionsMethods, IBaseCollectionResult { } + /** * User Custom Action Results */ @@ -8133,7 +8188,7 @@ declare module 'gd-sprest/intellisense/userProfile' { declare module 'gd-sprest/intellisense/users' { import { SP } from "gd-sprest-def"; - import { IBaseExecution, IBaseCollection } from "gd-sprest/utils/types/base"; + import { IBaseExecution, IBaseCollection, IBaseCollectionResult } from "gd-sprest/utils/types/base"; import { IUser, IUserQueryResult, IUserResult } from "gd-sprest/intellisense"; /** @@ -8164,11 +8219,6 @@ declare module 'gd-sprest/intellisense/users' { */ getByLoginName(loginName): IUser & IBaseExecution; - /** - * Method to get the next set of results. - */ - next(): IBaseExecution; - /** * Removes the user with the specified ID. * @param id - The ID of the user to remove. @@ -8187,6 +8237,11 @@ declare module 'gd-sprest/intellisense/users' { */ export interface IUsers extends IUsersMethods, IBaseCollection { } + /** + * User Query Results + */ + export interface IUserQueryResults extends IUsersMethods, IBaseCollectionResult { } + /** * User Results */ @@ -8562,6 +8617,11 @@ declare module 'gd-sprest/intellisense/views' { */ export interface IViews extends IViewsMethods, IBaseCollection { } + /** + * View Query Results + */ + export interface IViewQueryResults extends IViewsMethods, IBaseCollectionResult { } + /** * View Results */ @@ -9267,6 +9327,11 @@ declare module 'gd-sprest/intellisense/webs' { */ export interface IWebs extends IWebsMethods, IBaseCollection { } + /** + * Web Query Results + */ + export interface IWebQueryResults extends IWebsMethods, IBaseCollectionResult { } + /** * Web Results */ @@ -9349,13 +9414,6 @@ declare module 'gd-sprest/utils/types/base' { * Method to get the request information. */ getInfo(): IRequestInfo; - - /** - * Method to wait for the parent requests to complete - * @param callback - The callback method. - * @param requestIdx - The request index. - */ - waitForRequestsToComplete(callback: () => void, requestIdx?: number); } /** @@ -9385,7 +9443,44 @@ declare module 'gd-sprest/utils/types/base' { * Queries the collection. * @param oData - The OData information. */ - query?(query: ODataQuery): IBaseExecution; + query?(query: ODataQuery): IBaseExecution; + } + + /** + * Base Execution Query Result + */ + export interface IBaseQueryExecutionResult extends IBaseCollectionResult { + /** The collection results. */ + results: Array + } + + /** + * Base Collection + */ + export interface IBaseCollection extends IBaseQueryExecution> { + } + + /** + * Base Collection Results + */ + export interface IBaseCollectionResult { + /** True, if the object exists, false otherwise. */ + existsFl: boolean; + + /** Returns the next set of results, if paging exists. */ + next(): IBaseCollection; + + /** True, if more items exist. */ + nextFl: boolean; + + /** The raw string response. */ + response: string; + + /** The results. */ + results: Array; + + /** Method to stringify the object. */ + stringify(): string; } /** @@ -9446,43 +9541,11 @@ declare module 'gd-sprest/utils/types/base' { /** Updates the metdata uri. */ updateMetadataUri(metadata, targetInfo: ITargetInfoProps); - } - /** - * Base Collection Results - */ - export interface IBaseCollectionResult { /** - * Method to wait for the requests to complete. - * @param resolve - The method to be executed after the request completes. + * Method to wait for the parent requests to complete */ - done(resolve: (value?: T) => void); - - /** True, if the object exists, false otherwise. */ - existsFl: boolean; - - /** Returns the next set of results, if paging exists. */ - next(): IBaseCollection; - - /** True, if more items exist. */ - nextFl: boolean; - - /** The raw string response. */ - response: string; - - /** The results. */ - results: Array; - - /** Method to stringify the object. */ - stringify(): string; - } - - /** - * Base Collection - */ - export interface IBaseCollection extends IBaseQueryExecution, IBaseCollectionResult, IBaseCollectionResult> { - /** The collection results. */ - results: Array + waitForRequestsToComplete(callback: () => void, requestIdx?: number); } } diff --git a/dist/gd-sprest.js b/dist/gd-sprest.js index c47f8f4c..7b6ed905 100644 --- a/dist/gd-sprest.js +++ b/dist/gd-sprest.js @@ -250,7 +250,7 @@ eval("\n\nObject.defineProperty(exports, \"__esModule\", {\n value: true\n});\n /***/ (function(module, exports, __webpack_require__) { "use strict"; -eval("\n\nfunction __export(m) {\n for (var p in m) {\n if (!exports.hasOwnProperty(p)) exports[p] = m[p];\n }\n}\n\nObject.defineProperty(exports, \"__esModule\", {\n value: true\n});\n\n__export(__webpack_require__(/*! ./spCfgTypes */ \"./build/helper/spCfgTypes.js\"));\n\nvar lib_1 = __webpack_require__(/*! ../lib */ \"./build/lib/index.js\");\n\nvar __1 = __webpack_require__(/*! .. */ \"./build/index.js\");\n\nvar _1 = __webpack_require__(/*! . */ \"./build/helper/index.js\");\n/**\r\n * SharePoint Configuration\r\n */\n\n\nexports.SPConfig = function (cfg, webUrl) {\n // The selected configuration type to install\n var _cfgType; // The target name to install/uninstall\n\n\n var _targetName;\n /**\r\n * Methods\r\n */\n // Method to create the content types\n\n\n var createContentTypes = function createContentTypes(contentTypes, cfgContentTypes) {\n // Return a promise\n return new Promise(function (resolve, reject) {\n // Ensure fields exist\n if (cfgContentTypes == null || cfgContentTypes.length == 0) {\n // Resolve the promise\n resolve();\n return;\n }\n\n var _loop_1 = function _loop_1(i) {\n var cfgContentType = cfgContentTypes[i]; // See if this content type already exists\n\n var ct = isInCollection(\"Name\", cfgContentType.Name, contentTypes.results);\n\n if (ct) {\n // Log\n console.log(\"[gd-sprest][Content Type] The content type '\" + cfgContentType.Name + \"' already exists.\"); // Update the configuration\n\n cfgContentType.ContentType = ct;\n } else {\n // Log\n console.log(\"[gd-sprest][Content Type] Creating the '\" + cfgContentType.Name + \"' content type.\"); // See if the parent name exists\n\n if (cfgContentType.ParentName) {\n // Get the web containing the parent content type\n lib_1.Web(cfgContentType.ParentWebUrl || webUrl) // Get the content types\n .ContentTypes() // Filter for the parent name\n .query({\n Filter: \"Name eq '\" + cfgContentType.ParentName + \"'\"\n }).execute(function (parent) {\n // See if the parent exists\n if (parent.results[0]) {\n // Add the available content type\n contentTypes.addAvailableContentType(parent.results[0].Id.StringValue).execute(function (ct) {\n // See if it was successful\n if (ct.existsFl) {\n // Update the name\n (function () {\n return new Promise(function (resolve, reject) {\n // Ensure the name doesn't need to be updated\n if (ct.Name != cfgContentType.Name) {\n ct.update({\n Name: cfgContentType.Name\n }).execute(function () {\n // Resolve the promise\n resolve();\n });\n } else {\n // Resolve the promise\n resolve();\n }\n });\n })().then(function () {\n // Log\n console.log(\"[gd-sprest][Content Type] The content type '\" + cfgContentType.Name + \"' was created successfully.\"); // Update the configuration\n\n cfgContentType.ContentType = ct; // Trigger the event\n\n cfgContentType.onCreated ? cfgContentType.onCreated(ct) : null;\n });\n } else {\n // Log\n console.log(\"[gd-sprest][Content Type] The content type '\" + cfgContentType.Name + \"' failed to be created.\");\n console.error(\"[gd-sprest][Field] Error: \" + ct.response);\n }\n }, true);\n } else {\n // Log\n console.log(\"[gd-sprest][Content Type] The parent content type '\" + cfgContentType.Name + \"' was not found.\");\n }\n }, reject);\n } else {\n // Create the content type\n contentTypes.add({\n Description: cfgContentType.Description,\n Group: cfgContentType.Group,\n\n /*\r\n Id: {\r\n __metadata: { type: \"SP.ContentTypeId\" },\r\n StringValue: cfgContentType.Id ? cfgContentType.Id.StringValue : \"0x0100\" + ContextInfo.generateGUID().replace(\"{\", \"\").replace(\"-\", \"\").replace(\"}\", \"\")\r\n },\r\n */\n Id: cfgContentType.Id || \"0x0100\" + lib_1.ContextInfo.generateGUID().replace(\"{\", \"\").replace(\"-\", \"\").replace(\"}\", \"\"),\n Name: cfgContentType.Name\n }).execute(function (ct) {\n // See if it was successful\n if (ct.existsFl) {\n // Log\n console.log(\"[gd-sprest][Content Type] The content type '\" + cfgContentType.Name + \"' was created successfully.\"); // Update the configuration\n\n cfgContentType.ContentType = ct; // Trigger the event\n\n cfgContentType.onCreated ? cfgContentType.onCreated(ct) : null;\n } else {\n // Log\n console.log(\"[gd-sprest][Content Type] The content type '\" + cfgContentType.Name + \"' failed to be created.\");\n console.error(\"[gd-sprest][Field] Error: \" + ct.response);\n }\n }, reject, true);\n }\n }\n }; // Parse the configuration\n\n\n for (var i = 0; i < cfgContentTypes.length; i++) {\n _loop_1(i);\n } // Wait for the requests to complete\n\n\n contentTypes.done(function () {\n var _loop_2 = function _loop_2(i) {\n var cfgContentType = cfgContentTypes[i];\n var cfgUpdate = {};\n var updateFl = false; // Ensure the content type exists\n\n if (cfgContentType.ContentType == null) {\n return \"continue\";\n }\n /**\r\n * See if we need to update the properties\r\n */\n // Description\n\n\n if (cfgContentType.ContentType.Description != cfgContentType.Description) {\n // Update the configuration\n cfgUpdate.Description = cfgContentType.Description; // Log\n\n console.log(\"[gd-sprest][Content Type][\" + cfgContentType.ContentType.Name + \"] Description requires update.\"); // Set the flag\n\n updateFl = true;\n } // Group\n\n\n if (cfgContentType.ContentType.Group != cfgContentType.Group) {\n // Update the configuration\n cfgUpdate.Group = cfgContentType.Group; // Log\n\n console.log(\"[gd-sprest][Content Type][\" + cfgContentType.ContentType.Name + \"] Group requires update.\"); // Set the flag\n\n updateFl = true;\n } // JSLink\n\n\n if (cfgContentType.ContentType.JSLink != cfgContentType.JSLink) {\n // Update the configuration\n cfgUpdate.JSLink = cfgContentType.JSLink; // Log\n\n console.log(\"[gd-sprest][Content Type][\" + cfgContentType.ContentType.Name + \"] JSLink requires update.\"); // Set the flag\n\n updateFl = true;\n } // Name\n\n\n if (cfgContentType.ContentType.Name != cfgContentType.Name) {\n // Update the configuration\n cfgUpdate.Name = cfgContentType.Name; // Log\n\n console.log(\"[gd-sprest][Content Type][\" + cfgContentType.ContentType.Name + \"] Name requires update.\"); // Set the flag\n\n updateFl = true;\n } // See if an update is needed\n\n\n if (updateFl) {\n // Log\n console.log(\"[gd-sprest][Content Type][\" + cfgContentType.ContentType.Name + \"] Updating the webpart.\"); // Update the content type\n\n cfgContentType.ContentType.update({\n JSLink: cfgContentType.JSLink\n }).execute(function () {\n // Log\n console.log(\"[gd-sprest][Content Type][\" + cfgContentType.ContentType.Name + \"] Update request completed.\"); // Trigger the event\n\n cfgContentType.onUpdated ? cfgContentType.onUpdated(cfgContentType.ContentType) : null;\n });\n } else {\n // Trigger the event\n cfgContentType.onUpdated ? cfgContentType.onUpdated(cfgContentType.ContentType) : null;\n }\n }; // Parse the configuration\n\n\n for (var i = 0; i < cfgContentTypes.length; i++) {\n _loop_2(i);\n } // Wait for the requests to complete\n\n\n contentTypes.done(function () {\n // Resolve the promise\n resolve();\n });\n });\n });\n }; // Method to create the fields`\n\n\n var createFields = function createFields(fields, cfgFields) {\n // Return a promise\n return new Promise(function (resolve, reject) {\n // Ensure fields exist\n if (cfgFields == null || cfgFields.length == 0) {\n // Resolve the promise\n resolve();\n return;\n }\n\n var _loop_3 = function _loop_3(i) {\n var cfgField = cfgFields[i]; // See if this field already exists\n\n var field = isInCollection(\"InternalName\", cfgField.name, fields.results);\n\n if (field) {\n // Log\n console.log(\"[gd-sprest][Field] The field '\" + cfgField.name + \"' already exists.\"); // Trigger the event\n\n cfgField.onUpdated ? cfgField.onUpdated(field) : null;\n } else {\n // Log\n console.log(\"[gd-sprest][Field] Creating the '\" + cfgField.name + \"' field.\"); // The field created event\n\n var onFieldCreated_1 = function onFieldCreated_1(field) {\n // See if it was successful\n if (field.existsFl) {\n // Log\n console.log(\"[gd-sprest][Field] The field '\" + field.InternalName + \"' was created successfully.\"); // Trigger the event\n\n cfgField.onCreated ? cfgField.onCreated(field) : null;\n } else {\n // Log\n console.log(\"[gd-sprest][Field] The field '\" + cfgField.name + \"' failed to be created.\");\n console.error(\"[gd-sprest][Field] Error: \" + field.response);\n }\n }; // Compute the schema xml\n\n\n _1.FieldSchemaXML(cfgField).then(function (response) {\n var schemas = typeof response === \"string\" ? [response] : response; // Parse the fields to add\n\n for (var i_1 = 0; i_1 < schemas.length; i_1++) {\n // Add the field\n fields.createFieldAsXml(schemas[i_1]).execute(onFieldCreated_1, true);\n }\n });\n }\n }; // Parse the fields\n\n\n for (var i = 0; i < cfgFields.length; i++) {\n _loop_3(i);\n } // Wait for the requests to complete\n\n\n fields.done(function () {\n // Resolve the promise\n resolve();\n });\n });\n }; // Method to create the lists\n\n\n var createLists = function createLists(lists, cfgLists) {\n // Return a promise\n return new Promise(function (resolve, reject) {\n var _loop_4 = function _loop_4(i) {\n var cfgList = cfgLists[i]; // See if the target name exists\n\n if (_cfgType && _targetName) {\n // Ensure it's for this list\n if (cfgList.ListInformation.Title.toLowerCase() != _targetName) {\n return \"continue\";\n }\n } // See if this content type already exists\n\n\n var list = isInCollection(\"Title\", cfgList.ListInformation.Title, lists.results);\n\n if (list) {\n // Log\n console.log(\"[gd-sprest][List] The list '\" + cfgList.ListInformation.Title + \"' already exists.\");\n } else {\n // Log\n console.log(\"[gd-sprest][List] Creating the '\" + cfgList.ListInformation.Title + \"' list.\"); // Update the list name and remove spaces\n\n var listInfo_1 = cfgList.ListInformation;\n var listName_1 = listInfo_1.Title;\n listInfo_1.Title = listName_1.replace(/ /g, \"\"); // Add the list\n\n lists.add(listInfo_1) // Execute the request\n .execute(function (list) {\n // Restore the list name in the configuration\n listInfo_1.Title = listName_1; // See if the request was successful\n\n if (list.existsFl) {\n // See if we need to update the list\n if (list.existsFl && list.Title != listName_1) {\n // Update the list\n list.update({\n Title: listName_1\n }).execute(function () {\n // Log\n console.log(\"[gd-sprest][List] The list '\" + list.Title + \"' was created successfully.\");\n });\n } else {\n // Log\n console.log(\"[gd-sprest][List] The list '\" + list.Title + \"' was created successfully.\");\n } // Trigger the event\n\n\n cfgList.onCreated ? cfgList.onCreated(list) : null;\n } else {\n // Log\n console.log(\"[gd-sprest][List] The list '\" + listInfo_1.Title + \"' failed to be created.\");\n console.log(\"[gd-sprest][List] Error: '\" + list.response);\n }\n }, reject);\n }\n }; // Parse the content types\n\n\n for (var i = 0; i < cfgLists.length; i++) {\n _loop_4(i);\n } // Wait for the requests to complete\n\n\n lists.done(function () {\n // Update the lists\n updateLists(cfgLists).then(function () {\n // Resolve the promise\n resolve();\n });\n });\n });\n }; // Method to create the user custom actions\n\n\n var createUserCustomActions = function createUserCustomActions(customActions, cfgCustomActions) {\n // Return a promise\n return new Promise(function (resolve, reject) {\n // See if the configuration type exists\n if (_cfgType) {\n // Ensure it's for this type\n if (_cfgType != _1.SPCfgType.SiteUserCustomActions || _cfgType != _1.SPCfgType.WebUserCustomActions) {\n // Resolve the promise\n resolve();\n return;\n }\n } // Ensure the lists exist\n\n\n if (cfgCustomActions == null || cfgCustomActions.length == 0) {\n // Resolve the promise and return it\n resolve();\n return;\n } // Parse the custom actions\n\n\n for (var i = 0; i < cfgCustomActions.length; i++) {\n var cfgCustomAction = cfgCustomActions[i]; // See if the target name exists\n\n if (_cfgType && _targetName) {\n // Ensure it's for this custom action\n if (cfgCustomAction.Name.toLowerCase() != _targetName || cfgCustomAction.Title.toLowerCase() != _targetName) {\n // Skip this custom action\n continue;\n }\n } // See if this custom action already exists\n\n\n if (isInCollection(\"Name\", cfgCustomAction.Name, customActions.results)) {\n // Log\n console.log(\"[gd-sprest][Custom Action] The custom action '\" + cfgCustomAction.Name + \"' already exists.\");\n } else {\n // See if rights exist\n if (cfgCustomAction.Rights) {\n // Update the value\n cfgCustomAction.Rights = updateBasePermissions(cfgCustomAction.Rights);\n } // Add the custom action\n\n\n customActions.add(cfgCustomAction).execute(function (ca) {\n // Ensure it exists\n if (ca.existsFl) {\n // Log\n console.log(\"[gd-sprest][Custom Action] The custom action '\" + ca.Name + \"' was created successfully.\");\n } else {\n // Log\n console.log(\"[gd-sprest][Custom Action] The custom action '\" + ca.Name + \"' failed to be created.\");\n console.log(\"[gd-sprest][Custom Action] Error: \" + ca.response);\n }\n }, reject, true);\n }\n } // Wait for the requests to complete\n\n\n customActions.done(function () {\n // Resolve the promise\n resolve();\n });\n });\n }; // Method to create the list views\n\n\n var createViews = function createViews(views, cfgViews) {\n // Return a promise\n return new Promise(function (resolve, reject) {\n // Ensure the list views exist\n if (cfgViews == null || cfgViews.length == 0) {\n // Resolve the promise and return it\n resolve();\n return;\n }\n\n var _loop_5 = function _loop_5(i) {\n var cfgView = cfgViews[i]; // See if this view exists\n\n var view = isInCollection(\"Title\", cfgView.ViewName, views.results);\n\n if (view) {\n // Log\n console.log(\"[gd-sprest][View] The view '\" + cfgView.ViewName + \"' already exists.\");\n } else {\n // Add the view\n views.add({\n Title: cfgView.ViewName,\n ViewQuery: cfgView.ViewQuery\n }).execute(function (view) {\n // Ensure it exists\n if (view.existsFl) {\n // Log\n console.log(\"[gd-sprest][View] The view '\" + cfgView.ViewName + \"' was created successfully.\"); // Trigger the event\n\n cfgView.onCreated ? cfgView.onCreated(view) : null;\n } else {\n // Log\n console.log(\"[gd-sprest][View] The view '\" + cfgView.ViewName + \"' failed to be created.\");\n console.log(\"[gd-sprest][View] Error: \" + view.response);\n }\n }, reject, true);\n }\n }; // Parse the views\n\n\n for (var i = 0; i < cfgViews.length; i++) {\n _loop_5(i);\n } // Wait for the requests to complete\n\n\n views.done(function () {\n // Update the views\n updateViews(views, cfgViews).then(function () {\n // Resolve the promise\n resolve();\n });\n });\n });\n }; // Method to create the web parts\n\n\n var createWebParts = function createWebParts() {\n // Return a promise\n return new Promise(function (resolve, reject) {\n var cfgWebParts = cfg.WebPartCfg; // Log\n\n console.log(\"[gd-sprest][WebPart] Creating the web parts.\"); // Get the root web\n\n lib_1.Web(lib_1.ContextInfo.siteServerRelativeUrl) // Get the web part catalog\n .getCatalog(__1.SPTypes.ListTemplateType.WebPartCatalog) // Get the root folder\n .RootFolder() // Expand the files and items\n .query({\n Expand: [\"Files\"]\n }) // Execute the request\n .execute(function (folder) {\n var ctr = 0;\n\n var _loop_6 = function _loop_6(i) {\n var cfgWebPart = cfgWebParts[i]; // See if the target name exists\n\n if (_cfgType && _targetName) {\n // Ensure it's for this list\n if (cfgWebPart.FileName.toLowerCase() != _targetName) {\n return \"continue\";\n }\n } // The post execute method\n\n\n var postExecute = function postExecute() {\n // Increment the counter\n if (++ctr >= cfgWebParts.length) {\n // Resolve the promise\n resolve();\n }\n }; // See if this webpart exists\n\n\n var file = isInCollection(\"Name\", cfgWebPart.FileName, folder.Files.results);\n\n if (file.existsFl) {\n // Log\n console.log(\"[gd-sprest][WebPart] The webpart '\" + cfgWebPart.FileName + \"' already exists.\"); // Trigger the event\n\n cfgWebPart.onUpdated ? cfgWebPart.onUpdated(file) : null; // Execute the post event\n\n postExecute();\n } else {\n // Trim the xml\n var xml = cfgWebPart.XML.trim(); // Convert the string to an array buffer\n\n var buffer = new ArrayBuffer(xml.length * 2);\n var bufferView = new Uint16Array(buffer);\n\n for (var j = 0; j < xml.length; j++) {\n bufferView[j] = xml.charCodeAt(j);\n } // Create the webpart, but execute the requests one at a time\n\n\n folder.Files.add(true, cfgWebPart.FileName, buffer).execute(function (file) {\n // See if group exists\n if (cfgWebPart.Group) {\n // Set the target to the root web\n lib_1.Web(lib_1.ContextInfo.siteServerRelativeUrl) // Get the web part catalog\n .getCatalog(__1.SPTypes.ListTemplateType.WebPartCatalog) // Get the Items\n .Items() // Query for this webpart\n .query({\n Filter: \"FileLeafRef eq '\" + cfgWebPart.FileName + \"'\"\n }) // Execute the request\n .execute(function (items) {\n // Update the item\n items.results[0].update({\n Group: cfgWebPart.Group\n }).execute(postExecute);\n });\n } // Log\n\n\n console.log(\"[gd-sprest][WebPart] The '\" + file.Name + \"' webpart file was uploaded successfully.\"); // Trigger the event\n\n cfgWebPart.onCreated ? cfgWebPart.onCreated(file) : null;\n });\n }\n }; // Parse the configuration\n\n\n for (var i = 0; i < cfgWebParts.length; i++) {\n _loop_6(i);\n }\n }, reject);\n });\n }; // Method to see if an object exists in a collection\n\n\n var isInCollection = function isInCollection(key, value, collection) {\n var valueLower = value.toLowerCase(); // Parse the collection\n\n for (var i = 0; i < collection.length; i++) {\n var keyValue = collection[i][key];\n keyValue = keyValue ? keyValue.toLowerCase() : \"\"; // See if the item exists\n\n if (valueLower == keyValue) {\n // Return true\n return collection[i];\n }\n } // Not in the collection\n\n\n return false;\n }; // Method to remove the content type\n\n\n var removeContentTypes = function removeContentTypes(contentTypes, cfgContentTypes) {\n // Return a promise\n return new Promise(function (resolve, reject) {\n // Ensure the content types exist\n if (cfgContentTypes == null || cfgContentTypes.length == 0) {\n // Resolve the promise and return it\n resolve();\n return;\n }\n\n var _loop_7 = function _loop_7(i) {\n var cfgContentType = cfgContentTypes[i]; // Get the field\n\n var ct = isInCollection(\"Name\", cfgContentType.Name, contentTypes.results);\n\n if (ct) {\n // Remove the field\n ct.delete().execute(function () {\n // Log\n console.log(\"[gd-sprest][Field] The content type '\" + ct.Name + \"' was removed.\");\n }, reject, true);\n }\n }; // Parse the configuration\n\n\n for (var i = 0; i < cfgContentTypes.length; i++) {\n _loop_7(i);\n } // Wait for the requests to complete\n\n\n contentTypes.done(function () {\n // Resolve the promise\n resolve();\n });\n });\n }; // Method to remove the fields\n\n\n var removeFields = function removeFields(fields, cfgFields) {\n // Return a promise\n return new Promise(function (resolve, reject) {\n // Ensure the fields exist\n if (cfgFields == null || cfgFields.length == 0) {\n // Resolve the promise and return it\n resolve();\n return;\n }\n\n var _loop_8 = function _loop_8(i) {\n var cfgField = cfgFields[i]; // Get the field\n\n var field = isInCollection(\"InternalName\", cfgField.name, fields.results);\n\n if (field) {\n // Remove the field\n field.delete().execute(function () {\n // Log\n console.log(\"[gd-sprest][Field] The field '\" + field.InternalName + \"' was removed.\");\n }, reject, true);\n }\n }; // Parse the configuration\n\n\n for (var i = 0; i < cfgFields.length; i++) {\n _loop_8(i);\n } // Wait for the requests to complete\n\n\n fields.done(function () {\n // Resolve the promise\n resolve();\n });\n });\n }; // Method to remove the lists\n\n\n var removeLists = function removeLists(lists, cfgLists) {\n // Return a promise\n return new Promise(function (resolve, reject) {\n // See if the configuration type exists\n if (_cfgType) {\n // Ensure it's for this type\n if (_cfgType != _1.SPCfgType.Lists) {\n // Resolve the promise\n resolve();\n return;\n }\n } // Ensure the lists exist\n\n\n if (cfgLists == null || cfgLists.length == 0) {\n // Resolve the promise and return it\n resolve();\n return;\n }\n\n var _loop_9 = function _loop_9(i) {\n var cfgList = cfgLists[i]; // See if the target name exists\n\n if (_cfgType && _targetName) {\n // Ensure it's for this list\n if (cfgList.ListInformation.Title.toLowerCase() != _targetName) {\n return \"continue\";\n }\n } // Get the list\n\n\n var list = isInCollection(\"Title\", cfgList.ListInformation.Title, lists.results);\n\n if (list) {\n // Remove the list\n list.delete().execute(function () {\n // Log\n console.log(\"[gd-sprest][List] The list '\" + list.Title + \"' was removed.\");\n }, reject, true);\n }\n }; // Parse the configuration\n\n\n for (var i = 0; i < cfgLists.length; i++) {\n _loop_9(i);\n } // Wait for the requests to complete\n\n\n lists.done(function () {\n // Resolve the promise\n resolve();\n });\n });\n }; // Method to remove the user custom actions\n\n\n var removeUserCustomActions = function removeUserCustomActions(customActions, cfgCustomActions) {\n // Return a promise\n return new Promise(function (resolve, reject) {\n // See if the configuration type exists\n if (_cfgType) {\n // Ensure it's for this type\n if (_cfgType != _1.SPCfgType.SiteUserCustomActions || _cfgType != _1.SPCfgType.WebUserCustomActions) {\n // Resolve the promise\n resolve();\n return;\n }\n } // Ensure the custom actions exist\n\n\n if (cfgCustomActions == null || cfgCustomActions.length == 0) {\n // Resolve the promise and return it\n resolve();\n return;\n }\n\n var _loop_10 = function _loop_10(i) {\n var cfgCustomAction = cfgCustomActions[i]; // See if the target name exists\n\n if (_cfgType && _targetName) {\n // Ensure it's for this custom action\n if (cfgCustomAction.Name.toLowerCase() != _targetName || cfgCustomAction.Title.toLowerCase() != _targetName) {\n return \"continue\";\n }\n } // Get the custom action\n\n\n var ca = isInCollection(\"Name\", cfgCustomAction.Name, customActions.results);\n\n if (ca) {\n // Remove the custom action\n ca.delete().execute(function () {\n // Log\n console.log(\"[gd-sprest][Custom Action] The custom action '\" + ca.Name + \"' was removed.\");\n }, reject, true);\n }\n }; // Parse the configuration\n\n\n for (var i = 0; i < cfgCustomActions.length; i++) {\n _loop_10(i);\n } // Wait for the requests to complete\n\n\n customActions.done(function () {\n // Resolve the promise\n resolve();\n });\n });\n }; // Method to remove the web parts\n\n\n var removeWebParts = function removeWebParts() {\n var cfgWebParts = cfg.WebPartCfg; // Return a promise\n\n return new Promise(function (resolve, reject) {\n // See if the configuration type exists\n if (_cfgType) {\n // Ensure it's for this type\n if (_cfgType != _1.SPCfgType.WebParts) {\n // Resolve the promise\n resolve();\n return;\n }\n } // Ensure the configuration exists\n\n\n if (cfgWebParts == null || cfgWebParts.length == 0) {\n // Resolve the promise and return it\n resolve();\n return;\n } // Log\n\n\n console.log(\"[gd-sprest][WebPart] Removing the web parts.\"); // Get the root web\n\n lib_1.Web(lib_1.ContextInfo.siteServerRelativeUrl) // Get the webpart gallery\n .getCatalog(__1.SPTypes.ListTemplateType.WebPartCatalog) // Get the root folder\n .RootFolder() // Expand the files\n .Files() // Execute the request\n .execute(function (files) {\n var _loop_11 = function _loop_11(i) {\n var cfgWebPart = cfgWebParts[i]; // See if the target name exists\n\n if (_cfgType && _targetName) {\n // Ensure it's for this webpart\n if (cfgWebPart.FileName.toLowerCase() != _targetName) {\n return \"continue\";\n }\n } // Get the file\n\n\n var file = isInCollection(\"Name\", cfgWebPart.FileName, files.results);\n\n if (file) {\n // Remove the file\n file.delete().execute(function () {\n // Log\n console.log(\"[gd-sprest][WebPart] The webpart '\" + file.Name + \"' file was removed.\");\n }, true);\n }\n }; // Parse the configuration\n\n\n for (var i = 0; i < cfgWebParts.length; i++) {\n _loop_11(i);\n } // Resolve the promise\n\n\n resolve();\n }, reject);\n });\n }; // Method to update the base permissions\n\n\n var updateBasePermissions = function updateBasePermissions(values) {\n var high = values.High;\n var low = values.Low; // See if this is an array\n\n for (var i = 0; i < values[\"length\"]; i++) {\n var value = values[i]; // See if this is the full mask\n\n if (value == 65) {\n // Set the values\n low = 65535;\n high = 32767; // Break from the loop\n\n break;\n } // Else, see if it's empty\n else if (value == 0) {\n // Clear the values\n low = 0;\n high = 0;\n } // Else, update the base permission\n else {\n var bit = value - 1;\n var bitValue = 1; // Validate the bit\n\n if (bit < 0) {\n continue;\n } // See if it's a low permission\n\n\n if (bit < 32) {\n // Compute the value\n bitValue = bitValue << bit; // Set the low value\n\n low |= bitValue;\n } // Else, it's a high permission\n else {\n // Compute the value\n bitValue = bitValue << bit - 32; // Set the high value\n\n high |= bitValue;\n }\n }\n } // Return the base permission\n\n\n return {\n Low: low.toString(),\n High: high.toString()\n };\n }; // Method to update the lists\n\n\n var updateLists = function updateLists(cfgLists) {\n // Return a promise\n return new Promise(function (resolve, reject) {\n var request = function request(idx, resolve) {\n // Get the list configuration\n var cfgList = cfgLists[idx]; // See if the target name exists\n\n if (_targetName) {\n // Ensure it's for this list\n if (cfgList.ListInformation.Title.toLowerCase() != _targetName) {\n // Update the next list\n request(idx + 1, resolve);\n return;\n }\n } // Ensure the configuration exists\n\n\n if (cfgList) {\n // Get the web\n lib_1.Web(webUrl) // Get the list\n .Lists(cfgList.ListInformation.Title) // Expand the content types, fields and views\n .query({\n Expand: [\"ContentTypes\", \"Fields\", \"UserCustomActions\", \"Views\"]\n }) // Execute the request\n .execute(function (list) {\n // See if the title field is being updated\n if (cfgList.TitleFieldDisplayName) {\n // Parse the fields\n for (var i = 0; i < list.Fields.results.length; i++) {\n var field = list.Fields.results[i]; // See if this is the title field\n\n if (field.InternalName == \"Title\") {\n // See if an update is required\n if (field.Title != cfgList.TitleFieldDisplayName) {\n // Update the field name\n field.update({\n Title: cfgList.TitleFieldDisplayName\n }).execute(function () {\n // Log\n console.log(\"[gd-sprest][List] The 'Title' field's display name was updated to '\" + cfgList.TitleFieldDisplayName + \"'.\");\n });\n }\n }\n }\n } // Create the fields\n\n\n createFields(list.Fields, cfgList.CustomFields).then(function () {\n // Create the content types\n createContentTypes(list.ContentTypes, cfgList.ContentTypes).then(function () {\n // Update the views\n createViews(list.Views, cfgList.ViewInformation).then(function () {\n // Update the views\n createUserCustomActions(list.UserCustomActions, cfgList.UserCustomActions).then(function () {\n // Trigger the event\n cfgList.onUpdated ? cfgList.onUpdated(list) : null; // Update the next list\n\n request(idx + 1, resolve);\n }, reject);\n }, reject);\n }, reject);\n }, reject);\n }, reject);\n } else {\n // Resolve the promise\n resolve();\n }\n }; // Execute the request\n\n\n request(0, resolve);\n });\n }; // Method to update the views\n\n\n var updateViews = function updateViews(views, cfgViews) {\n var counter = 0; // Return a promise\n\n return new Promise(function (resolve, reject) {\n var _loop_12 = function _loop_12(i) {\n var cfgView = cfgViews[i]; // Get the view\n\n var view = views.getByTitle(cfgView.ViewName); // See if the view fields are defined\n\n if (cfgView.ViewFields && cfgView.ViewFields.length > 0) {\n // Log\n console.log(\"[gd-sprest][View] Updating the view fields for the '\" + cfgView.ViewName + \"' view.\"); // Clear the view fields\n\n view.ViewFields().removeAllViewFields().execute(true); // Parse the view fields\n\n for (var i_2 = 0; i_2 < cfgView.ViewFields.length; i_2++) {\n // Add the view field\n view.ViewFields().addViewField(cfgView.ViewFields[i_2]).execute(true);\n }\n } // See if we are updating the view properties\n\n\n if (cfgView.JSLink || cfgView.ViewQuery) {\n var props = {}; // Log\n\n console.log(\"[gd-sprest][View] Updating the view properties for the '\" + cfgView.ViewName + \"' view.\"); // Set the properties\n\n cfgView.JSLink ? props[\"JSLink\"] = cfgView.JSLink : null;\n cfgView.ViewQuery ? props[\"ViewQuery\"] = cfgView.ViewQuery : null; // Update the view\n\n view.update(props).execute(true);\n } // Wait for the requests to complete\n\n\n view.done(function () {\n var args = [];\n\n for (var _i = 0; _i < arguments.length; _i++) {\n args[_i] = arguments[_i];\n } // Log\n\n\n console.log(\"[gd-sprest][View] The updates for the '\" + cfgView.ViewName + \"' view has completed.\"); // Trigger the event\n\n cfgView.onUpdated ? cfgView.onUpdated(view) : null; // See if we are done\n\n if (++counter >= cfgViews.length) {\n // Resolve the promise\n resolve();\n }\n });\n }; // Parse the views\n\n\n for (var i = 0; i < cfgViews.length; i++) {\n _loop_12(i);\n }\n });\n }; // Method to uninstall the site components\n\n\n var uninstallSite = function uninstallSite() {\n // Return a promise\n return new Promise(function (resolve, reject) {\n // Log\n console.log(\"[gd-sprest][uninstall] Loading the site information...\"); // Ensure site actions exist\n\n if (cfg.CustomActionCfg == null || cfg.CustomActionCfg.Site == null) {\n // Resolve the promise\n resolve();\n return;\n } // Get the site\n\n\n lib_1.Site(webUrl) // Expand the user custom actions\n .query({\n Expand: [\"UserCustomActions\"]\n }) // Execute the request\n .execute(function (site) {\n // Remove the user custom actions\n removeUserCustomActions(site.UserCustomActions, cfg.CustomActionCfg ? cfg.CustomActionCfg.Site : []).then(function () {\n // Resolve the promise\n resolve(site);\n });\n }, reject);\n });\n }; // Method to uninstall the web components\n\n\n var uninstallWeb = function uninstallWeb() {\n // Return a promise\n return new Promise(function (resolve, reject) {\n // Log\n console.log(\"[gd-sprest][uninstall] Loading the web information...\"); // Get the web\n\n lib_1.Web(webUrl) // Expand the content types, fields, lists and user custom actions\n .query({\n Expand: [\"ContentTypes\", \"Fields\", \"Lists\", \"UserCustomActions\"]\n }) // Execute the request\n .execute(function (web) {\n // Remove the fields\n removeFields(web.Fields, cfg.Fields).then(function () {\n // Remove the content types\n removeContentTypes(web.ContentTypes, cfg.ContentTypes).then(function () {\n // Remove the lists\n removeLists(web.Lists, cfg.ListCfg).then(function () {\n // Remove the web custom actions\n removeUserCustomActions(web.UserCustomActions, cfg.CustomActionCfg ? cfg.CustomActionCfg.Web : null).then(function () {\n // Resolve the promise\n resolve();\n }, reject);\n }, reject);\n }, reject);\n }, reject);\n }, reject);\n });\n };\n /**\r\n * Public Interface\r\n */\n\n\n return {\n // The configuration\n _configuration: cfg,\n // Method to install the configuration\n install: function install() {\n // Return a promise\n return new Promise(function (resolve, reject) {\n var ctr = 0;\n var ctrExecutions = 0; // Log\n\n console.log(\"[gd-sprest] Loading the web information...\"); // Get the web\n\n var web = lib_1.Web(webUrl); // The post execution method\n\n var postExecute = function postExecute() {\n // See if we have completed the executions\n if (++ctr >= ctrExecutions) {\n // Resolve the promise\n resolve();\n }\n }; // See if we are creating fields\n\n\n if (cfg.Fields && cfg.Fields.length > 0) {\n // Increment the counter\n ctrExecutions++; // Log\n\n console.log(\"[gd-sprest][Fields] Starting the requests.\"); // Get the fields\n\n web.Fields().execute(function (fields) {\n // Return a promise\n return new Promise(function (resolve, reject) {\n // Create the fields\n createFields(_1.parse(fields.stringify()), cfg.Fields).then(function () {\n // Log\n console.log(\"[gd-sprest][Fields] Completed the requests.\"); // Execute the post execute method\n\n postExecute(); // Resolve the promise\n\n resolve();\n }, reject);\n });\n }, reject);\n } // See if we are creating the content types\n\n\n if (cfg.ContentTypes && cfg.ContentTypes.length > 0) {\n // Increment the counter\n ctrExecutions++; // Log\n\n console.log(\"[gd-sprest][Content Types] Starting the requests.\"); // Get the content types\n\n web.ContentTypes().execute(function (contentTypes) {\n // Create the content types\n createContentTypes(_1.parse(contentTypes.stringify()), cfg.ContentTypes).then(function () {\n // Log\n console.log(\"[gd-sprest][Content Types] Completed the requests.\"); // Execute the post execute method\n\n postExecute();\n });\n }, reject, true);\n } // See if we are creating the lists\n\n\n if (cfg.ListCfg && cfg.ListCfg.length) {\n // Increment the counter\n ctrExecutions++; // Log\n\n console.log(\"[gd-sprest][Lists] Starting the requests.\"); // Get the lists\n\n web.Lists().execute(function (lists) {\n // Create the lists\n createLists(_1.parse(lists.stringify()), cfg.ListCfg).then(function () {\n // Log\n console.log(\"[gd-sprest][Lists] Completed the requests.\"); // Execute the post execute method\n\n postExecute();\n });\n }, reject, true);\n } // See if we are creating the webparts\n\n\n if (cfg.WebPartCfg && cfg.WebPartCfg.length > 0) {\n // Increment the counter\n ctrExecutions++; // Log\n\n console.log(\"[gd-sprest][WebParts] Starting the requests.\"); // Create the webparts\n\n createWebParts().then(function () {\n // Log\n console.log(\"[gd-sprest][WebParts] Completed the requests.\"); // Execute the post execute method\n\n postExecute();\n });\n } // See if we are creating custom actions\n\n\n if (cfg.CustomActionCfg) {\n // See if we are targeting the site collection\n if (cfg.CustomActionCfg.Site) {\n // Increment the counter\n ctrExecutions++; // Log\n\n console.log(\"[gd-sprest][Site Custom Actions] Starting the requests.\"); // Get the site\n\n lib_1.Site(webUrl) // Get the user custom actions\n .UserCustomActions().execute(function (customActions) {\n // Create the user custom actions\n createUserCustomActions(_1.parse(customActions.stringify()), cfg.CustomActionCfg.Site).then(function () {\n // Log\n console.log(\"[gd-sprest][Site Custom Actions] Completed the requests.\"); // Execute the post execute method\n\n postExecute();\n });\n });\n } // See if we are targeting the web\n\n\n if (cfg.CustomActionCfg.Web) {\n // Increment the counter\n ctrExecutions++; // Log\n\n console.log(\"[gd-sprest][Web Custom Actions] Starting the requests.\"); // Get the user custom actions\n\n web.UserCustomActions().execute(function (customActions) {\n // Create the user custom actions\n createUserCustomActions(_1.parse(customActions.stringify()), cfg.CustomActionCfg.Web).then(function () {\n // Log\n console.log(\"[gd-sprest][Web Custom Actions] Completed the requests.\"); // Execute the post execute method\n\n postExecute();\n });\n }, reject);\n }\n }\n });\n },\n // Method to uninstall the configuration\n uninstall: function uninstall() {\n // Return a promise\n return new Promise(function (resolve, reject) {\n // Uninstall the web components\n uninstallWeb().then(function () {\n // Uninstall the site components\n uninstallSite().then(function () {\n // Remove the webparts\n removeWebParts().then(function () {\n // Log\n console.log(\"[gd-sprest] The configuration script completed, but some requests may still be running.\"); // Resolve the promise\n\n resolve();\n }, reject);\n }, reject);\n }, reject);\n });\n }\n };\n};\n\n//# sourceURL=webpack:///./build/helper/spCfg.js?"); +eval("\n\nfunction __export(m) {\n for (var p in m) {\n if (!exports.hasOwnProperty(p)) exports[p] = m[p];\n }\n}\n\nObject.defineProperty(exports, \"__esModule\", {\n value: true\n});\n\n__export(__webpack_require__(/*! ./spCfgTypes */ \"./build/helper/spCfgTypes.js\"));\n\nvar lib_1 = __webpack_require__(/*! ../lib */ \"./build/lib/index.js\");\n\nvar __1 = __webpack_require__(/*! .. */ \"./build/index.js\");\n\nvar _1 = __webpack_require__(/*! . */ \"./build/helper/index.js\");\n/**\r\n * SharePoint Configuration\r\n */\n\n\nexports.SPConfig = function (cfg, webUrl) {\n // The selected configuration type to install\n var _cfgType; // The target name to install/uninstall\n\n\n var _targetName;\n /**\r\n * Methods\r\n */\n // Method to create the content types\n\n\n var createContentTypes = function createContentTypes(collection, cfgContentTypes) {\n var contentTypes = collection; // Return a promise\n\n return new Promise(function (resolve, reject) {\n // Ensure fields exist\n if (cfgContentTypes == null || cfgContentTypes.length == 0) {\n // Resolve the promise\n resolve();\n return;\n }\n\n var _loop_1 = function _loop_1(i) {\n var cfgContentType = cfgContentTypes[i]; // See if this content type already exists\n\n var ct = isInCollection(\"Name\", cfgContentType.Name, collection.results);\n\n if (ct) {\n // Log\n console.log(\"[gd-sprest][Content Type] The content type '\" + cfgContentType.Name + \"' already exists.\"); // Update the configuration\n\n cfgContentType.ContentType = ct;\n } else {\n // Log\n console.log(\"[gd-sprest][Content Type] Creating the '\" + cfgContentType.Name + \"' content type.\"); // See if the parent name exists\n\n if (cfgContentType.ParentName) {\n // Get the web containing the parent content type\n lib_1.Web(cfgContentType.ParentWebUrl || webUrl) // Get the content types\n .ContentTypes() // Filter for the parent name\n .query({\n Filter: \"Name eq '\" + cfgContentType.ParentName + \"'\"\n }).execute(function (parent) {\n // See if the parent exists\n if (parent.results[0]) {\n // Add the available content type\n contentTypes.addAvailableContentType(parent.results[0].Id.StringValue).execute(function (ct) {\n // See if it was successful\n if (ct.existsFl) {\n // Update the name\n (function () {\n return new Promise(function (resolve, reject) {\n // Ensure the name doesn't need to be updated\n if (ct.Name != cfgContentType.Name) {\n ct.update({\n Name: cfgContentType.Name\n }).execute(function () {\n // Resolve the promise\n resolve();\n });\n } else {\n // Resolve the promise\n resolve();\n }\n });\n })().then(function () {\n // Log\n console.log(\"[gd-sprest][Content Type] The content type '\" + cfgContentType.Name + \"' was created successfully.\"); // Update the configuration\n\n cfgContentType.ContentType = ct; // Trigger the event\n\n cfgContentType.onCreated ? cfgContentType.onCreated(ct) : null;\n });\n } else {\n // Log\n console.log(\"[gd-sprest][Content Type] The content type '\" + cfgContentType.Name + \"' failed to be created.\");\n console.error(\"[gd-sprest][Field] Error: \" + ct.response);\n }\n }, true);\n } else {\n // Log\n console.log(\"[gd-sprest][Content Type] The parent content type '\" + cfgContentType.Name + \"' was not found.\");\n }\n }, reject);\n } else {\n // Create the content type\n contentTypes.add({\n Description: cfgContentType.Description,\n Group: cfgContentType.Group,\n\n /*\r\n Id: {\r\n __metadata: { type: \"SP.ContentTypeId\" },\r\n StringValue: cfgContentType.Id ? cfgContentType.Id.StringValue : \"0x0100\" + ContextInfo.generateGUID().replace(\"{\", \"\").replace(\"-\", \"\").replace(\"}\", \"\")\r\n },\r\n */\n Id: cfgContentType.Id || \"0x0100\" + lib_1.ContextInfo.generateGUID().replace(\"{\", \"\").replace(\"-\", \"\").replace(\"}\", \"\"),\n Name: cfgContentType.Name\n }).execute(function (ct) {\n // See if it was successful\n if (ct.existsFl) {\n // Log\n console.log(\"[gd-sprest][Content Type] The content type '\" + cfgContentType.Name + \"' was created successfully.\"); // Update the configuration\n\n cfgContentType.ContentType = ct; // Trigger the event\n\n cfgContentType.onCreated ? cfgContentType.onCreated(ct) : null;\n } else {\n // Log\n console.log(\"[gd-sprest][Content Type] The content type '\" + cfgContentType.Name + \"' failed to be created.\");\n console.error(\"[gd-sprest][Field] Error: \" + ct.response);\n }\n }, reject, true);\n }\n }\n }; // Parse the configuration\n\n\n for (var i = 0; i < cfgContentTypes.length; i++) {\n _loop_1(i);\n } // Wait for the requests to complete\n\n\n contentTypes.done(function () {\n var _loop_2 = function _loop_2(i) {\n var cfgContentType = cfgContentTypes[i];\n var cfgUpdate = {};\n var updateFl = false; // Ensure the content type exists\n\n if (cfgContentType.ContentType == null) {\n return \"continue\";\n }\n /**\r\n * See if we need to update the properties\r\n */\n // Description\n\n\n if (cfgContentType.ContentType.Description != cfgContentType.Description) {\n // Update the configuration\n cfgUpdate.Description = cfgContentType.Description; // Log\n\n console.log(\"[gd-sprest][Content Type][\" + cfgContentType.ContentType.Name + \"] Description requires update.\"); // Set the flag\n\n updateFl = true;\n } // Group\n\n\n if (cfgContentType.ContentType.Group != cfgContentType.Group) {\n // Update the configuration\n cfgUpdate.Group = cfgContentType.Group; // Log\n\n console.log(\"[gd-sprest][Content Type][\" + cfgContentType.ContentType.Name + \"] Group requires update.\"); // Set the flag\n\n updateFl = true;\n } // JSLink\n\n\n if (cfgContentType.ContentType.JSLink != cfgContentType.JSLink) {\n // Update the configuration\n cfgUpdate.JSLink = cfgContentType.JSLink; // Log\n\n console.log(\"[gd-sprest][Content Type][\" + cfgContentType.ContentType.Name + \"] JSLink requires update.\"); // Set the flag\n\n updateFl = true;\n } // Name\n\n\n if (cfgContentType.ContentType.Name != cfgContentType.Name) {\n // Update the configuration\n cfgUpdate.Name = cfgContentType.Name; // Log\n\n console.log(\"[gd-sprest][Content Type][\" + cfgContentType.ContentType.Name + \"] Name requires update.\"); // Set the flag\n\n updateFl = true;\n } // See if an update is needed\n\n\n if (updateFl) {\n // Log\n console.log(\"[gd-sprest][Content Type][\" + cfgContentType.ContentType.Name + \"] Updating the webpart.\"); // Update the content type\n\n cfgContentType.ContentType.update({\n JSLink: cfgContentType.JSLink\n }).execute(function () {\n // Log\n console.log(\"[gd-sprest][Content Type][\" + cfgContentType.ContentType.Name + \"] Update request completed.\"); // Trigger the event\n\n cfgContentType.onUpdated ? cfgContentType.onUpdated(cfgContentType.ContentType) : null;\n });\n } else {\n // Trigger the event\n cfgContentType.onUpdated ? cfgContentType.onUpdated(cfgContentType.ContentType) : null;\n }\n }; // Parse the configuration\n\n\n for (var i = 0; i < cfgContentTypes.length; i++) {\n _loop_2(i);\n } // Wait for the requests to complete\n\n\n contentTypes.done(function () {\n // Resolve the promise\n resolve();\n });\n });\n });\n }; // Method to create the fields`\n\n\n var createFields = function createFields(collection, cfgFields) {\n var fields = collection; // Return a promise\n\n return new Promise(function (resolve, reject) {\n // Ensure fields exist\n if (cfgFields == null || cfgFields.length == 0) {\n // Resolve the promise\n resolve();\n return;\n }\n\n var _loop_3 = function _loop_3(i) {\n var cfgField = cfgFields[i]; // See if this field already exists\n\n var field = isInCollection(\"InternalName\", cfgField.name, collection.results);\n\n if (field) {\n // Log\n console.log(\"[gd-sprest][Field] The field '\" + cfgField.name + \"' already exists.\"); // Trigger the event\n\n cfgField.onUpdated ? cfgField.onUpdated(field) : null;\n } else {\n // Log\n console.log(\"[gd-sprest][Field] Creating the '\" + cfgField.name + \"' field.\"); // The field created event\n\n var onFieldCreated_1 = function onFieldCreated_1(field) {\n // See if it was successful\n if (field.existsFl) {\n // Log\n console.log(\"[gd-sprest][Field] The field '\" + field.InternalName + \"' was created successfully.\"); // Trigger the event\n\n cfgField.onCreated ? cfgField.onCreated(field) : null;\n } else {\n // Log\n console.log(\"[gd-sprest][Field] The field '\" + cfgField.name + \"' failed to be created.\");\n console.error(\"[gd-sprest][Field] Error: \" + field.response);\n }\n }; // Compute the schema xml\n\n\n _1.FieldSchemaXML(cfgField).then(function (response) {\n var schemas = typeof response === \"string\" ? [response] : response; // Parse the fields to add\n\n for (var i_1 = 0; i_1 < schemas.length; i_1++) {\n // Add the field\n fields.createFieldAsXml(schemas[i_1]).execute(onFieldCreated_1, true);\n }\n });\n }\n }; // Parse the fields\n\n\n for (var i = 0; i < cfgFields.length; i++) {\n _loop_3(i);\n } // Wait for the requests to complete\n\n\n fields.done(function () {\n // Resolve the promise\n resolve();\n });\n });\n }; // Method to create the lists\n\n\n var createLists = function createLists(collection, cfgLists) {\n var lists = collection; // Return a promise\n\n return new Promise(function (resolve, reject) {\n var _loop_4 = function _loop_4(i) {\n var cfgList = cfgLists[i]; // See if the target name exists\n\n if (_cfgType && _targetName) {\n // Ensure it's for this list\n if (cfgList.ListInformation.Title.toLowerCase() != _targetName) {\n return \"continue\";\n }\n } // See if this content type already exists\n\n\n var list = isInCollection(\"Title\", cfgList.ListInformation.Title, collection.results);\n\n if (list) {\n // Log\n console.log(\"[gd-sprest][List] The list '\" + cfgList.ListInformation.Title + \"' already exists.\");\n } else {\n // Log\n console.log(\"[gd-sprest][List] Creating the '\" + cfgList.ListInformation.Title + \"' list.\"); // Update the list name and remove spaces\n\n var listInfo_1 = cfgList.ListInformation;\n var listName_1 = listInfo_1.Title;\n listInfo_1.Title = listName_1.replace(/ /g, \"\"); // Add the list\n\n lists.add(listInfo_1) // Execute the request\n .execute(function (list) {\n // Restore the list name in the configuration\n listInfo_1.Title = listName_1; // See if the request was successful\n\n if (list.existsFl) {\n // See if we need to update the list\n if (list.existsFl && list.Title != listName_1) {\n // Update the list\n list.update({\n Title: listName_1\n }).execute(function () {\n // Log\n console.log(\"[gd-sprest][List] The list '\" + list.Title + \"' was created successfully.\");\n });\n } else {\n // Log\n console.log(\"[gd-sprest][List] The list '\" + list.Title + \"' was created successfully.\");\n } // Trigger the event\n\n\n cfgList.onCreated ? cfgList.onCreated(list) : null;\n } else {\n // Log\n console.log(\"[gd-sprest][List] The list '\" + listInfo_1.Title + \"' failed to be created.\");\n console.log(\"[gd-sprest][List] Error: '\" + list.response);\n }\n }, reject);\n }\n }; // Parse the content types\n\n\n for (var i = 0; i < cfgLists.length; i++) {\n _loop_4(i);\n } // Wait for the requests to complete\n\n\n lists.done(function () {\n // Update the lists\n updateLists(cfgLists).then(function () {\n // Resolve the promise\n resolve();\n });\n });\n });\n }; // Method to create the user custom actions\n\n\n var createUserCustomActions = function createUserCustomActions(collection, cfgCustomActions) {\n var customActions = collection; // Return a promise\n\n return new Promise(function (resolve, reject) {\n // See if the configuration type exists\n if (_cfgType) {\n // Ensure it's for this type\n if (_cfgType != _1.SPCfgType.SiteUserCustomActions || _cfgType != _1.SPCfgType.WebUserCustomActions) {\n // Resolve the promise\n resolve();\n return;\n }\n } // Ensure the lists exist\n\n\n if (cfgCustomActions == null || cfgCustomActions.length == 0) {\n // Resolve the promise and return it\n resolve();\n return;\n } // Parse the custom actions\n\n\n for (var i = 0; i < cfgCustomActions.length; i++) {\n var cfgCustomAction = cfgCustomActions[i]; // See if the target name exists\n\n if (_cfgType && _targetName) {\n // Ensure it's for this custom action\n if (cfgCustomAction.Name.toLowerCase() != _targetName || cfgCustomAction.Title.toLowerCase() != _targetName) {\n // Skip this custom action\n continue;\n }\n } // See if this custom action already exists\n\n\n if (isInCollection(\"Name\", cfgCustomAction.Name, collection.results)) {\n // Log\n console.log(\"[gd-sprest][Custom Action] The custom action '\" + cfgCustomAction.Name + \"' already exists.\");\n } else {\n // See if rights exist\n if (cfgCustomAction.Rights) {\n // Update the value\n cfgCustomAction.Rights = updateBasePermissions(cfgCustomAction.Rights);\n } // Add the custom action\n\n\n customActions.add(cfgCustomAction).execute(function (ca) {\n // Ensure it exists\n if (ca.existsFl) {\n // Log\n console.log(\"[gd-sprest][Custom Action] The custom action '\" + ca.Name + \"' was created successfully.\");\n } else {\n // Log\n console.log(\"[gd-sprest][Custom Action] The custom action '\" + ca.Name + \"' failed to be created.\");\n console.log(\"[gd-sprest][Custom Action] Error: \" + ca.response);\n }\n }, reject, true);\n }\n } // Wait for the requests to complete\n\n\n customActions.done(function () {\n // Resolve the promise\n resolve();\n });\n });\n }; // Method to create the list views\n\n\n var createViews = function createViews(collection, cfgViews) {\n var views = collection; // Return a promise\n\n return new Promise(function (resolve, reject) {\n // Ensure the list views exist\n if (cfgViews == null || cfgViews.length == 0) {\n // Resolve the promise and return it\n resolve();\n return;\n }\n\n var _loop_5 = function _loop_5(i) {\n var cfgView = cfgViews[i]; // See if this view exists\n\n var view = isInCollection(\"Title\", cfgView.ViewName, collection.results);\n\n if (view) {\n // Log\n console.log(\"[gd-sprest][View] The view '\" + cfgView.ViewName + \"' already exists.\");\n } else {\n // Add the view\n views.add({\n Title: cfgView.ViewName,\n ViewQuery: cfgView.ViewQuery\n }).execute(function (view) {\n // Ensure it exists\n if (view.existsFl) {\n // Log\n console.log(\"[gd-sprest][View] The view '\" + cfgView.ViewName + \"' was created successfully.\"); // Trigger the event\n\n cfgView.onCreated ? cfgView.onCreated(view) : null;\n } else {\n // Log\n console.log(\"[gd-sprest][View] The view '\" + cfgView.ViewName + \"' failed to be created.\");\n console.log(\"[gd-sprest][View] Error: \" + view.response);\n }\n }, reject, true);\n }\n }; // Parse the views\n\n\n for (var i = 0; i < cfgViews.length; i++) {\n _loop_5(i);\n } // Wait for the requests to complete\n\n\n views.done(function () {\n // Update the views\n updateViews(collection, cfgViews).then(function () {\n // Resolve the promise\n resolve();\n });\n });\n });\n }; // Method to create the web parts\n\n\n var createWebParts = function createWebParts() {\n // Return a promise\n return new Promise(function (resolve, reject) {\n var cfgWebParts = cfg.WebPartCfg; // Log\n\n console.log(\"[gd-sprest][WebPart] Creating the web parts.\"); // Get the root web\n\n lib_1.Web(lib_1.ContextInfo.siteServerRelativeUrl) // Get the web part catalog\n .getCatalog(__1.SPTypes.ListTemplateType.WebPartCatalog) // Get the root folder\n .RootFolder() // Expand the files and items\n .query({\n Expand: [\"Files\"]\n }) // Execute the request\n .execute(function (folder) {\n var ctr = 0;\n\n var _loop_6 = function _loop_6(i) {\n var cfgWebPart = cfgWebParts[i]; // See if the target name exists\n\n if (_cfgType && _targetName) {\n // Ensure it's for this list\n if (cfgWebPart.FileName.toLowerCase() != _targetName) {\n return \"continue\";\n }\n } // The post execute method\n\n\n var postExecute = function postExecute() {\n // Increment the counter\n if (++ctr >= cfgWebParts.length) {\n // Resolve the promise\n resolve();\n }\n }; // See if this webpart exists\n\n\n var file = isInCollection(\"Name\", cfgWebPart.FileName, folder.Files.results);\n\n if (file.existsFl) {\n // Log\n console.log(\"[gd-sprest][WebPart] The webpart '\" + cfgWebPart.FileName + \"' already exists.\"); // Trigger the event\n\n cfgWebPart.onUpdated ? cfgWebPart.onUpdated(file) : null; // Execute the post event\n\n postExecute();\n } else {\n // Trim the xml\n var xml = cfgWebPart.XML.trim(); // Convert the string to an array buffer\n\n var buffer = new ArrayBuffer(xml.length * 2);\n var bufferView = new Uint16Array(buffer);\n\n for (var j = 0; j < xml.length; j++) {\n bufferView[j] = xml.charCodeAt(j);\n } // Create the webpart, but execute the requests one at a time\n\n\n folder.Files.add(true, cfgWebPart.FileName, buffer).execute(function (file) {\n // See if group exists\n if (cfgWebPart.Group) {\n // Set the target to the root web\n lib_1.Web(lib_1.ContextInfo.siteServerRelativeUrl) // Get the web part catalog\n .getCatalog(__1.SPTypes.ListTemplateType.WebPartCatalog) // Get the Items\n .Items() // Query for this webpart\n .query({\n Filter: \"FileLeafRef eq '\" + cfgWebPart.FileName + \"'\"\n }) // Execute the request\n .execute(function (items) {\n // Update the item\n items.results[0].update({\n Group: cfgWebPart.Group\n }).execute(postExecute);\n });\n } // Log\n\n\n console.log(\"[gd-sprest][WebPart] The '\" + file.Name + \"' webpart file was uploaded successfully.\"); // Trigger the event\n\n cfgWebPart.onCreated ? cfgWebPart.onCreated(file) : null;\n });\n }\n }; // Parse the configuration\n\n\n for (var i = 0; i < cfgWebParts.length; i++) {\n _loop_6(i);\n }\n }, reject);\n });\n }; // Method to see if an object exists in a collection\n\n\n var isInCollection = function isInCollection(key, value, collection) {\n var valueLower = value.toLowerCase(); // Parse the collection\n\n for (var i = 0; i < collection.length; i++) {\n var keyValue = collection[i][key];\n keyValue = keyValue ? keyValue.toLowerCase() : \"\"; // See if the item exists\n\n if (valueLower == keyValue) {\n // Return true\n return collection[i];\n }\n } // Not in the collection\n\n\n return false;\n }; // Method to remove the content type\n\n\n var removeContentTypes = function removeContentTypes(collection, cfgContentTypes) {\n var contentTypes = collection; // Return a promise\n\n return new Promise(function (resolve, reject) {\n // Ensure the content types exist\n if (cfgContentTypes == null || cfgContentTypes.length == 0) {\n // Resolve the promise and return it\n resolve();\n return;\n }\n\n var _loop_7 = function _loop_7(i) {\n var cfgContentType = cfgContentTypes[i]; // Get the field\n\n var ct = isInCollection(\"Name\", cfgContentType.Name, collection.results);\n\n if (ct) {\n // Remove the field\n ct.delete().execute(function () {\n // Log\n console.log(\"[gd-sprest][Field] The content type '\" + ct.Name + \"' was removed.\");\n }, reject, true);\n }\n }; // Parse the configuration\n\n\n for (var i = 0; i < cfgContentTypes.length; i++) {\n _loop_7(i);\n } // Wait for the requests to complete\n\n\n contentTypes.done(function () {\n // Resolve the promise\n resolve();\n });\n });\n }; // Method to remove the fields\n\n\n var removeFields = function removeFields(collection, cfgFields) {\n var fields = collection; // Return a promise\n\n return new Promise(function (resolve, reject) {\n // Ensure the fields exist\n if (cfgFields == null || cfgFields.length == 0) {\n // Resolve the promise and return it\n resolve();\n return;\n }\n\n var _loop_8 = function _loop_8(i) {\n var cfgField = cfgFields[i]; // Get the field\n\n var field = isInCollection(\"InternalName\", cfgField.name, collection.results);\n\n if (field) {\n // Remove the field\n field.delete().execute(function () {\n // Log\n console.log(\"[gd-sprest][Field] The field '\" + field.InternalName + \"' was removed.\");\n }, reject, true);\n }\n }; // Parse the configuration\n\n\n for (var i = 0; i < cfgFields.length; i++) {\n _loop_8(i);\n } // Wait for the requests to complete\n\n\n fields.done(function () {\n // Resolve the promise\n resolve();\n });\n });\n }; // Method to remove the lists\n\n\n var removeLists = function removeLists(collection, cfgLists) {\n var lists = collection; // Return a promise\n\n return new Promise(function (resolve, reject) {\n // See if the configuration type exists\n if (_cfgType) {\n // Ensure it's for this type\n if (_cfgType != _1.SPCfgType.Lists) {\n // Resolve the promise\n resolve();\n return;\n }\n } // Ensure the lists exist\n\n\n if (cfgLists == null || cfgLists.length == 0) {\n // Resolve the promise and return it\n resolve();\n return;\n }\n\n var _loop_9 = function _loop_9(i) {\n var cfgList = cfgLists[i]; // See if the target name exists\n\n if (_cfgType && _targetName) {\n // Ensure it's for this list\n if (cfgList.ListInformation.Title.toLowerCase() != _targetName) {\n return \"continue\";\n }\n } // Get the list\n\n\n var list = isInCollection(\"Title\", cfgList.ListInformation.Title, collection.results);\n\n if (list) {\n // Remove the list\n list.delete().execute(function () {\n // Log\n console.log(\"[gd-sprest][List] The list '\" + list.Title + \"' was removed.\");\n }, reject, true);\n }\n }; // Parse the configuration\n\n\n for (var i = 0; i < cfgLists.length; i++) {\n _loop_9(i);\n } // Wait for the requests to complete\n\n\n lists.done(function () {\n // Resolve the promise\n resolve();\n });\n });\n }; // Method to remove the user custom actions\n\n\n var removeUserCustomActions = function removeUserCustomActions(collection, cfgCustomActions) {\n var customActions = collection; // Return a promise\n\n return new Promise(function (resolve, reject) {\n // See if the configuration type exists\n if (_cfgType) {\n // Ensure it's for this type\n if (_cfgType != _1.SPCfgType.SiteUserCustomActions || _cfgType != _1.SPCfgType.WebUserCustomActions) {\n // Resolve the promise\n resolve();\n return;\n }\n } // Ensure the custom actions exist\n\n\n if (cfgCustomActions == null || cfgCustomActions.length == 0) {\n // Resolve the promise and return it\n resolve();\n return;\n }\n\n var _loop_10 = function _loop_10(i) {\n var cfgCustomAction = cfgCustomActions[i]; // See if the target name exists\n\n if (_cfgType && _targetName) {\n // Ensure it's for this custom action\n if (cfgCustomAction.Name.toLowerCase() != _targetName || cfgCustomAction.Title.toLowerCase() != _targetName) {\n return \"continue\";\n }\n } // Get the custom action\n\n\n var ca = isInCollection(\"Name\", cfgCustomAction.Name, collection.results);\n\n if (ca) {\n // Remove the custom action\n ca.delete().execute(function () {\n // Log\n console.log(\"[gd-sprest][Custom Action] The custom action '\" + ca.Name + \"' was removed.\");\n }, reject, true);\n }\n }; // Parse the configuration\n\n\n for (var i = 0; i < cfgCustomActions.length; i++) {\n _loop_10(i);\n } // Wait for the requests to complete\n\n\n customActions.done(function () {\n // Resolve the promise\n resolve();\n });\n });\n }; // Method to remove the web parts\n\n\n var removeWebParts = function removeWebParts() {\n var cfgWebParts = cfg.WebPartCfg; // Return a promise\n\n return new Promise(function (resolve, reject) {\n // See if the configuration type exists\n if (_cfgType) {\n // Ensure it's for this type\n if (_cfgType != _1.SPCfgType.WebParts) {\n // Resolve the promise\n resolve();\n return;\n }\n } // Ensure the configuration exists\n\n\n if (cfgWebParts == null || cfgWebParts.length == 0) {\n // Resolve the promise and return it\n resolve();\n return;\n } // Log\n\n\n console.log(\"[gd-sprest][WebPart] Removing the web parts.\"); // Get the root web\n\n lib_1.Web(lib_1.ContextInfo.siteServerRelativeUrl) // Get the webpart gallery\n .getCatalog(__1.SPTypes.ListTemplateType.WebPartCatalog) // Get the root folder\n .RootFolder() // Expand the files\n .Files() // Execute the request\n .execute(function (files) {\n var _loop_11 = function _loop_11(i) {\n var cfgWebPart = cfgWebParts[i]; // See if the target name exists\n\n if (_cfgType && _targetName) {\n // Ensure it's for this webpart\n if (cfgWebPart.FileName.toLowerCase() != _targetName) {\n return \"continue\";\n }\n } // Get the file\n\n\n var file = isInCollection(\"Name\", cfgWebPart.FileName, files.results);\n\n if (file) {\n // Remove the file\n file.delete().execute(function () {\n // Log\n console.log(\"[gd-sprest][WebPart] The webpart '\" + file.Name + \"' file was removed.\");\n }, true);\n }\n }; // Parse the configuration\n\n\n for (var i = 0; i < cfgWebParts.length; i++) {\n _loop_11(i);\n } // Resolve the promise\n\n\n resolve();\n }, reject);\n });\n }; // Method to update the base permissions\n\n\n var updateBasePermissions = function updateBasePermissions(values) {\n var high = values.High;\n var low = values.Low; // See if this is an array\n\n for (var i = 0; i < values[\"length\"]; i++) {\n var value = values[i]; // See if this is the full mask\n\n if (value == 65) {\n // Set the values\n low = 65535;\n high = 32767; // Break from the loop\n\n break;\n } // Else, see if it's empty\n else if (value == 0) {\n // Clear the values\n low = 0;\n high = 0;\n } // Else, update the base permission\n else {\n var bit = value - 1;\n var bitValue = 1; // Validate the bit\n\n if (bit < 0) {\n continue;\n } // See if it's a low permission\n\n\n if (bit < 32) {\n // Compute the value\n bitValue = bitValue << bit; // Set the low value\n\n low |= bitValue;\n } // Else, it's a high permission\n else {\n // Compute the value\n bitValue = bitValue << bit - 32; // Set the high value\n\n high |= bitValue;\n }\n }\n } // Return the base permission\n\n\n return {\n Low: low.toString(),\n High: high.toString()\n };\n }; // Method to update the lists\n\n\n var updateLists = function updateLists(cfgLists) {\n // Return a promise\n return new Promise(function (resolve, reject) {\n var request = function request(idx, resolve) {\n // Get the list configuration\n var cfgList = cfgLists[idx]; // See if the target name exists\n\n if (_targetName) {\n // Ensure it's for this list\n if (cfgList.ListInformation.Title.toLowerCase() != _targetName) {\n // Update the next list\n request(idx + 1, resolve);\n return;\n }\n } // Ensure the configuration exists\n\n\n if (cfgList) {\n // Get the web\n lib_1.Web(webUrl) // Get the list\n .Lists(cfgList.ListInformation.Title) // Expand the content types, fields and views\n .query({\n Expand: [\"ContentTypes\", \"Fields\", \"UserCustomActions\", \"Views\"]\n }) // Execute the request\n .execute(function (list) {\n // See if the title field is being updated\n if (cfgList.TitleFieldDisplayName) {\n // Parse the fields\n for (var i = 0; i < list.Fields.results.length; i++) {\n var field = list.Fields.results[i]; // See if this is the title field\n\n if (field.InternalName == \"Title\") {\n // See if an update is required\n if (field.Title != cfgList.TitleFieldDisplayName) {\n // Update the field name\n field.update({\n Title: cfgList.TitleFieldDisplayName\n }).execute(function () {\n // Log\n console.log(\"[gd-sprest][List] The 'Title' field's display name was updated to '\" + cfgList.TitleFieldDisplayName + \"'.\");\n });\n }\n }\n }\n } // Create the fields\n\n\n createFields(list.Fields, cfgList.CustomFields).then(function () {\n // Create the content types\n createContentTypes(list.ContentTypes, cfgList.ContentTypes).then(function () {\n // Update the views\n createViews(list.Views, cfgList.ViewInformation).then(function () {\n // Update the views\n createUserCustomActions(list.UserCustomActions, cfgList.UserCustomActions).then(function () {\n // Trigger the event\n cfgList.onUpdated ? cfgList.onUpdated(list) : null; // Update the next list\n\n request(idx + 1, resolve);\n }, reject);\n }, reject);\n }, reject);\n }, reject);\n }, reject);\n } else {\n // Resolve the promise\n resolve();\n }\n }; // Execute the request\n\n\n request(0, resolve);\n });\n }; // Method to update the views\n\n\n var updateViews = function updateViews(views, cfgViews) {\n var counter = 0; // Return a promise\n\n return new Promise(function (resolve, reject) {\n var _loop_12 = function _loop_12(i) {\n var cfgView = cfgViews[i]; // Get the view\n\n var view = views.getByTitle(cfgView.ViewName); // See if the view fields are defined\n\n if (cfgView.ViewFields && cfgView.ViewFields.length > 0) {\n // Log\n console.log(\"[gd-sprest][View] Updating the view fields for the '\" + cfgView.ViewName + \"' view.\"); // Clear the view fields\n\n view.ViewFields().removeAllViewFields().execute(true); // Parse the view fields\n\n for (var i_2 = 0; i_2 < cfgView.ViewFields.length; i_2++) {\n // Add the view field\n view.ViewFields().addViewField(cfgView.ViewFields[i_2]).execute(true);\n }\n } // See if we are updating the view properties\n\n\n if (cfgView.JSLink || cfgView.ViewQuery) {\n var props = {}; // Log\n\n console.log(\"[gd-sprest][View] Updating the view properties for the '\" + cfgView.ViewName + \"' view.\"); // Set the properties\n\n cfgView.JSLink ? props[\"JSLink\"] = cfgView.JSLink : null;\n cfgView.ViewQuery ? props[\"ViewQuery\"] = cfgView.ViewQuery : null; // Update the view\n\n view.update(props).execute(true);\n } // Wait for the requests to complete\n\n\n view.done(function () {\n var args = [];\n\n for (var _i = 0; _i < arguments.length; _i++) {\n args[_i] = arguments[_i];\n } // Log\n\n\n console.log(\"[gd-sprest][View] The updates for the '\" + cfgView.ViewName + \"' view has completed.\"); // Trigger the event\n\n cfgView.onUpdated ? cfgView.onUpdated(view) : null; // See if we are done\n\n if (++counter >= cfgViews.length) {\n // Resolve the promise\n resolve();\n }\n });\n }; // Parse the views\n\n\n for (var i = 0; i < cfgViews.length; i++) {\n _loop_12(i);\n }\n });\n }; // Method to uninstall the site components\n\n\n var uninstallSite = function uninstallSite() {\n // Return a promise\n return new Promise(function (resolve, reject) {\n // Log\n console.log(\"[gd-sprest][uninstall] Loading the site information...\"); // Ensure site actions exist\n\n if (cfg.CustomActionCfg == null || cfg.CustomActionCfg.Site == null) {\n // Resolve the promise\n resolve();\n return;\n } // Get the site\n\n\n lib_1.Site(webUrl) // Expand the user custom actions\n .query({\n Expand: [\"UserCustomActions\"]\n }) // Execute the request\n .execute(function (site) {\n // Remove the user custom actions\n removeUserCustomActions(site.UserCustomActions, cfg.CustomActionCfg ? cfg.CustomActionCfg.Site : []).then(function () {\n // Resolve the promise\n resolve(site);\n });\n }, reject);\n });\n }; // Method to uninstall the web components\n\n\n var uninstallWeb = function uninstallWeb() {\n // Return a promise\n return new Promise(function (resolve, reject) {\n // Log\n console.log(\"[gd-sprest][uninstall] Loading the web information...\"); // Get the web\n\n lib_1.Web(webUrl) // Expand the content types, fields, lists and user custom actions\n .query({\n Expand: [\"ContentTypes\", \"Fields\", \"Lists\", \"UserCustomActions\"]\n }) // Execute the request\n .execute(function (web) {\n // Remove the fields\n removeFields(web.Fields, cfg.Fields).then(function () {\n // Remove the content types\n removeContentTypes(web.ContentTypes, cfg.ContentTypes).then(function () {\n // Remove the lists\n removeLists(web.Lists, cfg.ListCfg).then(function () {\n // Remove the web custom actions\n removeUserCustomActions(web.UserCustomActions, cfg.CustomActionCfg ? cfg.CustomActionCfg.Web : null).then(function () {\n // Resolve the promise\n resolve();\n }, reject);\n }, reject);\n }, reject);\n }, reject);\n }, reject);\n });\n };\n /**\r\n * Public Interface\r\n */\n\n\n return {\n // The configuration\n _configuration: cfg,\n // Method to install the configuration\n install: function install() {\n // Return a promise\n return new Promise(function (resolve, reject) {\n var ctr = 0;\n var ctrExecutions = 0; // Log\n\n console.log(\"[gd-sprest] Loading the web information...\"); // Get the web\n\n var web = lib_1.Web(webUrl); // The post execution method\n\n var postExecute = function postExecute() {\n // See if we have completed the executions\n if (++ctr >= ctrExecutions) {\n // Resolve the promise\n resolve();\n }\n }; // See if we are creating fields\n\n\n if (cfg.Fields && cfg.Fields.length > 0) {\n // Increment the counter\n ctrExecutions++; // Log\n\n console.log(\"[gd-sprest][Fields] Starting the requests.\"); // Get the fields\n\n web.Fields().execute(function (fields) {\n // Return a promise\n return new Promise(function (resolve, reject) {\n // Create the fields\n createFields(_1.parse(fields.stringify()), cfg.Fields).then(function () {\n // Log\n console.log(\"[gd-sprest][Fields] Completed the requests.\"); // Execute the post execute method\n\n postExecute(); // Resolve the promise\n\n resolve();\n }, reject);\n });\n }, reject);\n } // See if we are creating the content types\n\n\n if (cfg.ContentTypes && cfg.ContentTypes.length > 0) {\n // Increment the counter\n ctrExecutions++; // Log\n\n console.log(\"[gd-sprest][Content Types] Starting the requests.\"); // Get the content types\n\n web.ContentTypes().execute(function (contentTypes) {\n // Create the content types\n createContentTypes(_1.parse(contentTypes.stringify()), cfg.ContentTypes).then(function () {\n // Log\n console.log(\"[gd-sprest][Content Types] Completed the requests.\"); // Execute the post execute method\n\n postExecute();\n });\n }, reject, true);\n } // See if we are creating the lists\n\n\n if (cfg.ListCfg && cfg.ListCfg.length) {\n // Increment the counter\n ctrExecutions++; // Log\n\n console.log(\"[gd-sprest][Lists] Starting the requests.\"); // Get the lists\n\n web.Lists().execute(function (lists) {\n // Create the lists\n createLists(_1.parse(lists.stringify()), cfg.ListCfg).then(function () {\n // Log\n console.log(\"[gd-sprest][Lists] Completed the requests.\"); // Execute the post execute method\n\n postExecute();\n });\n }, reject, true);\n } // See if we are creating the webparts\n\n\n if (cfg.WebPartCfg && cfg.WebPartCfg.length > 0) {\n // Increment the counter\n ctrExecutions++; // Log\n\n console.log(\"[gd-sprest][WebParts] Starting the requests.\"); // Create the webparts\n\n createWebParts().then(function () {\n // Log\n console.log(\"[gd-sprest][WebParts] Completed the requests.\"); // Execute the post execute method\n\n postExecute();\n });\n } // See if we are creating custom actions\n\n\n if (cfg.CustomActionCfg) {\n // See if we are targeting the site collection\n if (cfg.CustomActionCfg.Site) {\n // Increment the counter\n ctrExecutions++; // Log\n\n console.log(\"[gd-sprest][Site Custom Actions] Starting the requests.\"); // Get the site\n\n lib_1.Site(webUrl) // Get the user custom actions\n .UserCustomActions().execute(function (customActions) {\n // Create the user custom actions\n createUserCustomActions(_1.parse(customActions.stringify()), cfg.CustomActionCfg.Site).then(function () {\n // Log\n console.log(\"[gd-sprest][Site Custom Actions] Completed the requests.\"); // Execute the post execute method\n\n postExecute();\n });\n });\n } // See if we are targeting the web\n\n\n if (cfg.CustomActionCfg.Web) {\n // Increment the counter\n ctrExecutions++; // Log\n\n console.log(\"[gd-sprest][Web Custom Actions] Starting the requests.\"); // Get the user custom actions\n\n web.UserCustomActions().execute(function (customActions) {\n // Create the user custom actions\n createUserCustomActions(_1.parse(customActions.stringify()), cfg.CustomActionCfg.Web).then(function () {\n // Log\n console.log(\"[gd-sprest][Web Custom Actions] Completed the requests.\"); // Execute the post execute method\n\n postExecute();\n });\n }, reject);\n }\n }\n });\n },\n // Method to uninstall the configuration\n uninstall: function uninstall() {\n // Return a promise\n return new Promise(function (resolve, reject) {\n // Uninstall the web components\n uninstallWeb().then(function () {\n // Uninstall the site components\n uninstallSite().then(function () {\n // Remove the webparts\n removeWebParts().then(function () {\n // Log\n console.log(\"[gd-sprest] The configuration script completed, but some requests may still be running.\"); // Resolve the promise\n\n resolve();\n }, reject);\n }, reject);\n }, reject);\n });\n }\n };\n};\n\n//# sourceURL=webpack:///./build/helper/spCfg.js?"); /***/ }), @@ -670,7 +670,7 @@ eval("\n\nObject.defineProperty(exports, \"__esModule\", {\n value: true\n});\n /***/ (function(module, exports, __webpack_require__) { "use strict"; -eval("\n\nObject.defineProperty(exports, \"__esModule\", {\n value: true\n});\n\nvar Helper = __webpack_require__(/*! ./helper */ \"./build/helper/index.js\");\n\nvar Lib = __webpack_require__(/*! ./lib */ \"./build/lib/index.js\");\n\nvar Mapper = __webpack_require__(/*! ./mapper */ \"./build/mapper/index.js\");\n/**\r\n * SharePoint REST Library\r\n */\n\n\nexports.$REST = {\n __ver: 4.52,\n AppContext: function AppContext(siteUrl) {\n return Lib.Site.getAppContext(siteUrl);\n },\n ContextInfo: Lib.ContextInfo,\n DefaultRequestToHostFl: false,\n Graph: Lib.Graph,\n Helper: Helper,\n List: Lib.List,\n ListByEntityName: Lib.List.getByEntityName,\n ListDataAsStream: Lib.List.getDataAsStream,\n Navigation: Lib.Navigation,\n PeopleManager: Lib.PeopleManager,\n PeoplePicker: Lib.PeoplePicker,\n ProfileLoader: Lib.ProfileLoader,\n RemoteWeb: function RemoteWeb(requestUrl) {\n return Lib.Web.getRemoteWeb(requestUrl);\n },\n Search: Lib.Search,\n Site: Lib.Site,\n SiteExists: function SiteExists(url) {\n return Lib.Site.exists(url);\n },\n SiteUrl: function SiteUrl(id) {\n return Lib.Site.getUrlById(id);\n },\n SPTypes: Mapper.SPTypes,\n SocialFeed: Lib.SocialFeed,\n UserProfile: Lib.UserProfile,\n Utility: Lib.Utility,\n Web: Lib.Web\n}; // See if the library doesn't exist, or is an older version\n\nvar global = Lib.ContextInfo.window.$REST;\n\nif (global == null || global.__ver == null || global.__ver < exports.$REST.__ver) {\n // Set the global variable\n Lib.ContextInfo.window.$REST = exports.$REST; // Ensure the SP lib exists\n\n if (Lib.ContextInfo.window.SP) {\n // Alert other scripts this library is loaded\n Lib.ContextInfo.window.SP.SOD.notifyScriptLoadedAndExecuteWaitingJobs(\"gd-sprest\");\n Lib.ContextInfo.window.SP.SOD.notifyScriptLoadedAndExecuteWaitingJobs(\"gd-sprest.js\");\n }\n}\n\n//# sourceURL=webpack:///./build/rest.js?"); +eval("\n\nObject.defineProperty(exports, \"__esModule\", {\n value: true\n});\n\nvar Helper = __webpack_require__(/*! ./helper */ \"./build/helper/index.js\");\n\nvar Lib = __webpack_require__(/*! ./lib */ \"./build/lib/index.js\");\n\nvar Mapper = __webpack_require__(/*! ./mapper */ \"./build/mapper/index.js\");\n/**\r\n * SharePoint REST Library\r\n */\n\n\nexports.$REST = {\n __ver: 4.53,\n AppContext: function AppContext(siteUrl) {\n return Lib.Site.getAppContext(siteUrl);\n },\n ContextInfo: Lib.ContextInfo,\n DefaultRequestToHostFl: false,\n Graph: Lib.Graph,\n Helper: Helper,\n List: Lib.List,\n ListByEntityName: Lib.List.getByEntityName,\n ListDataAsStream: Lib.List.getDataAsStream,\n Navigation: Lib.Navigation,\n PeopleManager: Lib.PeopleManager,\n PeoplePicker: Lib.PeoplePicker,\n ProfileLoader: Lib.ProfileLoader,\n RemoteWeb: function RemoteWeb(requestUrl) {\n return Lib.Web.getRemoteWeb(requestUrl);\n },\n Search: Lib.Search,\n Site: Lib.Site,\n SiteExists: function SiteExists(url) {\n return Lib.Site.exists(url);\n },\n SiteUrl: function SiteUrl(id) {\n return Lib.Site.getUrlById(id);\n },\n SPTypes: Mapper.SPTypes,\n SocialFeed: Lib.SocialFeed,\n UserProfile: Lib.UserProfile,\n Utility: Lib.Utility,\n Web: Lib.Web\n}; // See if the library doesn't exist, or is an older version\n\nvar global = Lib.ContextInfo.window.$REST;\n\nif (global == null || global.__ver == null || global.__ver < exports.$REST.__ver) {\n // Set the global variable\n Lib.ContextInfo.window.$REST = exports.$REST; // Ensure the SP lib exists\n\n if (Lib.ContextInfo.window.SP) {\n // Alert other scripts this library is loaded\n Lib.ContextInfo.window.SP.SOD.notifyScriptLoadedAndExecuteWaitingJobs(\"gd-sprest\");\n Lib.ContextInfo.window.SP.SOD.notifyScriptLoadedAndExecuteWaitingJobs(\"gd-sprest.js\");\n }\n}\n\n//# sourceURL=webpack:///./build/rest.js?"); /***/ }), diff --git a/dist/gd-sprest.min.js b/dist/gd-sprest.min.js index a61d63e2..5ac774d4 100644 --- a/dist/gd-sprest.min.js +++ b/dist/gd-sprest.min.js @@ -1 +1 @@ -!function(e){var t={};function n(r){if(t[r])return t[r].exports;var o=t[r]={i:r,l:!1,exports:{}};return e[r].call(o.exports,o,o.exports,n),o.l=!0,o.exports}n.m=e,n.c=t,n.d=function(e,t,r){n.o(e,t)||Object.defineProperty(e,t,{enumerable:!0,get:r})},n.r=function(e){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})},n.t=function(e,t){if(1&t&&(e=n(e)),8&t)return e;if(4&t&&"object"==typeof e&&e&&e.__esModule)return e;var r=Object.create(null);if(n.r(r),Object.defineProperty(r,"default",{enumerable:!0,value:e}),2&t&&"string"!=typeof e)for(var o in e)n.d(r,o,function(t){return e[t]}.bind(null,o));return r},n.n=function(e){var t=e&&e.__esModule?function(){return e.default}:function(){return e};return n.d(t,"a",t),t},n.o=function(e,t){return Object.prototype.hasOwnProperty.call(e,t)},n.p="",n(n.s=48)}([function(e,t,n){"use strict";function r(e){for(var n in e)t.hasOwnProperty(n)||(t[n]=e[n])}Object.defineProperty(t,"__esModule",{value:!0}),r(n(39)),r(n(40)),r(n(41)),r(n(42)),r(n(85)),r(n(86)),r(n(87)),r(n(43)),r(n(44))},function(e,t,n){"use strict";function r(e){for(var n in e)t.hasOwnProperty(n)||(t[n]=e[n])}Object.defineProperty(t,"__esModule",{value:!0}),r(n(84)),r(n(103)),r(n(104)),r(n(105)),r(n(106)),r(n(107)),r(n(108)),r(n(109)),r(n(110)),r(n(111)),r(n(112)),r(n(113)),r(n(45))},function(e,t,n){var r=n(28)("wks"),o=n(20),i=n(3).Symbol,a="function"==typeof i;(e.exports=function(e){return r[e]||(r[e]=a&&i[e]||(a?i:o)("Symbol."+e))}).store=r},function(e,t){var n=e.exports="undefined"!=typeof window&&window.Math==Math?window:"undefined"!=typeof self&&self.Math==Math?self:Function("return this")();"number"==typeof __g&&(__g=n)},function(e,t,n){var r=n(8);e.exports=function(e){if(!r(e))throw TypeError(e+" is not an object!");return e}},function(e,t){var n=e.exports={version:"2.6.0"};"number"==typeof __e&&(__e=n)},function(e,t,n){var r=n(13),o=n(30);e.exports=n(9)?function(e,t,n){return r.f(e,t,o(1,n))}:function(e,t,n){return e[t]=n,e}},function(e,t,n){var r=n(3),o=n(6),i=n(14),a=n(20)("src"),s=Function.toString,u=(""+s).split("toString");n(5).inspectSource=function(e){return s.call(e)},(e.exports=function(e,t,n,s){var l="function"==typeof n;l&&(i(n,"name")||o(n,"name",t)),e[t]!==n&&(l&&(i(n,a)||o(n,a,e[t]?""+e[t]:u.join(String(t)))),e===r?e[t]=n:s?e[t]?e[t]=n:o(e,t,n):(delete e[t],o(e,t,n)))})(Function.prototype,"toString",function(){return"function"==typeof this&&this[a]||s.call(this)})},function(e,t){e.exports=function(e){return"object"==typeof e?null!==e:"function"==typeof e}},function(e,t,n){e.exports=!n(29)(function(){return 7!=Object.defineProperty({},"a",{get:function(){return 7}}).a})},function(e,t){e.exports={}},function(e,t,n){"use strict";function r(e){for(var n in e)t.hasOwnProperty(n)||(t[n]=e[n])}Object.defineProperty(t,"__esModule",{value:!0});var o=n(27);t.Helper=o;var i=n(17);t.SPTypes=i.SPTypes,r(n(1)),r(n(127))},function(e,t){var n={}.toString;e.exports=function(e){return n.call(e).slice(8,-1)}},function(e,t,n){var r=n(4),o=n(51),i=n(52),a=Object.defineProperty;t.f=n(9)?Object.defineProperty:function(e,t,n){if(r(e),t=i(t,!0),r(n),o)try{return a(e,t,n)}catch(e){}if("get"in n||"set"in n)throw TypeError("Accessors not supported!");return"value"in n&&(e[t]=n.value),e}},function(e,t){var n={}.hasOwnProperty;e.exports=function(e,t){return n.call(e,t)}},function(e,t,n){var r=n(16);e.exports=function(e,t,n){if(r(e),void 0===t)return e;switch(n){case 1:return function(n){return e.call(t,n)};case 2:return function(n,r){return e.call(t,n,r)};case 3:return function(n,r,o){return e.call(t,n,r,o)}}return function(){return e.apply(t,arguments)}}},function(e,t){e.exports=function(e){if("function"!=typeof e)throw TypeError(e+" is not a function!");return e}},function(e,t,n){"use strict";Object.defineProperty(t,"__esModule",{value:!0});var r=n(88);t.Mapper=r;var o=n(102);t.SPTypes=o},function(e,t,n){var r=n(12),o=n(2)("toStringTag"),i="Arguments"==r(function(){return arguments}());e.exports=function(e){var t,n,a;return void 0===e?"Undefined":null===e?"Null":"string"==typeof(n=function(e,t){try{return e[t]}catch(e){}}(t=Object(e),o))?n:i?r(t):"Object"==(a=r(t))&&"function"==typeof t.callee?"Arguments":a}},function(e,t){e.exports=!1},function(e,t){var n=0,r=Math.random();e.exports=function(e){return"Symbol(".concat(void 0===e?"":e,")_",(++n+r).toString(36))}},function(e,t,n){var r=n(8),o=n(3).document,i=r(o)&&r(o.createElement);e.exports=function(e){return i?o.createElement(e):{}}},function(e,t){var n=Math.ceil,r=Math.floor;e.exports=function(e){return isNaN(e=+e)?0:(e>0?r:n)(e)}},function(e,t){e.exports=function(e){if(null==e)throw TypeError("Can't call method on "+e);return e}},function(e,t,n){var r=n(59),o=n(23);e.exports=function(e){return r(o(e))}},function(e,t,n){var r=n(28)("keys"),o=n(20);e.exports=function(e){return r[e]||(r[e]=o(e))}},function(e,t,n){var r=n(13).f,o=n(14),i=n(2)("toStringTag");e.exports=function(e,t,n){e&&!o(e=n?e:e.prototype,i)&&r(e,i,{configurable:!0,value:t})}},function(e,t,n){"use strict";function r(e){for(var n in e)t.hasOwnProperty(n)||(t[n]=e[n])}Object.defineProperty(t,"__esModule",{value:!0}),r(n(83)),r(n(114)),r(n(115)),r(n(116)),r(n(118)),r(n(119)),r(n(120)),r(n(121)),r(n(122)),r(n(47)),r(n(123)),r(n(124)),r(n(46)),r(n(125)),r(n(126))},function(e,t,n){var r=n(5),o=n(3),i=o["__core-js_shared__"]||(o["__core-js_shared__"]={});(e.exports=function(e,t){return i[e]||(i[e]=void 0!==t?t:{})})("versions",[]).push({version:r.version,mode:n(19)?"pure":"global",copyright:"© 2018 Denis Pushkarev (zloirock.ru)"})},function(e,t){e.exports=function(e){try{return!!e()}catch(e){return!0}}},function(e,t){e.exports=function(e,t){return{enumerable:!(1&e),configurable:!(2&e),writable:!(4&e),value:t}}},function(e,t,n){"use strict";var r=n(19),o=n(32),i=n(7),a=n(6),s=n(10),u=n(55),l=n(26),p=n(62),c=n(2)("iterator"),d=!([].keys&&"next"in[].keys()),f=function(){return this};e.exports=function(e,t,n,y,m,g,h){u(n,t,y);var T,b,P,I=function(e){if(!d&&e in w)return w[e];switch(e){case"keys":case"values":return function(){return new n(this,e)}}return function(){return new n(this,e)}},v=t+" Iterator",q="values"==m,S=!1,w=e.prototype,x=w[c]||w["@@iterator"]||m&&w[m],R=x||I(m),C=m?q?I("entries"):R:void 0,F="Array"==t&&w.entries||x;if(F&&(P=p(F.call(new e)))!==Object.prototype&&P.next&&(l(P,v,!0),r||"function"==typeof P[c]||a(P,c,f)),q&&x&&"values"!==x.name&&(S=!0,R=function(){return x.call(this)}),r&&!h||!d&&!S&&w[c]||a(w,c,R),s[t]=R,s[v]=f,m)if(T={values:q?R:I("values"),keys:g?R:I("keys"),entries:C},h)for(b in T)b in w||i(w,b,T[b]);else o(o.P+o.F*(d||S),t,T);return T}},function(e,t,n){var r=n(3),o=n(5),i=n(6),a=n(7),s=n(15),u=function(e,t,n){var l,p,c,d,f=e&u.F,y=e&u.G,m=e&u.S,g=e&u.P,h=e&u.B,T=y?r:m?r[t]||(r[t]={}):(r[t]||{}).prototype,b=y?o:o[t]||(o[t]={}),P=b.prototype||(b.prototype={});for(l in y&&(n=t),n)c=((p=!f&&T&&void 0!==T[l])?T:n)[l],d=h&&p?s(c,r):g&&"function"==typeof c?s(Function.call,c):c,T&&a(T,l,c,e&u.U),b[l]!=c&&i(b,l,d),g&&P[l]!=c&&(P[l]=c)};r.core=o,u.F=1,u.G=2,u.S=4,u.P=8,u.B=16,u.W=32,u.U=64,u.R=128,e.exports=u},function(e,t,n){var r=n(58),o=n(35);e.exports=Object.keys||function(e){return r(e,o)}},function(e,t,n){var r=n(22),o=Math.min;e.exports=function(e){return e>0?o(r(e),9007199254740991):0}},function(e,t){e.exports="constructor,hasOwnProperty,isPrototypeOf,propertyIsEnumerable,toLocaleString,toString,valueOf".split(",")},function(e,t,n){var r=n(3).document;e.exports=r&&r.documentElement},function(e,t,n){var r,o,i,a=n(15),s=n(75),u=n(36),l=n(21),p=n(3),c=p.process,d=p.setImmediate,f=p.clearImmediate,y=p.MessageChannel,m=p.Dispatch,g=0,h={},T=function(){var e=+this;if(h.hasOwnProperty(e)){var t=h[e];delete h[e],t()}},b=function(e){T.call(e.data)};d&&f||(d=function(e){for(var t=[],n=1;arguments.length>n;)t.push(arguments[n++]);return h[++g]=function(){s("function"==typeof e?e:Function(e),t)},r(g),g},f=function(e){delete h[e]},"process"==n(12)(c)?r=function(e){c.nextTick(a(T,e,1))}:m&&m.now?r=function(e){m.now(a(T,e,1))}:y?(i=(o=new y).port2,o.port1.onmessage=b,r=a(i.postMessage,i,1)):p.addEventListener&&"function"==typeof postMessage&&!p.importScripts?(r=function(e){p.postMessage(e+"","*")},p.addEventListener("message",b,!1)):r="onreadystatechange"in l("script")?function(e){u.appendChild(l("script")).onreadystatechange=function(){u.removeChild(this),T.call(e)}}:function(e){setTimeout(a(T,e,1),0)}),e.exports={set:d,clear:f}},function(e,t,n){"use strict";var r=n(16);function o(e){var t,n;this.promise=new e(function(e,r){if(void 0!==t||void 0!==n)throw TypeError("Bad Promise constructor");t=e,n=r}),this.resolve=r(t),this.reject=r(n)}e.exports.f=function(e){return new o(e)}},function(e,t,n){"use strict";Object.defineProperty(t,"__esModule",{value:!0}),t.RequestType={Custom:0,Delete:1,Merge:2,OData:3,Get:10,GetBuffer:11,GetWithArgs:12,GetWithArgsInBody:13,GetWithArgsInQS:14,GetWithArgsInQSAsVar:15,GetWithArgsValueOnly:16,GetReplace:17,GraphGet:20,GraphPost:21,Post:30,PostWithArgs:31,PostWithArgsInBody:32,PostWithArgsInQS:33,PostWithArgsInQSAsVar:34,PostWithArgsValueOnly:35,PostReplace:36}},function(e,t,n){"use strict";Object.defineProperty(t,"__esModule",{value:!0});var r=n(1),o=n(0);t.Helper={addBaseMethods:function(e,t){t.addMethods=e.addMethods,t.base=e.base,t.done=e.done,t.execute=e.execute,t.executeAndWait=e.executeAndWait,t.executeMethod=e.executeMethod,t.existsFl=!0,t.getCollection=e.getCollection,t.getProperty=e.getProperty,t.parent=e,t.targetInfo=e.targetInfo,t.updateMetadataUri=e.updateMetadataUri,t.waitForRequestsToComplete=e.waitForRequestsToComplete},done:function(e,t){e.base=e.base?e.base:e,e.responseIndex=e.responseIndex>=0?e.responseIndex:0,o.Request.waitForRequestsToComplete(e,function(){var n=e.base.responses;e.base.responses=[],e.base.waitFlags=[],t&&t.apply(e,n)})},executeMethod:function(e,n,r,i){var a=null,s=e.d?e.d.__metadata:e.__metadata;s&&s.uri?(a={url:s.uri},r.inheritMetadataType&&s.type&&(r.metadataType=s.type),t.Helper.updateMetadataUri(e,s,a)):a=Object.create(e.targetInfo);var u=new o.MethodInfo(n,r,i);a.bufferFl=r.requestType==o.RequestType.GetBuffer,a.data=u.body,a.defaultToWebFl=void 0===a.defaultToWebFl&&e.base?e.base.targetInfo.defaultToWebFl:a.defaultToWebFl,a.method=u.requestMethod,a.requestDigest=void 0===a.requestDigest&&e.base&&e.base.targetInfo.requestDigest?e.base.targetInfo.requestDigest:a.requestDigest,a.requestType=r.requestType,u.replaceEndpointFl?a.endpoint=u.url:u.url&&u.url.length>0&&(a.endpoint=a.endpoint?a.endpoint:"",a.endpoint&&u.url&&0!=u.url.indexOf("?")&&(a.endpoint+="/"),a.endpoint+=u.url);var l=new o.Base(a);return l.base=e.base?e.base:e,l.getAllItemsFl=u.getAllItemsFl,l.parent=e,l.requestType=r.requestType,r.returnType&&o.Request.addMethods(l,{__metadata:{type:r.returnType}}),l},getCollection:function(e,n,r){var i=Object.create(e.targetInfo);i.data=null,i.method=null;var a=e.d?e.d.__metadata:e.__metadata;a&&a.uri?(i.url=a.uri,t.Helper.updateMetadataUri(e,a,i),i.endpoint=n):i.endpoint+="/"+n,i.callback=r&&"function"==typeof r[0]?r[0]:null;var s=new o.Base(i);return s.base=e.base?e.base:e,s.parent=e,s},getNextSetOfResults:function(e){var t=Object.create(e.targetInfo);t.endpoint="",t.url=e.d.__next;var n=new o.Base(t);return n.base=e.base?e.base:e,n.parent=e,n},getProperty:function(e,n,r){var i=Object.create(e.targetInfo);r.startsWith("graph")&&(i.requestType=o.RequestType.GraphGet),i.data=null,i.method=null;var a=e.d?e.d.__metadata:e.__metadata;a&&a.uri?(i.url=a.uri,t.Helper.updateMetadataUri(e,a,i),i.endpoint=n):i.endpoint+="/"+n;var s=new o.Base(i);return s.base=e.base?e.base:e,s.parent=e,r&&o.Request.addMethods(s,{__metadata:{type:r}}),s},stringify:function(e){return JSON.stringify({response:e.response,status:e.status,targetInfo:{accessToken:e.targetInfo.accessToken,bufferFl:e.targetInfo.bufferFl,defaultToWebFl:e.targetInfo.defaultToWebFl,endpoint:e.targetInfo.endpoint,method:e.targetInfo.method,overrideDefaultRequestToHostFl:e.targetInfo.overrideDefaultRequestToHostFl,requestDigest:e.targetInfo.requestDigest,requestHeader:e.targetInfo.requestHeader,requestInfo:e.targetInfo.requestInfo,requestType:e.targetInfo.requestType,url:e.targetInfo.url}})},updateDataCollection:function(e,n){if(n&&(e.results=e.results?e.results.concat(n):n,e.results.length>0))for(var r=0,i=e.results;r=2&&(t=t[0]+"//"+t[2]),t},e.getQueryStringValue=function(e){for(var t=r.ContextInfo.existsFl&&r.ContextInfo.document?r.ContextInfo.document.location.href.split("?"):[""],n=(t=t.length>1?t[1]:t[0]).split("&"),o=0;o0){console.log("[gd-sprest][View] Updating the view fields for the '"+i.ViewName+"' view."),a.ViewFields().removeAllViewFields().execute(!0);for(var s=0;s=t.length&&r()})},a=0;a=f&&l()};e.Fields&&e.Fields.length>0&&(f++,console.log("[gd-sprest][Fields] Starting the requests."),y.Fields().execute(function(t){return new Promise(function(n,r){a(i.parse(t.stringify()),e.Fields).then(function(){console.log("[gd-sprest][Fields] Completed the requests."),m(),n()},r)})},p)),e.ContentTypes&&e.ContentTypes.length>0&&(f++,console.log("[gd-sprest][Content Types] Starting the requests."),y.ContentTypes().execute(function(t){n(i.parse(t.stringify()),e.ContentTypes).then(function(){console.log("[gd-sprest][Content Types] Completed the requests."),m()})},p,!0)),e.ListCfg&&e.ListCfg.length&&(f++,console.log("[gd-sprest][Lists] Starting the requests."),y.Lists().execute(function(t){(function(e,t){return new Promise(function(n,r){for(var o=function(n){var o=t[n];if(u("Title",o.ListInformation.Title,e.results))console.log("[gd-sprest][List] The list '"+o.ListInformation.Title+"' already exists.");else{console.log("[gd-sprest][List] Creating the '"+o.ListInformation.Title+"' list.");var i=o.ListInformation,a=i.Title;i.Title=a.replace(/ /g,""),e.add(i).execute(function(e){i.Title=a,e.existsFl?(e.existsFl&&e.Title!=a?e.update({Title:a}).execute(function(){console.log("[gd-sprest][List] The list '"+e.Title+"' was created successfully.")}):console.log("[gd-sprest][List] The list '"+e.Title+"' was created successfully."),o.onCreated&&o.onCreated(e)):(console.log("[gd-sprest][List] The list '"+i.Title+"' failed to be created."),console.log("[gd-sprest][List] Error: '"+e.response))},r)}},i=0;i0&&(f++,console.log("[gd-sprest][WebParts] Starting the requests."),new Promise(function(t,n){var i=e.WebPartCfg;console.log("[gd-sprest][WebPart] Creating the web parts."),r.Web(r.ContextInfo.siteServerRelativeUrl).getCatalog(o.SPTypes.ListTemplateType.WebPartCatalog).RootFolder().query({Expand:["Files"]}).execute(function(e){for(var n=0,a=function(a){var s=i[a],l=function(){++n>=i.length&&t()},p=u("Name",s.FileName,e.Files.results);if(p.existsFl)console.log("[gd-sprest][WebPart] The webpart '"+s.FileName+"' already exists."),s.onUpdated&&s.onUpdated(p),l();else{for(var c=s.XML.trim(),d=new ArrayBuffer(2*c.length),f=new Uint16Array(d),y=0;y"+e.title+"",t.id=e.id,t.onclick=e.onClick,n?r.appendChild(t):r.insertBefore(t,r.firstChild)),t}},function(e,t,n){n(49),e.exports=n(11)},function(e,t,n){n(50),n(53),n(64),n(68),e.exports=n(5).Promise},function(e,t,n){"use strict";var r=n(18),o={};o[n(2)("toStringTag")]="z",o+""!="[object z]"&&n(7)(Object.prototype,"toString",function(){return"[object "+r(this)+"]"},!0)},function(e,t,n){e.exports=!n(9)&&!n(29)(function(){return 7!=Object.defineProperty(n(21)("div"),"a",{get:function(){return 7}}).a})},function(e,t,n){var r=n(8);e.exports=function(e,t){if(!r(e))return e;var n,o;if(t&&"function"==typeof(n=e.toString)&&!r(o=n.call(e)))return o;if("function"==typeof(n=e.valueOf)&&!r(o=n.call(e)))return o;if(!t&&"function"==typeof(n=e.toString)&&!r(o=n.call(e)))return o;throw TypeError("Can't convert object to primitive value")}},function(e,t,n){"use strict";var r=n(54)(!0);n(31)(String,"String",function(e){this._t=String(e),this._i=0},function(){var e,t=this._t,n=this._i;return n>=t.length?{value:void 0,done:!0}:(e=r(t,n),this._i+=e.length,{value:e,done:!1})})},function(e,t,n){var r=n(22),o=n(23);e.exports=function(e){return function(t,n){var i,a,s=String(o(t)),u=r(n),l=s.length;return u<0||u>=l?e?"":void 0:(i=s.charCodeAt(u))<55296||i>56319||u+1===l||(a=s.charCodeAt(u+1))<56320||a>57343?e?s.charAt(u):i:e?s.slice(u,u+2):a-56320+(i-55296<<10)+65536}}},function(e,t,n){"use strict";var r=n(56),o=n(30),i=n(26),a={};n(6)(a,n(2)("iterator"),function(){return this}),e.exports=function(e,t,n){e.prototype=r(a,{next:o(1,n)}),i(e,t+" Iterator")}},function(e,t,n){var r=n(4),o=n(57),i=n(35),a=n(25)("IE_PROTO"),s=function(){},u=function(){var e,t=n(21)("iframe"),r=i.length;for(t.style.display="none",n(36).appendChild(t),t.src="javascript:",(e=t.contentWindow.document).open(),e.write("