All Projects → koltyakov → sp-pnp-node

koltyakov / sp-pnp-node

Licence: MIT license
SharePoint JavaScript Core Library wrapper helper for Node.js

Programming Languages

typescript
32286 projects
javascript
184084 projects - #8 most used programming language
Dockerfile
14818 projects

Projects that are alternatives of or similar to sp-pnp-node

Spservices
SPServices is a jQuery library which abstracts SharePoint's Web Services and makes them easier to use. It also includes functions which use the various Web Service operations to provide more useful (and cool) capabilities. It works entirely client side and requires no server install.
Stars: ✭ 199 (+696%)
Mutual labels:  sharepoint
pnp-starterkit-setup
x-platform setup script for the SharePoint Starter Kit
Stars: ✭ 14 (-44%)
Mutual labels:  sharepoint
mvp-monitor
📊 Microsoft MVPs Monitor
Stars: ✭ 30 (+20%)
Mutual labels:  sharepoint
Office365dev
《Office 365 开发入门指南》,本书已经于2018年9月份由北京大学出版社上市发行,可以通过 http://product.dangdang.com/25347066.html 进行购买。配套视频教程于2019年2月在网易云课堂上架,你可以通过 https://aka.ms/office365devlesson 参加学习,教程相关的参考资料、范例代码、相关链接,请访问 https://github.com/chenxizhang/office365dev/tree/master/lessons
Stars: ✭ 228 (+812%)
Mutual labels:  sharepoint
vbo365-rest-self-service
Unofficial Self-Service Web Portal for Veeam Backup for Microsoft Office 365
Stars: ✭ 24 (-4%)
Mutual labels:  sharepoint
SPOMod
SharePoint Module for managing lists, items and files. The module is a massive work comprising over 3000 lines of code and 50 SharePoint Online cmdlets for managing: lists list columns list items files content type taxonomy
Stars: ✭ 20 (-20%)
Mutual labels:  sharepoint
Sharepointplus
SharepointPlus ($SP) is a JavaScript library which offers some extended features for SharePoint entirely on client side (requires no server install). $SP will simplify your interactions with Sharepoint.
Stars: ✭ 186 (+644%)
Mutual labels:  sharepoint
productivity-tools
List of popular productivity tools for SharePoint
Stars: ✭ 26 (+4%)
Mutual labels:  sharepoint
camljs
Library for creating SharePoint CAML queries client-side. For JSOM, REST or SPServices.
Stars: ✭ 77 (+208%)
Mutual labels:  sharepoint
SharePoint-Security
A Github Repository Created to compliment a BSides Canberra 2018 talk on SharePoint Security.
Stars: ✭ 42 (+68%)
Mutual labels:  sharepoint
react-taxonomypicker
A Taxonomy Picker control built with TypeScript for React. Built for use in Office 365 / SharePoint
Stars: ✭ 23 (-8%)
Mutual labels:  sharepoint
gulp-spsync-creds
Gulp plugin for synchronizing local files with a SharePoint library via user credentials
Stars: ✭ 12 (-52%)
Mutual labels:  sharepoint
vbo365-rest
Unofficial Self-Service Web Portal for Veeam Backup for Microsoft Office 365
Stars: ✭ 44 (+76%)
Mutual labels:  sharepoint
Sharepointdsc
The SharePointDsc PowerShell module provides DSC resources that can be used to deploy and manage a SharePoint farm
Stars: ✭ 205 (+720%)
Mutual labels:  sharepoint
Awesome-SharePoint-Node.js
A collection of libraries and tools for Node.js runtime dealing with SharePoint
Stars: ✭ 85 (+240%)
Mutual labels:  sharepoint
Phpspo
Office 365 Library for PHP. It allows to performs CRUD operations against Office 365 resources via an REST/OData based API
Stars: ✭ 198 (+692%)
Mutual labels:  sharepoint
cisar
SharePoint CSR Live Editor (Chrome extension)
Stars: ✭ 73 (+192%)
Mutual labels:  sharepoint
BlazorPoint
Blazor (Client Side) on SharePoint
Stars: ✭ 40 (+60%)
Mutual labels:  sharepoint
SharePoint-Patch-Script
An updated version of Russ Maxwell's "5 hour" SharePoint Patch Script supporting SharePoint 2013, 2016, and 2019.
Stars: ✭ 48 (+92%)
Mutual labels:  sharepoint
List-Formatting
List Formatting Samples for use in SharePoint and Microsoft Lists
Stars: ✭ 1,227 (+4808%)
Mutual labels:  sharepoint

sp-pnp-node - PnPjs's auth client factory for Node.js

NPM

npm version Downloads Build Status Gitter chat

Consider using pnp-auth as a successor which soaked the best of sp-pnp-node and node-pnp-sp libraries. I'm keeping sp-pnp-node not archived and update it from time to time only because of some production implementations which I'm too lazy to migrate to pnp-auth right away.

sp-pnp-node provides a simple way for using PnPjs in Node.js with support of various authentication strategies.

About PnPjs

PnPjs Client Side Libraries for Microsoft 365 was created to help developers by simplifying common operations within SharePoint and the SharePoint Framework. Currently it contains a fluent API for working with the full SharePoint REST API as well as utility and helper functions. This takes the guess work out of creating REST requests, letting developers focus on the what and less on the how.

Supported SharePoint versions

  • SharePoint Online
  • SharePoint On-Prem (2019, 2016, 2013)

Install

npm install sp-pnp-node @pnp/pnpjs@^1.3.11

Usage examples

Minimal setup

Can be as simple as 5 lines of code:

import { Web } from '@pnp/sp';
import { PnpNode } from 'sp-pnp-node';

new PnpNode().init().then(settings => {

  const web = new Web(settings.siteUrl);
  /// ... // <<< Here goes PnP JS Core code

}).catch(console.log);

demo

sp-pnp-node has two modes:

  • ambient init - wraps PnPjs with promise based auth wizard helper
  • factory - fetchClientFactory implementation

When to use ambient init: in scripts with user interaction involved when there is no information about authentication and target invironment before script is executed. SharePoint url and the creds are prompted in a console.

In CI/CD scenarios, factory approach is recommended over interactive console as it can lead to a task stuck.

TypeScript

Ambient init example

import { Web } from '@pnp/sp';
import { PnpNode, IPnpNodeSettings } from 'sp-pnp-node';

const optionalInitSettings: IPnpNodeSettings = {
  // ...
};

new PnpNode(optionalInitSettings).init().then((settings: IPnpNodeSettings) => {

  // Here goes PnP JS Core code >>>

  const web = new Web(settings.siteUrl);
  // Any SPWeb url can be used for `new Web(...)`
  // not necessarily which is provided in `optionalInitSettings`

  // Get all list example
  web.lists.get()
    .then(lists => {
      console.log(lists.map(list => list.Title));
    })
    .catch(console.log);

  // <<< Here goes PnP JS Core code

}).catch(console.log);

Factory example

import * as pnp from '@pnp/sp';
import { PnpNode, IPnpNodeSettings } from 'sp-pnp-node';

const config = require('../config/private.json');

const pnpNodeSettings: IPnpNodeSettings = {
  // siteUrl - Optional if baseUrl is in pnp.setup or in case of `new Web(url)`
  siteUrl: config.siteUrl,
  authOptions: config
};

pnp.sp.setup({
  sp: {
    fetchClientFactory: () => new PnpNode(pnpNodeSettings),
    // baseUrl - Optional if siteUrl is in IPnpNodeSettings or in case of `new Web(url)`
    baseUrl: config.siteUrl
  }
});

pnp.sp.web.get()
  .then(console.log)
  .catch(console.log);

// Or

/*
new Web('http://adhoc.url/sites/site').get()
  .then(console.log)
  .catch(console.log);
*/

JavaScript

const { Web } = require('@pnp/sp');
const { PnpNode } = require('sp-pnp-node');

new PnpNode().init().then(settings => {

  // Here goes PnP JS Core code >>>

  const web = new Web(settings.siteUrl);

  // Get all content types example
  web.contentTypes.get()
    .then(cts => {
      console.log(cts.map(ct => {
        return {
          name: ct.Name,
          description: ct.Description
        };
      }));
    })
    .catch(console.log);

  // <<< Here goes PnP JS Core code

}).catch(console.log);

OData Metadata modes

import { sp } from '@pnp/sp';
import { PnpNode, IPnpNodeSettings } from 'sp-pnp-node';

new PnpNode().init().then((settings: IPnpNodeSettings) => {

  sp.setup({
    sp: {
      headers: {
        // 'Accept': 'application/json;odata=verbose'
        'Accept': 'application/json;odata=minimalmetadata'
        // 'Accept': 'application/json;odata=nometadata'
      }
    }
  });

  // ...

}).catch(console.log);

Initiation settings

import { PnpNode } from 'sp-pnp-node';

const pnpNodeSettings: IPnpNodeSettings = {
  /// ...
};

new PnpNode(pnpNodeSettings).init().then(settings => {

  // Here goes PnP JS Core code

}).catch(console.log);

Raw Fetch client usage

import { PnpNode } from 'sp-pnp-node';

declare const global: any;

new PnpNode().init().then(settings => {

  // Any raw RESP API requests with Fetch client
  global.fetch(`${settings.siteUrl}/_api/web`, {
    method: 'GET',
    headers: {
      accept: 'application/json;odata=minimalmetadata'
    }
  })
    .then(response => response.json())
    .then(console.log)
    .catch(console.log);

});

PnP Node Settings options

  • siteUrl?: string; // Optional SPWeb url
  • authOptions?: IAuthOptions; node-sp-auth credentials options
  • config?: IAuthConf; node-sp-auth-config options
    • configPath?: string; // Path to auth config .json | Default is './config/private.json'
    • encryptPassword?: boolean; // Encrypts password to a machine-bind hash | Default is 'true'
    • saveConfigOnDisk?: boolean; // Saves config .json to disk | Default is 'true'

Settings can be left blank. Auth options in such a case will be asked by node-sp-auth-config options in a wizard like approach.

Settings scenarios

  • No initial settings (defaults): wizard approach, covers console applications cases with user interaction
  • With explicitly defined authOptions:
    • external tools is in charge for preparing auth credentials in node-sp-auth format
    • credentials should not be dumped on disc
  • Config file with prepopulated credentials: schedule, job automation, continues integration

Supported authentication scenarios

  • SharePoint On-Premise (2013, 2016):

    • User credentials (NTLM)
    • Form-based authentication (FBA)
    • Add-In Only permissions
    • ADFS user credentials
  • SharePoint Online:

    • User credentials (SAML)
    • Add-In Only permissions
    • ADFS user credentials

Inspiration and references

This project was inspired by Sergei Sergeev and Patrick Rodgers. Main ideas were taken from node-pnpjs-sample and Using PnP JS Core and node-sp-auth. The result project implements the same concepts with a goal of reusability and maintenance simplification.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].