npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

sprestlib

v1.9.0

Published

SharePoint REST Web Services JavaScript Library

Downloads

3,398

Readme

npm version Open Source Love MIT License Package Quality Known Vulnerabilities

SpRestLib

SharePoint REST Web Services JavaScript Library

Provides a concise, promise-based API that simplifies asynchronous REST interaction with SharePoint. Easily read/write List items, execute REST calls, interact with files and folders, gather site properties, and query user information. Enables rapid development of SharePoint Apps/Add-ins using the JavaScript SharePoint App Model.

Library Features

  • Simple - Most SharePoint web service calls are a few lines of code
  • Modern - Lightweight, pure JavaScript solution with no other dependencies
  • Elegant - Utilizes the new ES6 Promise architecture for asynchronous operations
  • Robust - Built for SharePoint 2013 API and OData v3

SharePoint Interfaces

  • List Methods - Create, read, update, and delete (CRUD) List/Library items, including support for paging/next
  • User Methods - Get User information: Basic (ID, Email, LoginName, etc.) and UserProfile (Manager, 100+ Properties)
  • Site Methods - Get Site information (Lists, Groups, Users, Roles, Subsites and Permissions)
  • File Methods - Get files, file properties/permissions, delete/recycle files
  • Folder Methods - Get folder contents, folder properties/permissions, create/delete/recycle folders
  • REST Methods - Execute REST API calls against any available SharePoint REST API endpoint
  • Form Population - Populate form elements using data-bind declarative binding system like Knockout or AngluarJS

Supported Environments

  • SharePoint 2013 (SP2013), SharePoint 2016 (SP2016), Office 365 SharePoint Online (SPO)

Method Overview

REST API

List/Library

  • sprLib.list(listName).items(options) - Returns an array of SP.ListItem objects using a variety of query options
  • sprLib.list(listName).create(item) - Create a new list item using JSON data
  • sprLib.list(listName).update(item) - Update an existing item using JSON data
  • sprLib.list(listName).delete(item) - Delete an existing item using JSON data (permanently delete)
  • sprLib.list(listName).recycle(item) - Recycle an existing item using JSON data (move to Recycle Bin)
  • sprLib.list(listName).cols() - Returns an array of column properties (datatype, default values, etc.)
  • sprLib.list(listName).info() - Returns SP.List properties (last modified, number of items, etc.)
  • sprLib.list(listName).perms() - Returns an array of the list's Member Role assignments

File

  • sprLib.file(fileName).get() - Returns a file (binary/text) as a blob which can be saved
  • sprLib.file(fileName).info() - Returns SP.File properties (Created, GUID, HasUniquePerms, etc.)
  • sprLib.file(fileName).perms() - Returns an array of the file's Member Role assignments
  • sprLib.file(fileName).checkin() - Check in a file (supports optional comments/checkin types)
  • sprLib.file(fileName).checkout() - Check out a file
  • sprLib.file(fileName).delete() - Permanently deletes a file (bypasses recycle bin)
  • sprLib.file(fileName).recycle() - Moves file to the site Recycle Bin

Folder

  • sprLib.folder(folderName).files() - Returns an array of file objects contained in the folder
  • sprLib.folder(folderName).folders() - Returns an array of folder objects contained in the folder
  • sprLib.folder(folderName).info() - Returns SP.Folder properties (Created, GUID, HasUniquePerms, etc.)
  • sprLib.folder(folderName).perms() - Returns an array of the folder's Member Role assignments
  • sprLib.folder(folderName).add() - Creates a new folder under the parent folder
  • sprLib.folder(folderName).delete() - Permanently deletes a folder (bypasses recycle bin)
  • sprLib.folder(folderName).recycle() - Moves folder to the site Recycle Bin

Site Collection/Subsite

  • sprLib.site(siteUrl).groups() - Returns an array of the site's Groups and Members
  • sprLib.site(siteUrl).info() - Returns SP.Web site properties (ID, Owner, Language, Logo, etc.)
  • sprLib.site(siteUrl).lists() - Returns an array of the site's Lists/Libraries
  • sprLib.site(siteUrl).perms() - Returns an array of the site's Member/Roles objects
  • sprLib.site(siteUrl).roles() - Returns an array of the site's Roles
  • sprLib.site(siteUrl).subsites() - Returns an array of the site's Subsites
  • sprLib.site(siteUrl).users() - Returns an array of the site's Users and their base permissions

User Groups/Info/Profile

  • sprLib.user(options).groups() - Returns SP.Group group properties (Id, Owner, Title, etc.)
  • sprLib.user(options).info() - Returns SP.User user properties (Id, Email, Login, Title, etc.)
  • sprLib.user(options).profile() - Returns SP.UserProfile.PersonProperties (DirectReports, PictureUrl, etc.)

Utility Methods

  • sprLib.renewSecurityToken() - Refreshes the SharePoint page security digest token (__REQUESTDIGEST)

SpRestLib-UI :: Form Population

  • data-sprlib{options} - Populates the parent tag using the options provided


Library Demo

Demo via Browser Console

It's really easy to test drive SpRestLib!

Just open your browser's Developer Tools window anywhere on your SharePoint site, then run the following code snippet which will load the SpRestLib bundle script dynamically:

// Load/Demo SpRestLib via CDN
var script = document.createElement('script');
script.src = "https://cdn.jsdelivr.net/gh/gitbrent/[email protected]/dist/sprestlib.bundle.js";
script.onload = function(){
    // Demo library method - show current user info
    console.log('Current SharePoint User: ');
    sprLib.user().info().then( objUser => console.log(objUser) );
}
document.getElementsByTagName('head')[0].appendChild(script);

Try It Out

Demo via Page Webpart

Upload the example/sprestlib-demo.html file to SiteAssets on your SharePoint site and add it into a Webpart for a live demo of all available methods.

Demo Webpart


Installation

CDN

<script src="https://cdn.jsdelivr.net/gh/gitbrent/[email protected]/dist/sprestlib.min.js"></script>
// Use bundle for IE11 support
<script src="https://cdn.jsdelivr.net/gh/gitbrent/[email protected]/dist/sprestlib.bundle.js"></script>

Download

<script src="/subsite/SiteAssets/js/sprestlib.min.js"></script>
// Use bundle for IE11 support
<script src="/subsite/SiteAssets/js/sprestlib.bundle.js"></script>

npm

npm install sprestlib

var sprLib = require("sprestlib");

yarn

yarn install sprestlib

Method Reference

REST API Methods

REST API Methods

List/Library Methods (SP.List)

List/Library Methods

File Methods (SP.File)

File Methods

Folder Methods (SP.Folder)

Folder Methods

Site Methods (SP.Web)

Site Methods

User Methods (SP.User)

User Methods

Utility Methods

Utility Methods

Form Binding (SpRestLib UI)

Form Binding


Library Features and Notes

Async Operations via Promises

JavaScript Async Promises

SharePoint Authentication Notes

SharePoint Authentication Notes

Integration with Other Libraries

Using SpRestLib with React, Angular, SharePoint Electron, etc. Integration with Other Libraries

Connect to SharePoint Online/Office.com with Node.js

  • SpRestLib can be utilized via Node.js to perform powerful operations, generate reports, etc.
  • See the example directory for a complete, working demo of connecting to SharePoint Online.

Issues / Suggestions

Authentication

See SharePoint Authentication Notes for issues with authentication.

Bugs

Please file issues or suggestions on the issues page on GitHub, or even better, submit a pull request. Feedback is always welcome!

When reporting issues, please include a code snippet or a link demonstrating the problem.


Supported SharePoint Versions

Backwards Compatibility

Does SpRestLib support SharePoint 2010 or 2007?
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.


Special Thanks

  • Marc D Anderson - SpRestLib is built in the spirit of the late, great SPServices library
  • Microsoft - for the SharePoint.com developer account
  • Everyone who submitted an Issue or Pull Request

License

Copyright © 2016-2018 Brent Ely

MIT