├── .gitignore ├── CHANGELOG.md ├── LICENSE ├── README.md ├── bower.json ├── dist ├── sprestlib-ui.bundle.js ├── sprestlib-ui.bundle.js.map ├── sprestlib-ui.css ├── sprestlib-ui.js ├── sprestlib-ui.min.js ├── sprestlib-ui.min.js.map ├── sprestlib.bundle.js ├── sprestlib.bundle.js.map ├── sprestlib.d.ts ├── sprestlib.js ├── sprestlib.min.js └── tsconfig.json ├── example ├── css │ ├── prism-coy.min.css │ ├── sprestlib-demo.css │ ├── sprestlib-ui.css │ └── tablesorter.css ├── img │ ├── readme-demo-webpart.png │ ├── readme-try-it-out.png │ ├── readme-tryitout-console.png │ ├── setup-Departments.png │ ├── setup-Employees.png │ ├── setup01.png │ ├── setup02.png │ ├── setup03.png │ └── setup04.png ├── js │ ├── ascii-table.min.js │ ├── jquery.min.js │ ├── jquery.tablesorter.min.js │ └── prism.min.js ├── nodejs-demo.js ├── sprestlib-demo-file-upload.html ├── sprestlib-demo-people-picker.html ├── sprestlib-demo.html └── sprestlib-ui-demo.html ├── gulpfile.js ├── lib ├── jquery.min.js ├── jquery.tablesorter.min.js └── promise.min.js ├── package.json └── test ├── ascii-table.min.js ├── qunit-test.html └── qunit-tests.js /.gitignore: -------------------------------------------------------------------------------- 1 | ### MacOS 2 | .DS_Store 3 | ### Node 4 | node_modules/ 5 | npm-debug.log 6 | bower_components/ 7 | .icloud 8 | *.icloud 9 | package-lock.json 10 | ### Docusaurus 11 | blog/ 12 | website/ 13 | docs/ 14 | css/hybrid.min.css 15 | css/main.css 16 | css/style.bundle.css 17 | -------------------------------------------------------------------------------- /CHANGELOG.md: -------------------------------------------------------------------------------- 1 | # Changelog 2 | All notable changes to this project will be documented in this file. 3 | 4 | The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), 5 | and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). 6 | 7 | ## [1.10.0] - 2019-02-?? 8 | ### Added 9 | - New `site` API method: `group().create()` [\#47](https://github.com/gitbrent/sprestlib/issues/47) ([DavidPratten](https://github.com/DavidPratten)) 10 | - New `site` API method: `group().delete()` [\#47](https://github.com/gitbrent/sprestlib/issues/47) ([DavidPratten](https://github.com/DavidPratten)) 11 | - New `site` API method: `group().addUser()` [\#47](https://github.com/gitbrent/sprestlib/issues/47) ([DavidPratten](https://github.com/DavidPratten)) 12 | - New `site` API method: `group().removeUser()` [\#47](https://github.com/gitbrent/sprestlib/issues/47) ([DavidPratten](https://github.com/DavidPratten)) 13 | ### Changed 14 | - Updated library to use content-type `nometadata` instead of always using `verbose`, saving 25-50% of payload size of the JSON results ([gitbrent](https://github.com/gitbrent)) 15 | - Updated JSON result parsing to handle more cases/styles (nometadata, verbose, MS Graph) ([gitbrent](https://github.com/gitbrent)) 16 | - Updated construction of REST `headers` to make it more robust ([gitbrent](https://github.com/gitbrent)) 17 | - Updated Promise reject error message: Returned string now includes SharePoint `error.code` and no longer shows the "URL used:" string; Updated parsing code to be more robust; Now includes support for parsing Microsoft Graph REST API call errors. ([gitbrent](https://github.com/gitbrent)) 18 | - Fix: `APP_OPTS.baseUrl` now uses `_spPageContextInfo.siteServerRelativeUrl` [\#46](https://github.com/gitbrent/sprestlib/issues/46) ([DavidPratten](https://github.com/DavidPratten)) 19 | 20 | 21 | ## [1.9.0] - 2018-12-12 22 | ### Added 23 | - New `file` API method: `checkin()` ([gitbrent](https://github.com/gitbrent)) 24 | - New `file` API method: `checkout()` ([gitbrent](https://github.com/gitbrent)) 25 | - New `file` API method: `delete()` ([gitbrent](https://github.com/gitbrent)) 26 | - New `file` API method: `recycle()` ([gitbrent](https://github.com/gitbrent)) 27 | - New `folder` API method: `add()` ([gitbrent](https://github.com/gitbrent)) 28 | - New `folder` API method: `delete()` ([gitbrent](https://github.com/gitbrent)) 29 | - New `folder` API method: `recycle()` ([gitbrent](https://github.com/gitbrent)) 30 | - New `folder` API method: `upload()` [\#18](https://github.com/gitbrent/sprestlib/issues/18) ([ra6hi9](https://github.com/ra6hi9)) 31 | - New `options()` method: replaces `baseUrl()` and `nodeConfig()` methods ([gitbrent](https://github.com/gitbrent)) 32 | ### Changed 33 | - Typescript: Modified declaration file [\#37](https://github.com/gitbrent/sprestlib/pull/37) ([kelvinbell](https://github.com/kelvinbell)) 34 | - Allow single UserProfile property to be queried [\#38](https://github.com/gitbrent/sprestlib/issues/38) ([YakQin](https://github.com/YakQin)) 35 | - The `rest()` method now includes the page's `__REQUESTDIGEST` value for POST types with custom headers that did not already include a value for `X-RequestDigest` 36 | ### Removed 37 | *DEPRECATED* `baseUrl()` and `nodeConfig()` methods - use the new `options()` method instead. 38 | 39 | 40 | ## [v1.8.0](https://github.com/gitbrent/sprestlib/tree/v1.8.0) (2018-08-29) 41 | [Full Changelog](https://github.com/gitbrent/sprestlib/compare/v1.7.0...v1.8.0) 42 | 43 | **Implemented Enhancements:** 44 | - New File Methods: `get()`, `info()`, `perms()` [\#20](https://github.com/gitbrent/sprestlib/issues/20) ([ra6hi9](https://github.com/ra6hi9))([YakQin](https://github.com/YakQin))([gitbrent](https://github.com/gitbrent)) 45 | - New Folder Methods: `files()`, `folders()`, `info()`, `perms()` [\#20](https://github.com/gitbrent/sprestlib/issues/20) ([ra6hi9](https://github.com/ra6hi9))([YakQin](https://github.com/YakQin))([gitbrent](https://github.com/gitbrent)) 46 | - Added Typescript Definitions [\#24](https://github.com/gitbrent/sprestlib/issues/24) ([Wireliner](https://github.com/Wireliner)) 47 | - Added two new properties to `list().cols()` method: `choiceValues` and `allowFillInChoices` 48 | - Added "browser" field to `package.json` to improve library integration 49 | 50 | **Fixed Bugs:** 51 | - The list() `baseUrl` option is ignored by the underlying versions query. [\#27](https://github.com/gitbrent/sprestlib/issues/27) ([gitbrent](https://github.com/gitbrent)) 52 | - sprLib.user(options).profile() using "post"? [\#30](https://github.com/gitbrent/sprestlib/issues/30) ([YakQin](https://github.com/YakQin)) 53 | - The `baseUrl` option no longer works in `user()` methods [\#31](https://github.com/gitbrent/sprestlib/issues/31) ([YakQin](https://github.com/YakQin)) 54 | - Typescript fix: listCols should be optional [\#33](https://github.com/gitbrent/sprestlib/pull/33) ([csoren](https://github.com/csoren)) 55 | 56 | 57 | ## [v1.7.0](https://github.com/gitbrent/sprestlib/tree/v1.7.0) (2018-05-14) 58 | [Full Changelog](https://github.com/gitbrent/sprestlib/compare/v1.6.0...v1.7.0) 59 | 60 | **Implemented Enhancements:** 61 | - Renamed `getItems()` list method to `items()`. 62 | - Modify user() method option names to be case insensitive [\#17](https://github.com/gitbrent/sprestlib/issues/17) ([gitbrent](https://github.com/gitbrent)) 63 | - Get members of a specific group given its name [\#19](https://github.com/gitbrent/sprestlib/issues/19) ([ra6hi9](https://github.com/ra6hi9)) 64 | 65 | **Fixed Bugs:** 66 | - Added `catch()` to core REST method call to properly handle failed queries 67 | - Updated Node detection to be more accurate and work with Angular, etc. (aka:"ERROR in ./node_modules/sprestlib/dist/sprestlib.js") [\#23](https://github.com/gitbrent/sprestlib/issues/23) ([azmatzuberi](https://github.com/azmatzuberi)) 68 | 69 | 70 | ## [v1.6.0](https://github.com/gitbrent/sprestlib/tree/v1.6.0) (2018-03-05) 71 | [Full Changelog](https://github.com/gitbrent/sprestlib/compare/v1.5.0...v1.6.0) 72 | 73 | **Implemented Enhancements:** 74 | - Add support for SP User Profile API [\#14](https://github.com/gitbrent/sprestlib/issues/14) ([ra6hi9](https://github.com/ra6hi9)) 75 | - Removed jQuery methods from sprestlib.js - there are now ZERO library dependencies! 76 | - Add async/await example [\#16](https://github.com/gitbrent/sprestlib/pull/16) ([wmertens](https://github.com/wmertens)) 77 | - Removed all ES6 code from `sprestlib-demo.html` (it is IE11 compatible now!), plus moved deps to CDN from local files. 78 | - Improved error messages/feedback 79 | 80 | **Fixed Bugs:** 81 | - Fixed two issues with CRUD operations via Node.js 82 | - Fixed a few minor issues with parsing no results in certain scenarios, etc. 83 | 84 | 85 | ## [v1.5.0](https://github.com/gitbrent/sprestlib/tree/v1.5.0) (2018-02-16) 86 | [Full Changelog](https://github.com/gitbrent/sprestlib/compare/v1.4.0...v1.5.0) 87 | 88 | **Implemented Enhancements:** 89 | - Form binding/population spun off into separate `sprestlib-ui.js` library 90 | - Created a separate demo page for `sprestlib-ui.js` library 91 | - Added new dist file (minified library): `sprestlib.min.js` 92 | 93 | **Fixed Bugs:** 94 | - Selecting the same field name twice results in undefined [\#15](https://github.com/gitbrent/sprestlib/issues/15) ([gitbrent](https://github.com/gitbrent)) 95 | - Fixed a null-check defect in REST result parsing 96 | 97 | 98 | ## [v1.4.0](https://github.com/gitbrent/sprestlib/tree/v1.4.0) (2018-01-08) 99 | [Full Changelog](https://github.com/gitbrent/sprestlib/compare/v1.3.0...v1.4.0) 100 | 101 | **Implemented Enhancements:** 102 | - Add paging/skip/next ability to getItems() [\#4](https://github.com/gitbrent/sprestlib/issues/4) ([Wireliner](https://github.com/Wireliner)) 103 | - Error in list(listname).create(data) [\#5](https://github.com/gitbrent/sprestlib/issues/5) ([Wireliner](https://github.com/Wireliner)) 104 | - Add new option for auth DigestToken [\#6](https://github.com/gitbrent/sprestlib/issues/6) ([Wireliner](https://github.com/Wireliner)) 105 | - Add new 'guid' option to list() [\#7](https://github.com/gitbrent/sprestlib/issues/7) ([YakQin](https://github.com/YakQin)) 106 | - Add new 'baseUrl' option to user() [\#8](https://github.com/gitbrent/sprestlib/issues/8) ([YakQin](https://github.com/YakQin)) 107 | - Add new 'nodeEnabled' option for Angular/etc [\#9](https://github.com/gitbrent/sprestlib/issues/9) ([ra6hi9](https://github.com/ra6hi9)) 108 | 109 | 110 | ## [v1.3.0](https://github.com/gitbrent/sprestlib/tree/v1.3.0) (2017-11-27) 111 | [Full Changelog](https://github.com/gitbrent/sprestlib/compare/v1.2.1...v1.3.0) 112 | 113 | **Implemented Enhancements:** 114 | - *BREAKING CHANGE*: `list().baseUrl()` removed! (new: `baseUrl` param to `list()`) 115 | - *BREAKING CHANGE*: `version()` method removed! (new: `sprLib.version` property) 116 | - `.list()` now accepts an object in addition to listname (string) 117 | - Added new `metadata` option to `list().getItems()` and `rest()` methods 118 | - Added new Site methods: `site()` - returns info, perms, users, groups, subsites, etc. 119 | 120 | 121 | ## [v1.2.1](https://github.com/gitbrent/sprestlib/tree/v1.2.1) (2017-10-12) 122 | [Full Changelog](https://github.com/gitbrent/sprestlib/compare/v1.2.0...v1.2.1) 123 | 124 | **Fixed Bugs:** 125 | - Url param passing .rest() with 'http'/'https' is not being parsed correctly [\#2](https://github.com/gitbrent/sprestlib/issues/2) ([gitbrent](https://github.com/gitbrent)) 126 | - Query options passed to .rest() are only parsed when 'queryCols' exists [\#3](https://github.com/gitbrent/sprestlib/issues/3) ([gitbrent](https://github.com/gitbrent)) 127 | 128 | 129 | ## [v1.2.0](https://github.com/gitbrent/sprestlib/tree/v1.2.0) (2017-10-05) 130 | [Full Changelog](https://github.com/gitbrent/sprestlib/compare/v1.1.0...v1.2.0) 131 | 132 | **Implemented Enhancements:** 133 | - Added Electron compatibility 134 | - Moved Qunit and SpRestLib script loading to dynamic for demo and qunit pages. 135 | 136 | **Fixed Bugs:** 137 | - The sprLib.rest() method is not parsing queryCols correctly [\#1](https://github.com/gitbrent/sprestlib/issues/1) ([gitbrent](https://github.com/gitbrent)) 138 | 139 | 140 | ## [v1.1.0](https://github.com/gitbrent/sprestlib/tree/v1.1.0) (2017-09-07) 141 | [Full Changelog](https://github.com/gitbrent/sprestlib/compare/v1.0.0...v1.1.0) 142 | 143 | **Fixed Bugs:** 144 | - Fixed bug in error messages introduced in last release 145 | - Fixed error handling in Node.js 146 | - Fixed return of empty array for null Person/lookup fields 147 | 148 | 149 | ## [v1.0.0](https://github.com/gitbrent/sprestlib/tree/v1.0.0) (2017-08-08) 150 | [Full Changelog](https://github.com/gitbrent/sprestlib/compare/v0.12.0...v1.0.0) 151 | 152 | **Implemented Enhancements:** 153 | - Added ability to lookup users by `login` 154 | - Node connectivity to SharePoint (Office 365) works now 155 | - Last bit of cleanup work to arrive at v1.0.0 156 | 157 | 158 | ## [v0.12.0](https://github.com/gitbrent/sprestlib/tree/v0.12.0) (2017-07-05) 159 | [Full Changelog](https://github.com/gitbrent/sprestlib/compare/v0.11.0...v0.12.0) 160 | 161 | **Fixed Bugs:** 162 | - Lots of code cleanup and bug fixes 163 | 164 | 165 | ## [v0.11.0](https://github.com/gitbrent/sprestlib/tree/v0.11.0) (2017-06-25) 166 | [Full Changelog](https://github.com/gitbrent/sprestlib/compare/v0.10.0...v0.11.0) 167 | 168 | **Fixed Bugs:** 169 | - Misc bug fixes 170 | 171 | **Implemented Enhancements:** 172 | - Added `baseUrl` method to List API to dynamically set baseUrl on a per-call basis 173 | - Added `cache`, `contentType` and `type`='POST' options to `rest()` API 174 | - Added ability to get user info by `title` or `email` 175 | - Added new `.recycle()` List method 176 | - Added sprestlib.bundle.js file (using gulp) 177 | - Added bower support 178 | 179 | 180 | ## [v0.10.0](https://github.com/gitbrent/sprestlib/tree/v1.0.0) (2017-05-11) 181 | **Code Cleanup** 182 | **New Features** 183 | 184 | 185 | ## [v0.9.0](https://github.com/gitbrent/sprestlib/tree/v1.0.0) (2017-01-31) 186 | **Initial Release** 187 | 188 | [Unreleased]: https://github.com/gitbrent/sprestlib/compare/v1.10.0...HEAD 189 | [1.10.0]: https://github.com/gitbrent/sprestlib/compare/v1.9.0...v1.10.0 190 | [1.9.0]: https://github.com/gitbrent/sprestlib/compare/v1.8.0...v1.9.0 191 | [1.8.0]: https://github.com/gitbrent/sprestlib/compare/v1.7.0...v1.8.0 192 | [1.7.0]: https://github.com/gitbrent/sprestlib/compare/v1.6.0...v1.7.0 193 | [1.6.0]: https://github.com/gitbrent/sprestlib/compare/v1.5.0...v1.6.0 194 | [1.5.0]: https://github.com/gitbrent/sprestlib/compare/v1.4.0...v1.5.0 195 | [1.4.0]: https://github.com/gitbrent/sprestlib/compare/v1.3.0...v1.4.0 196 | [1.3.0]: https://github.com/gitbrent/sprestlib/compare/v1.2.0...v1.3.0 197 | [1.2.1]: https://github.com/gitbrent/sprestlib/compare/v1.2.0...v1.2.1 198 | [1.2.0]: https://github.com/gitbrent/sprestlib/compare/v1.1.0...v1.2.0 199 | [1.1.0]: https://github.com/gitbrent/sprestlib/compare/v1.0.0...v1.1.0 200 | [1.0.0]: https://github.com/gitbrent/sprestlib/compare/v0.12.0...v1.0.0 201 | [0.12.0]: https://github.com/gitbrent/sprestlib/compare/v0.11.0...v0.12.0 202 | [0.11.0]: https://github.com/gitbrent/sprestlib/compare/v0.10.0...v0.11.0 203 | [0.10.0]: https://github.com/gitbrent/sprestlib/compare/v0.9.0...v0.10.0 204 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2016-2018 Brent Ely 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | [![npm version](https://img.shields.io/npm/v/sprestlib.svg)](https://www.npmjs.com/package/sprestlib) [![MIT License](https://img.shields.io/github/license/gitbrent/sprestlib.svg)](https://github.com/gitbrent/SpRestLib/blob/master/LICENSE) [![Known Vulnerabilities](https://snyk.io/test/npm/sprestlib/badge.svg)](https://snyk.io/test/npm/sprestlib) [![Package Quality](http://npm.packagequality.com/shield/sprestlib.png?style=flat-square)](https://github.com/gitbrent/sprestlib) [![jsDelivr Stats](https://data.jsdelivr.com/v1/package/npm/sprestlib/badge)](https://www.jsdelivr.com/package/npm/sprestlib) 2 | 3 | # SpRestLib 4 | 5 | ## Microsoft SharePoint REST JavaScript Library 6 | SpRestLib is a lightweight wrapper around the SharePoint REST API that can be used in client browsers or server-side. 7 | 8 | This library is for developers who build web parts embedded into Content Editor/Script Editor, SPFx web parts, Angular/React apps, 9 | Node.js/npm-based solutions, etc. Using SpRestLib greatly simplifies SharePoint integration by reducing common operations to concise 10 | Promise-based methods. 11 | 12 | ### Library Features 13 | * Simple - Clean, concise API: Get users, sites, list items, etc. in 1-3 lines of code 14 | * Modern - Lightweight, pure JavaScript solution with no other dependencies 15 | * Elegant - Utilizes the new [ES6 Promise](http://www.datchley.name/es6-promises/) architecture for asynchronous operations 16 | * Robust - Handles authentication, asynchronous errors, results paging and more 17 | 18 | ### SharePoint Interfaces 19 | * List Methods - Create, read, update, and delete (CRUD) List/Library items, including support for paging/next 20 | * User Methods - Get User information: Basic (ID, Email, LoginName, etc.) and UserProfile (Manager, 100+ Properties) 21 | * Site Methods - Get Site information (Lists, Groups, Users, Roles, Subsites and Permissions) 22 | * File Methods - Get files, file properties/permissions, delete/recycle files 23 | * Folder Methods - Get folder contents, folder properties/permissions, create/delete/recycle folders 24 | * REST Methods - Execute REST API calls against any available [SharePoint REST API](https://msdn.microsoft.com/en-us/library/office/dn268594.aspx) endpoint 25 | * Form Population - Populate form elements using data-bind declarative binding system like Knockout or AngluarJS 26 | 27 | ### Supported Environments 28 | * SharePoint 2013 (SP2013), SharePoint 2016 (SP2016), SharePoint 2019 (SP2019), SharePoint Online (SPO) 29 | 30 | 31 | ************************************************************************************************** 32 | # Method Overview 33 | 34 | ## REST API 35 | * `sprLib.rest(options)` - Returns the results of a given REST call to any [SharePoint REST API](https://msdn.microsoft.com/en-us/library/office/dn268594.aspx) 36 | 37 | ## List/Library 38 | * `sprLib.list(listName).items()` - Returns an array of `SP.ListItem` objects using a variety of query options 39 | * `sprLib.list(listName).create()` - Create a new list item using JSON data 40 | * `sprLib.list(listName).update()` - Update an existing item using JSON data 41 | * `sprLib.list(listName).delete()` - Delete an existing item using JSON data (permanently delete) 42 | * `sprLib.list(listName).recycle()` - Recycle an existing item using JSON data (move to Recycle Bin) 43 | * `sprLib.list(listName).cols()` - Returns an array of column properties (datatype, default values, etc.) 44 | * `sprLib.list(listName).info()` - Returns `SP.List` properties (last modified, number of items, etc.) 45 | * `sprLib.list(listName).perms()` - Returns an array of the list's Member Role assignments 46 | 47 | ## File 48 | * `sprLib.file(fileName).get()` - Returns a file (binary/text) as a blob which can be saved 49 | * `sprLib.file(fileName).info()` - Returns `SP.File` properties (Created, GUID, HasUniquePerms, etc.) 50 | * `sprLib.file(fileName).perms()` - Returns an array of the file's Member Role assignments 51 | * `sprLib.file(fileName).checkin()` - Check in a file (supports optional comments/checkin types) 52 | * `sprLib.file(fileName).checkout()` - Check out a file 53 | * `sprLib.file(fileName).delete()` - Permanently deletes a file (bypasses recycle bin) 54 | * `sprLib.file(fileName).recycle()` - Moves file to the site Recycle Bin 55 | 56 | ## Folder 57 | * `sprLib.folder(folderName).files()` - Returns an array of file objects contained in the folder 58 | * `sprLib.folder(folderName).folders()` - Returns an array of folder objects contained in the folder 59 | * `sprLib.folder(folderName).info()` - Returns `SP.Folder` properties (Created, GUID, HasUniquePerms, etc.) 60 | * `sprLib.folder(folderName).perms()` - Returns an array of the folder's Member Role assignments 61 | * `sprLib.folder(folderName).add()` - Creates a new folder under the parent folder 62 | * `sprLib.folder(folderName).delete()` - Permanently deletes a folder (bypasses recycle bin) 63 | * `sprLib.folder(folderName).recycle()` - Moves folder to the site Recycle Bin 64 | 65 | ## Site Collection/Subsite 66 | * `sprLib.site(siteUrl).groups()` - Returns an array of the site's Groups and Members 67 | * `sprLib.site(siteUrl).info()` - Returns `SP.Web` site properties (ID, Owner, Language, Logo, etc.) 68 | * `sprLib.site(siteUrl).lists()` - Returns an array of the site's Lists/Libraries 69 | * `sprLib.site(siteUrl).perms()` - Returns an array of the site's Member/Roles objects 70 | * `sprLib.site(siteUrl).roles()` - Returns an array of the site's Roles 71 | * `sprLib.site(siteUrl).subsites()` - Returns an array of the site's Subsites 72 | * `sprLib.site(siteUrl).users()` - Returns an array of the site's Users and their base permissions 73 | 74 | ## User Groups/Info/Profile 75 | * `sprLib.user(options).groups()` - Returns `SP.Group` group properties (Id, Owner, Title, etc.) 76 | * `sprLib.user(options).info()` - Returns `SP.User` user properties (Id, Email, Login, Title, etc.) 77 | * `sprLib.user(options).profile()` - Returns `SP.UserProfile.PersonProperties` (DirectReports, PictureUrl, etc.) 78 | 79 | ## Utility Methods 80 | * `sprLib.renewSecurityToken()` - Refreshes the SharePoint page security digest token (`__REQUESTDIGEST`) 81 | 82 | ## SpRestLib-UI :: Form Population 83 | * `data-sprlib{options}` - Populates the parent tag using the options provided 84 | 85 | 86 | 87 | ************************************************************************************************** 88 | 89 | 90 | 91 | 92 | - [Library Demo](#library-demo) 93 | - [Demo via Browser Console](#demo-via-browser-console) 94 | - [Demo via Page Web Part](#demo-via-page-web-part) 95 | - [Installation](#installation) 96 | - [CDN](#cdn) 97 | - [Download](#download) 98 | - [npm](#npm) 99 | - [yarn](#yarn) 100 | - [Method Reference](#method-reference) 101 | - [REST API Methods](#rest-api-methods) 102 | - [List/Library Methods (`SP.List`)](#listlibrary-methods-splist) 103 | - [File Methods (`SP.File`)](#file-methods-spfile) 104 | - [Folder Methods (`SP.Folder`)](#folder-methods-spfolder) 105 | - [Site Methods (`SP.Web`)](#site-methods-spweb) 106 | - [User Methods (`SP.User`)](#user-methods-spuser) 107 | - [Utility Methods](#utility-methods) 108 | - [Form Binding (SpRestLib UI)](#form-binding-sprestlib-ui) 109 | - [Library Features and Notes](#library-features-and-notes) 110 | - [Async Operations via Promises](#async-operations-via-promises) 111 | - [SharePoint Authentication Notes](#sharepoint-authentication-notes) 112 | - [Integration with Other Libraries](#integration-with-other-libraries) 113 | - [Connect to SharePoint Online/Office.com with Node.js](#connect-to-sharepoint-onlineofficecom-with-nodejs) 114 | - [Issues / Suggestions](#issues--suggestions) 115 | - [Authentication](#authentication) 116 | - [Bugs](#bugs) 117 | - [Supported SharePoint Versions](#supported-sharepoint-versions) 118 | - [Backwards Compatibility](#backwards-compatibility) 119 | - [Special Thanks](#special-thanks) 120 | - [License](#license) 121 | 122 | 123 | 124 | 125 | ************************************************************************************************** 126 | # Library Demo 127 | 128 | ## Demo via Browser Console 129 | It's really easy to test drive SpRestLib! 130 | 131 | Just open your browser's Developer Tools window anywhere on your SharePoint site, 132 | then run the following code snippet which will load the SpRestLib bundle script dynamically: 133 | 134 | ```javascript 135 | // Load/Demo SpRestLib via CDN 136 | var script = document.createElement('script'); 137 | script.src = "https://cdn.jsdelivr.net/gh/gitbrent/sprestlib@1.9.0/dist/sprestlib.bundle.js"; 138 | script.onload = function(){ 139 | // Demo library method - show current user info 140 | console.log('Current SharePoint User: '); 141 | sprLib.user().info().then( objUser => console.log(objUser) ); 142 | } 143 | document.getElementsByTagName('head')[0].appendChild(script); 144 | ``` 145 | ![Try It Out](https://raw.githubusercontent.com/gitbrent/SpRestLib/master/example/img/readme-tryitout-console.png) 146 | 147 | ## Demo via Page Web Part 148 | Upload the `example/sprestlib-demo.html` file to SiteAssets on your SharePoint site and add it into a web part for a live 149 | demo of all available methods. 150 | 151 | ![Demo SharePoint Web Part](https://raw.githubusercontent.com/gitbrent/SpRestLib/master/example/img/readme-demo-webpart.png) 152 | 153 | 154 | ************************************************************************************************** 155 | # Installation 156 | 157 | ## CDN 158 | ```javascript 159 | 160 | // Use bundle for IE11 support 161 | 162 | ``` 163 | 164 | ## Download 165 | ```javascript 166 | 167 | // Use bundle for IE11 support 168 | 169 | ``` 170 | 171 | ## npm 172 | ```javascript 173 | npm install sprestlib 174 | 175 | var sprLib = require("sprestlib"); 176 | ``` 177 | 178 | ## yarn 179 | ```javascript 180 | yarn install sprestlib 181 | ``` 182 | 183 | 184 | ************************************************************************************************** 185 | # Method Reference 186 | 187 | ## REST API Methods 188 | [REST API Methods](https://gitbrent.github.io/SpRestLib/docs/api-rest.html) 189 | 190 | ## List/Library Methods (`SP.List`) 191 | [List/Library Methods](https://gitbrent.github.io/SpRestLib/docs/api-list.html) 192 | 193 | ## File Methods (`SP.File`) 194 | [File Methods](https://gitbrent.github.io/SpRestLib/docs/api-file.html) 195 | 196 | ## Folder Methods (`SP.Folder`) 197 | [Folder Methods](https://gitbrent.github.io/SpRestLib/docs/api-folder.html) 198 | 199 | ## Site Methods (`SP.Web`) 200 | [Site Methods](https://gitbrent.github.io/SpRestLib/docs/api-site.html) 201 | 202 | ## User Methods (`SP.User`) 203 | [User Methods](https://gitbrent.github.io/SpRestLib/docs/api-user.html) 204 | 205 | ## Utility Methods 206 | [Utility Methods](https://gitbrent.github.io/SpRestLib/docs/feat-utilities.html) 207 | 208 | ## Form Binding (SpRestLib UI) 209 | [Form Binding](https://gitbrent.github.io/SpRestLib/docs/ui-form-binding.html) 210 | 211 | 212 | ************************************************************************************************** 213 | # Library Features and Notes 214 | 215 | ## Async Operations via Promises 216 | [JavaScript Async Promises](https://gitbrent.github.io/SpRestLib/docs/feat-promises.html) 217 | 218 | ## SharePoint Authentication Notes 219 | [SharePoint Authentication Notes](https://gitbrent.github.io/SpRestLib/docs/sp-auth-notes.html) 220 | 221 | ## Integration with Other Libraries 222 | Using SpRestLib with React, Angular, SharePoint Electron, etc. 223 | [Integration with Other Libraries](https://gitbrent.github.io/SpRestLib/docs/feat-integration.html) 224 | 225 | ## Connect to SharePoint Online/Office.com with Node.js 226 | * SpRestLib can be utilized via Node.js to perform powerful operations, generate reports, etc. 227 | * See the `example` directory for a complete, working demo of connecting to SharePoint Online. 228 | 229 | 230 | ************************************************************************************************** 231 | # Issues / Suggestions 232 | 233 | ## Authentication 234 | See [SharePoint Authentication Notes](https://gitbrent.github.io/SpRestLib/docs/sp-auth-notes.html) for issues with authentication. 235 | 236 | ## Bugs 237 | Please file issues or suggestions on the [issues page on GitHub](https://github.com/gitbrent/SpRestLib/issues/new), or even better, [submit a pull request](https://github.com/gitbrent/SpRestLib/pulls). Feedback is always welcome! 238 | 239 | When reporting issues, please include a code snippet or a link demonstrating the problem. 240 | 241 | 242 | 243 | ************************************************************************************************** 244 | # Supported SharePoint Versions 245 | 246 | ## Backwards Compatibility 247 | *Does SpRestLib support SharePoint 2010 or 2007?* 248 | Unfortunately, older versions cannot be supported. The SharePoint 2007/2010 API utilized SOAP web services with XML (`_vti_bin/lists.asmx` endpoints) while the current API uses a completely new (`_api/web/lists()` endpoint) backed by REST services. 249 | 250 | 251 | 252 | ************************************************************************************************** 253 | # Special Thanks 254 | 255 | * [Marc D Anderson](http://sympmarc.com/) - SpRestLib is built in the spirit of the late, great `SPServices` library 256 | * Microsoft - for the SharePoint.com developer account 257 | * Everyone who submitted an Issue or Pull Request 258 | 259 | 260 | 261 | ************************************************************************************************** 262 | # License 263 | 264 | Copyright © 2016-2019 [Brent Ely](https://github.com/gitbrent/SpRestLib) 265 | 266 | [MIT](https://github.com/gitbrent/SpRestLib/blob/master/LICENSE) 267 | -------------------------------------------------------------------------------- /bower.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "sprestlib", 3 | "description": "SharePoint REST Web Services JavaScript Library", 4 | "main": [ 5 | "dist/sprestlib.js" 6 | ], 7 | "dependencies": { 8 | "promise": "^0.2.2" 9 | }, 10 | "authors": [ 11 | "Brent Ely " 12 | ], 13 | "license": "MIT", 14 | "keywords": [ 15 | "javascript-rest-library", 16 | "javascript-sharepoint-rest", 17 | "javascript-sharepoint-services", 18 | "javascript-sharepoint-web-services", 19 | "javascript-sp-web-services", 20 | "sharepoint-javascript", 21 | "sharepoint-javascript-framework", 22 | "sharepoint-javascript-library", 23 | "sharepoint-javascript-list", 24 | "sharepoint-javascript-rest", 25 | "sharepoint-javascript-webpart", 26 | "sharepoint-angular", 27 | "sharepoint-react", 28 | "sharepoint-node", 29 | "sharepoint-rest-api", 30 | "sharepoint-rest-library", 31 | "sharepoint-web-services", 32 | "sharepoint-web-services-library" 33 | ], 34 | "homepage": "https://gitbrent.github.io/SpRestLib/", 35 | "ignore": [ 36 | "**/.*", 37 | "node_modules", 38 | "bower_components", 39 | "test", 40 | "tests" 41 | ] 42 | } 43 | -------------------------------------------------------------------------------- /dist/sprestlib-ui.css: -------------------------------------------------------------------------------- 1 | /* 2 | * NAME: sprestlib-ui.css 3 | * VER.: 1.0.0 4 | * REL.: 20180109 5 | * SRC.: [CSS Spinners](https://github.com/tobiasahlin/SpinKit/) 6 | */ 7 | 8 | .sprlib-spinner { 9 | display: block; 10 | height: 16px; 11 | text-align: center; 12 | white-space: nowrap; 13 | } 14 | .sprlib-spinner > div { 15 | display: inline-block; 16 | width:16px; height:16px; 17 | background-color: #40b0df; 18 | border: 3px solid #f2f9fc; 19 | border-radius: 100%; 20 | animation: sprlib-sk-bouncedelay 1.4s infinite ease-in-out both; 21 | } 22 | .sprlib-spinner .sprlib-bounce1 { animation-delay: -0.32s; } 23 | .sprlib-spinner .sprlib-bounce2 { animation-delay: -0.16s; } 24 | @keyframes sprlib-sk-bouncedelay { 0%, 80%, 100% { transform: scale(0); } 40% { transform: scale(1.0); } } 25 | -------------------------------------------------------------------------------- /dist/sprestlib-ui.js: -------------------------------------------------------------------------------- 1 | /*\ 2 | |*| :: SpRestLib-UI.js :: 3 | |*| 4 | |*| JavaScript Library for SharePoint Web Serices 5 | |*| https://github.com/gitbrent/SpRestLib 6 | |*| 7 | |*| This library is released under the MIT Public License (MIT) 8 | |*| 9 | |*| SpRestLib (C) 2016-present Brent Ely -- https://github.com/gitbrent 10 | |*| 11 | |*| Permission is hereby granted, free of charge, to any person obtaining a copy 12 | |*| of this software and associated documentation files (the "Software"), to deal 13 | |*| in the Software without restriction, including without limitation the rights 14 | |*| to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 15 | |*| copies of the Software, and to permit persons to whom the Software is 16 | |*| furnished to do so, subject to the following conditions: 17 | |*| 18 | |*| The above copyright notice and this permission notice shall be included in all 19 | |*| copies or substantial portions of the Software. 20 | |*| 21 | |*| THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 22 | |*| IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 23 | |*| FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 24 | |*| AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 25 | |*| LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 26 | |*| OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 27 | |*| SOFTWARE. 28 | \*/ 29 | 30 | (function(){ 31 | // APP VERSION/BUILD 32 | var APP_VER = "1.0.0"; 33 | var APP_BLD = "20180828"; 34 | var SPRLIB_REQ = "1.4.0+"; 35 | var DEBUG = false; // (verbose mode/lots of logging) 36 | // APP MESSAGE STRINGS (Internationalization) 37 | var APP_STRINGS = { 38 | "de": { 39 | "false" : "Nein", 40 | "noRows": "(Keine zeilen)", 41 | "true" : "Ja" 42 | }, 43 | "en": { 44 | "false" : "No", 45 | "noRows": "(No rows)", 46 | "true" : "Yes" 47 | }, 48 | "es": { 49 | "false" : "No", 50 | "noRows": "(No hay filas)", 51 | "true" : "Sí" 52 | }, 53 | "fr": { 54 | "false" : "Non", 55 | "noRows": "(Aucune ligne)", 56 | "true" : "Oui" 57 | }, 58 | "in": { 59 | "false" : "नहीं", 60 | "noRows": "(कोई पंक्तियाँ)", 61 | "true" : "हाँ" 62 | }, 63 | "jp": { 64 | "false" : "偽", 65 | "noRows": "(行がありません)", 66 | "true" : "真実" 67 | } 68 | }; 69 | var APP_CSS = { 70 | updatingBeg: { 'background-color':'#e2e9ec' }, 71 | updatingErr: { 'background-color':'#e2999c', 'color':'#fff' }, 72 | updatingEnd: { 'background-color':'', 'color':'' } 73 | }; 74 | var APP_DATE_FORMATS = { 75 | "US": "Ex: 02/14/2018 09:15:01", 76 | "DATE": "", 77 | "TIME": "", 78 | "YYYYMMDD": "", 79 | "INTLTIME": "", 80 | "INTL": "", 81 | "ISO": "" 82 | }; 83 | 84 | // SPRESTLIB-UI Setup 85 | sprLib.ui = {}; 86 | sprLib.ui.version = APP_VER+'-'+APP_BLD; 87 | 88 | /* TODO: 89 | * Add On-demand/Ad-hoc support (enable parsing/population *after* page is loaded) 90 | * Add support for callback, so users can do things after the element is populated (Select a default, show a total somewhere, etc.) 91 | * Add `Intl` (i18n) support (its supported in IE11!!) - Date and Currency formats are awesome (add Direction for our R->L users too?) 92 | */ 93 | 94 | /* =============================================================================================== 95 | | 96 | # # 97 | # # ###### # ##### ###### ##### #### 98 | # # # # # # # # # # 99 | ####### ##### # # # ##### # # #### 100 | # # # # ##### # ##### # 101 | # # # # # # # # # # 102 | # # ###### ###### # ###### # # #### 103 | | 104 | ================================================================================================== 105 | */ 106 | 107 | function formatCurrency(n, c, d, t) { 108 | var c = isNaN(c = Math.abs(c)) ? 2 : c, 109 | d = (d == undefined) ? "." : d, 110 | t = (t == undefined) ? "," : t, 111 | s = (n < 0) ? "-" : "", 112 | i = parseInt(n = Math.abs(+n || 0).toFixed(c)) + "", 113 | j = ((j = i.length) > 3) ? (j % 3) : 0; 114 | return APP_OPTS.currencyChar + s + (j ? i.substr(0, j) + t : "") + i.substr(j).replace(/(\d{3})(?=\d)/g, "$1" + t) + (c ? d + Math.abs(n - i).toFixed(c).slice(2) : ""); 115 | } 116 | 117 | function formatDate(inDate, inType) { 118 | var MONTHS = ['Jan','Feb','Mar','Apr','May','Jun','Jul','Aug','Sep','Oct','Nov','Dec']; 119 | 120 | // REALITY-CHECK: 121 | if ( !inDate ) return ''; 122 | 123 | var dateTemp = new Date(inDate); 124 | dateMM = dateTemp.getMonth() + 1; dateDD = dateTemp.getDate(); dateYY = dateTemp.getFullYear(); 125 | h = dateTemp.getHours(); m = dateTemp.getMinutes(); s = dateTemp.getSeconds(); 126 | // 127 | if (inType == "US") { 128 | strFinalDate = (dateMM<=9 ? '0' + dateMM : dateMM) + "/" + (dateDD<=9 ? '0' + dateDD : dateDD) + "/" + dateYY + " " + (h<=9 ? '0' + h : h) + ":" + (m<=9 ? '0' + m : m) + ":" + (s<=9 ? '0' + s : s); 129 | } 130 | else if (inType == "DATE") { 131 | strFinalDate = (dateMM<=9 ? '0' + dateMM : dateMM) + "/" + (dateDD<=9 ? '0' + dateDD : dateDD) + "/" + dateYY; 132 | } 133 | else if (inType == "TIME") { 134 | strFinalDate = (h<=9 ? '0' + h : h) + ":" + (m<=9 ? '0' + m : m) + ":" + (s<=9 ? '0' + s : s); 135 | } 136 | else if (inType == "YYYYMMDD") { 137 | strFinalDate = dateYY +"-"+ (dateMM<=9 ? '0' + dateMM : dateMM) +"-"+ (dateDD<=9 ? '0' + dateDD : dateDD) + " " + (h<=9 ? '0' + h : h) + ":" + (m<=9 ? '0' + m : m) + ":" + (s<=9 ? '0' + s : s); 138 | } 139 | else if (inType == "INTLTIME") { 140 | strFinalDate = MONTHS[dateTemp.getMonth()] + " " + (dateDD<=9 ? '0' + dateDD : dateDD) + ", " + dateYY + " " + (h<=9 ? '0' + h : h) + ":" + (m<=9 ? '0' + m : m) + ":" + (s<=9 ? '0' + s : s); 141 | } 142 | else if (inType == "INTL") { 143 | strFinalDate = MONTHS[dateTemp.getMonth()] + " " + (dateDD<=9 ? '0' + dateDD : dateDD) + ", " + dateYY; 144 | } 145 | else if (inType == "ISO") { 146 | strFinalDate = dateYY +"-"+ (dateMM<=9 ? '0' + dateMM : dateMM) +"-"+ (dateDD<=9 ? '0' + dateDD : dateDD) +"T"+ (h<=9 ? '0' + h : h) + ":" + (m<=9 ? '0' + m : m) + ":" + (s<=9 ? '0' + s : s) + ".000Z"; 147 | } 148 | 149 | if ( strFinalDate && (strFinalDate.indexOf("NaN") > -1 || strFinalDate.indexOf("undefined") > -1) ) return ''; 150 | return strFinalDate; 151 | } 152 | 153 | /* =============================================================================================== 154 | | 155 | ###### # ####### 156 | # # # # # ##### # # # #### # # #### ##### # # #### 157 | # # # ## # # # # ## # # # # # # # # # ## ## # 158 | ###### # # # # # # # # # # # # ##### # # # # # ## # #### 159 | # # # # # # # # # # # # # ### # # # # ##### # # # 160 | # # # # ## # # # # ## # # # # # # # # # # # # 161 | ###### # # # ##### # # # #### # # #### # # # # #### 162 | | 163 | ================================================================================================== 164 | */ 165 | 166 | // TODO: Unimplemented/undocumented/undemoed... need to: Validate/Update/Document 167 | function doParseFormIntoJson(inModel, inEleId) { 168 | var objReturn = { 169 | jsonSpData: {}, 170 | jsonFormat: {} 171 | }; 172 | var strCol = ""; 173 | 174 | // STEP 1: REALITY-CHECK: 175 | if ( $('#'+inEleId).length == 0 ) { 176 | var strTemp = 'parseForm ERROR:\n\n'+ inEleId +' does not exist!'; 177 | ( inModel.onFail ) ? inModel.onFail(strTemp) : console.error(strTemp); 178 | return null; 179 | } 180 | 181 | // STEP 2: Parse all form fields into SP-JSON and Formatted values 182 | $('#'+inEleId+' [data-bind]').each(function(i,tag){ 183 | // A: Get column name for this field 184 | // Determine which type of binding we are dealing with: 185 | // CASE 1: 186 | if ( $(this).data('bind').col ) 187 | strCol = $(this).data('bind').col; 188 | // CASE 2: 189 | else if ( $(this).data('bind')[Object.keys($(this).data('bind'))[0]].cols && $.isArray($(this).data('bind')[Object.keys($(this).data('bind'))[0]].cols) ) 190 | strCol = $(this).data('bind')[Object.keys($(this).data('bind'))[0]].cols[0]; 191 | else return; 192 | 193 | // B: Handle fields not in Model (user may want some additional info inserted, etc.) 194 | var dataName = ( inModel.listCols[strCol] ? inModel.listCols[strCol].dataName : strCol ); 195 | 196 | // C: Handle various element types 197 | { 198 | // CASE: 199 | if ( $(this).is(':checkbox') ) { 200 | objReturn.jsonSpData[dataName] = $(this).prop('checked'); 201 | objReturn.jsonFormat[strCol] = APP_STRINGS[APP_OPTS.language][$(this).prop('checked').toString()]; 202 | } 203 | // CASE: 204 | else if ( $(this).val() && $(this).hasClass('hasDatepicker') ) { 205 | objReturn.jsonSpData[dataName] = $(this).datepicker('getDate').toISOString(); 206 | objReturn.jsonFormat[strCol] = ( inModel.listCols[strCol].dateFormat ? bdeLib.localDateStrFromSP(null,$(this).datepicker('getDate'),inModel.listCols[strCol].dateFormat) : $(this).datepicker('getDate').toISOString() ); 207 | } 208 | // CASE: 209 | else if ( $(this).val() && $(this).prop('type') == 'select-one' ) { 210 | objReturn.jsonSpData[dataName] = ($(this).data('type') && ($(this).data('type') == 'num' || $(this).data('type') == 'pct')) ? Number($(this).val()) : $(this).val().toString(); 211 | objReturn.jsonFormat[strCol] = objReturn.jsonSpData[dataName]; 212 | } 213 | // CASE: 214 | else if ( $(this).val() && $(this).prop('type') == 'select-multiple' ) { 215 | // TODO: This is for multi-lookup! Multi-choice w/b different - add code! 216 | // EX: (SP2013/16): { "SkillsId": { "__metadata":{"type":"Collection(Edm.Int32)"}, "results":[1,2,3] } } 217 | var arrIds = []; 218 | $.each($(this).val(), function(i,val){ arrIds.push( Number(val) ); }); 219 | objReturn.jsonSpData[dataName] = { "__metadata":{"type":"Collection(Edm.Int32)"}, "results":arrIds }; 220 | objReturn.jsonFormat[strCol] = arrIds.toString(); 221 | } 222 | // CASE: 223 | else if ( $(this).val() && $(this).is(':radio') ) { 224 | // TODO: FUTURE: Add radiobutton, get value by name or whatever 225 | } 226 | // CASE: