diff --git a/AUTHORS b/AUTHORS index df68c5314..61b1eaf0b 100644 --- a/AUTHORS +++ b/AUTHORS @@ -5,3 +5,9 @@ Patrick Rodgers, Microsoft (patrick-rodgers) Ademosu Ayodele (aaademosu) Tomi Tavela (tavikukko) Chris Kent (thechriskent) +Waldek Mastykarzk, Microsoft (waldekmastykarz) +jesse (barkdoll) +Superior (SuperioOne) +Robert Lindström (robert-lindstrom) +Marc D Anderson (sympmarc) +(lch-dbrown) diff --git a/CHANGELOG.md b/CHANGELOG.md index d262c034a..f85a5d715 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,6 +5,35 @@ All notable changes to this project will be documented in this file. The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/) and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.html). +## 3.2.0 - 2022-April-08 + +### Fixed + +- node: + - Fix for CommonJS imports with ESM modules. + +- sp: + - Fix issue with sendEmail utility. + - Bug fixes for getAllChildrenAsOrderedTree in Taxonomy. + - Update for issues with stale requestdigest. + - Bug fix for client-side pages for home page so that title is read from the json blob. + - Remove user-agent header for throttling as no longer used. + - Bug fix for renderListDataAsStream method + +- graph: + - Added getById method to Sites. + - Added transitiveMemberOf method to User. + - Added installedApps method to a Team. + +- docs: + - Various documentation copy/paste and typo fixes. + - Updates for getting-started guidance for imports of both @pnp/sp and @pnp/graph in SPFx. + - Updates to remove documentation showing batching adding files; includes new tag on all areas of library that are not supported for batching. + - New documentation for Graph to get SharePoint sites. + - New doucmentation for updating a BCS field in SharePoint. + - Added Graph memberOf and transitiveMemberOf properties. + - Updated docs on the Web() method. + ## 3.1.0 - 2022-March-11 - sp: @@ -17,15 +46,11 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0. ## 3.0.3 - 2022-March-3 -### Fixed - - sp: - Issues preventing search queries from running. #2124 ## 3.0.2 - 2022-Feb-22 -### Fixed - - sp: - Issue in SPFx behavior with improperly using current web's request digest for non-current web calls #2102 @@ -35,8 +60,6 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0. ## 3.0.1 - 2022-Feb-15 -### Fixed - - sp: - Fixed root property initializers #2082 diff --git a/docs/concepts/authentication.md b/docs/concepts/authentication.md index 3c4f4b6c9..2a62e44c0 100644 --- a/docs/concepts/authentication.md +++ b/docs/concepts/authentication.md @@ -48,7 +48,7 @@ import { SPFx, spfi } from "@pnp/sp"; import "@pnp/sp/webs"; // within a webpart, application customizer, or adaptive card extension where the context object is available -const sp = spfi().using(SPFx(this.context)); +const sp = spfi(...); const webData = await sp.web(); ``` diff --git a/docs/concepts/batching-caching.md b/docs/concepts/batching-caching.md index 1adee6d1b..e9932b2d3 100644 --- a/docs/concepts/batching-caching.md +++ b/docs/concepts/batching-caching.md @@ -3,12 +3,12 @@ When optimizing for performance you can combine [batching](batching.md) and [caching](../queryable/behaviors.md#caching) to reduce the overall number of requests. On the first request any cachable data is stored as expected once the request completes. On subsequent requests if data is found in the cache it is returned immediately and that request is not added to the batch, in fact the batch will never register the request. This can work across many requests such that some returned cached data and others do not - the non-cached requests will be added to and processed by the batch as expected. ```TypeScript -import { spfi, SPFx } from "@pnp/sp"; +import { spfi } from "@pnp/sp"; import "@pnp/sp/webs"; import "@pnp/sp/lists"; import { Caching } from "@pnp/queryable"; -const sp = spfi("https://318studios.sharepoint.com/sites/dev").using(SPFx(this.context)); +const sp = spfi(...); const [batchedSP, execute] = await sp.batched(); @@ -36,12 +36,12 @@ await execute2(); In this second example we include an update to the web's title. Because non-get requests are never cached the update code will always run, but the results from the two get requests will resolve from the cache prior to being added to the batch. ```TypeScript -import { spfi, SPFx } from "@pnp/sp"; +import { spfi } from "@pnp/sp"; import "@pnp/sp/webs"; import "@pnp/sp/lists"; import { Caching } from "@pnp/queryable"; -const sp = spfi("https://318studios.sharepoint.com/sites/dev").using(SPFx(this.context)); +const sp = spfi(...); const [batchedSP, execute] = await sp.batched(); diff --git a/docs/concepts/batching.md b/docs/concepts/batching.md index 6966cd299..ade964c84 100644 --- a/docs/concepts/batching.md +++ b/docs/concepts/batching.md @@ -5,12 +5,12 @@ Where possible batching can significantly increase application performance by co ## SP Example ```TypeScript -import { spfi, SPFx } from "@pnp/sp"; +import { spfi } from "@pnp/sp"; import "@pnp/sp/webs"; import "@pnp/sp/lists"; import "@pnp/sp/batching"; -const sp = spfi().using(SPFx(this.context)); +const sp = spfi(...); const [batchedSP, execute] = sp.batched(); @@ -35,12 +35,12 @@ for(let i = 0; i < res.length; i++) { ### Using a batched web ```TypeScript -import { spfi, SPFx } from "@pnp/sp"; +import { spfi } from "@pnp/sp"; import "@pnp/sp/webs"; import "@pnp/sp/lists"; import "@pnp/sp/batching"; -const sp = spfi().using(SPFx(this.context)); +const sp = spfi(...); const [batchedWeb, execute] = sp.web.batched(); diff --git a/docs/contributing/extending-the-library.md b/docs/contributing/extending-the-library.md index fe65ed727..363224fa2 100644 --- a/docs/contributing/extending-the-library.md +++ b/docs/contributing/extending-the-library.md @@ -38,10 +38,11 @@ And the matching graph type: The general idea of a factory function is that it takes two parameters. The first is either a string or Queryable derivative which forms base for the new object. The second is the next part of the url. In some cases (like the webs property example above) you will note there is no second parameter. Some classes are decorated with defaultPath, which automatically fills the second param. Don't worry too much right now about the deep internals of the library, let's instead focus on some concrete examples. ```TypeScript +import { SPFx } from "@pnp/sp"; import { Web } from "@pnp/sp/webs"; // create a web from an absolute url -const web = Web("https://tenant.sharepoint.com"); +const web = Web("https://tenant.sharepoint.com").using(SPFx(this.context)); // as an example, create a new web using the first as a base // targets: https://tenant.sharepoint.com/sites/dev diff --git a/docs/getting-started.md b/docs/getting-started.md index 44161897f..aa8ec4973 100644 --- a/docs/getting-started.md +++ b/docs/getting-started.md @@ -82,6 +82,8 @@ Because SharePoint Framework provides a local context to each component we need Depending on how you architect your solution establishing context is done where you want to make calls to the API. The examples demonstrate doing so in the onInit method as a local variable but this could also be done to a private variable or passed into a service. +>Note if you are going to use both the @pnp/sp and @pnp/graph packages in SPFx you will need to alias the SPFx behavior import, please see the [section](#using-both-pnpsp-and-pnpgraph-in-spfx) below for more details. + ### Using @pnp/sp `spfi` factory interface in SPFx ```TypeScript @@ -92,8 +94,8 @@ import { spfi, SPFx } from "@pnp/sp"; protected async onInit(): Promise { await super.onInit(); - const sp = spfi().using(SPFx(this.context)); - + const sp = spfi().using(spSPFx(this.context)); + } // ... @@ -118,6 +120,27 @@ protected async onInit(): Promise { ``` +### Using both @pnp/sp and @pnp/graph in SPFx + +```TypeScript + +import { spfi, SPFx as spSPFx } from "@pnp/sp"; +import { graphfi, SPFx as graphSPFx} from "@pnp/graph"; + +// ... + +protected async onInit(): Promise { + + await super.onInit(); + const sp = spfi().using(spSPFx(this.context)); + const graph = graphfi().using(graphSPFx(this.context)); + +} + +// ... + +``` + ### Establish context within an SPFx service Because you do not have full access to the context object within a service you need to setup things a little differently. If you do not need AAD tokens you can leave that part out and specify just the pageContext (Option 2). @@ -154,8 +177,6 @@ export class SampleService { //Option 2 - without AADTokenProvider this._sp = spfi().using(SPFx({ pageContext })); - - }); } public getLists(): Promise { @@ -172,7 +193,7 @@ export class SampleService { To call the SharePoint APIs via MSAL you are required to use certificate authentication with your application. Fully covering certificates is outside the scope of these docs, but the following commands were used with openssl to create testing certs for the sample code below. -``` +```cmd mkdir \temp cd \temp openssl req -x509 -newkey rsa:2048 -keyout keytmp.pem -out cert.pem -days 365 -passout pass:HereIsMySuperPass -subj '/C=US/ST=Washington/L=Seattle' @@ -269,6 +290,7 @@ You must install TypeScript @next or you will get errors using node12 module res The tsconfig file for your project should have the `"module": "CommonJS"` and `"moduleResolution": "node12",` settings in addition to whatever else you need. _tsconfig.json_ + ```JSON { "compilerOptions": { @@ -280,6 +302,7 @@ _tsconfig.json_ You must then import the esm dependencies using the async import pattern. This works as expected with our selective imports, and vscode will pick up the intellisense as expected. _index.ts_ + ```TypeScript import { settings } from "./settings.js"; @@ -312,7 +335,6 @@ Finally, when launching node you need to include the `` flag with a setting of ' > Read more in the releated [TypeScript Issue](https://github.com/microsoft/TypeScript/issues/43329), [TS pull request Adding the functionality](https://github.com/microsoft/TypeScript/pull/45884), and the [TS Docs](https://www.typescriptlang.org/tsconfig#moduleResolution). - ## Single Page Application Context In some cases you may be working in a client-side application that doesn't have context to the SharePoint site. In that case you will need to utilize the MSAL Client, you can get the details on creating that connection in this [article](./concepts/authentication.md#MSAL-in-Browser). @@ -341,7 +363,7 @@ import { AssignFrom } from "@pnp/core"; import "@pnp/sp/webs"; //Connection to the current context's Web -const sp = spfi().using(SPFx(this.context)); +const sp = spfi(...); // Option 1: Create a new instance of Queryable const spWebB = spfi({Other Web URL}).using(SPDefault(this.context)); diff --git a/docs/graph/behaviors.md b/docs/graph/behaviors.md index ef5dfef54..1956f207c 100644 --- a/docs/graph/behaviors.md +++ b/docs/graph/behaviors.md @@ -106,11 +106,11 @@ await graph.users(); This behavior is designed to work closely with SPFx. The only parameter is the current SPFx Context. `SPFx` is a composed behavior including DefaultHeaders, DefaultInit, BrowserFetchWithRetry, and DefaultParse. It also replaces any authentication present with a method to get a token from the SPFx aadTokenProviderFactory. ```TypeScript -import { graphfi, SPFx } from "@pnp/graph"; +import { graphfi } from "@pnp/graph"; import "@pnp/graph/users"; // this.context represents the context object within an SPFx webpart, application customizer, or ACE. -const graph = graphfi().using(SPFx(this.context)); +const graph = graphfi(...); await graph.users(); ``` @@ -128,7 +128,7 @@ const graph = graphfi().using(graphSPFx(this.context)); If you want to use a different form of authentication you can apply that behavior after `SPFx` to override it. In this case we are using the [client MSAL authentication](../msaljsclient). ```TypeScript -import { graphfi, SPFx } from "@pnp/graph"; +import { graphfi } from "@pnp/graph"; import { MSAL } from "@pnp/msaljsclient"; import "@pnp/graph/users"; diff --git a/docs/graph/calendars.md b/docs/graph/calendars.md index d7c475a26..b9b195068 100644 --- a/docs/graph/calendars.md +++ b/docs/graph/calendars.md @@ -12,11 +12,11 @@ More information can be found in the official Graph documentation: ## Get All Calendars For a User ```TypeScript -import { graphfi, SPFx } from "@pnp/graph"; +import { graphfi } from "@pnp/graph"; import '@pnp/graph/calendars'; import '@pnp/graph/users'; -const graph = graphfi().using(SPFx(this.context)); +const graph = graphfi(...); const calendars = await graph.users.getById('user@tenant.onmicrosoft.com').calendars(); @@ -27,11 +27,11 @@ const myCalendars = await graph.me.calendars(); ## Get a Specific Calendar For a User ```TypeScript -import { graphfi, SPFx } from "@pnp/graph"; +import { graphfi } from "@pnp/graph"; import '@pnp/graph/calendars'; import '@pnp/graph/users'; -const graph = graphfi().using(SPFx(this.context)); +const graph = graphfi(...); const CALENDAR_ID = 'AQMkAGZjNmY0MDN3LRI3YTYtNDQAFWQtOWNhZC04MmY3MGYxODkeOWUARgAAA-xUBMMopY1NkrWA0qGcXHsHAG4I-wMXjoRMkgRnRetM5oIAAAIBBgAAAG4I-wMXjoRMkgRnRetM5oIAAAIsYgAAAA=='; @@ -43,11 +43,11 @@ const myCalendar = await graph.me.calendars.getById(CALENDAR_ID)(); ## Get a User's Default Calendar ```TypeScript -import { graphfi, SPFx } from "@pnp/graph"; +import { graphfi } from "@pnp/graph"; import '@pnp/graph/calendars'; import '@pnp/graph/users'; -const graph = graphfi().using(SPFx(this.context)); +const graph = graphfi(...); const calendar = await graph.users.getById('user@tenant.onmicrosoft.com').calendar(); @@ -57,11 +57,11 @@ const myCalendar = await graph.me.calendar(); ## Get Events For a User's Default Calendar ```TypeScript -import { graphfi, SPFx } from "@pnp/graph"; +import { graphfi } from "@pnp/graph"; import '@pnp/graph/calendars'; import '@pnp/graph/users'; -const graph = graphfi().using(SPFx(this.context)); +const graph = graphfi(...); // You can get the default calendar events const events = await graph.users.getById('user@tenant.onmicrosoft.com').calendar.events(); @@ -79,11 +79,11 @@ const events = await graph.me.events(); You can use .events.getByID to search through all the events in all calendars or narrow the request to a specific calendar. ```TypeScript -import { graphfi, SPFx } from "@pnp/graph"; +import { graphfi } from "@pnp/graph"; import '@pnp/graph/calendars'; import '@pnp/graph/users'; -const graph = graphfi().using(SPFx(this.context)); +const graph = graphfi(...); const CalendarID = 'AQMkAGZjNmY0MDN3LRI3YTYtNDQAFWQtOWNhZC04MmY3MGYxODkeOWUARgAAA=='; @@ -106,11 +106,11 @@ const events = await graph.me.calendars.getByID(CalendarID).events.getByID(Event This will work on any `IEvents` objects (e.g. anything accessed using an `events` key). ```TypeScript -import { graphfi, SPFx } from "@pnp/graph"; +import { graphfi } from "@pnp/graph"; import '@pnp/graph/calendars'; import '@pnp/graph/users'; -const graph = graphfi().using(SPFx(this.context)); +const graph = graphfi(...); await graph.users.getById('user@tenant.onmicrosoft.com').calendar.events.add( { @@ -147,11 +147,11 @@ await graph.users.getById('user@tenant.onmicrosoft.com').calendar.events.add( This will work on any `IEvents` objects (e.g. anything accessed using an `events` key). ```TypeScript -import { graphfi, SPFx } from "@pnp/graph"; +import { graphfi } from "@pnp/graph"; import '@pnp/graph/calendars'; import '@pnp/graph/users'; -const graph = graphfi().using(SPFx(this.context)); +const graph = graphfi(...); const EVENT_ID = 'BBMkAGZjNmY6MDM3LWI3YTYtNERhZC05Y2FkLTgyZjcwZjE4OTI5ZQBGAAAAAAD8VQTDKKWNTY61gNKhnFzLBwBuCP8DF46ETJIEZ0XrTOaCAAAAAAENAABuCP8DF46ETJFEZ0EnTOaCAAFvdoJvAAA='; @@ -165,11 +165,11 @@ await graph.users.getById('user@tenant.onmicrosoft.com').calendar.events.getById This will work on any `IEvents` objects (e.g. anything accessed using an `events` key). ```TypeScript -import { graphfi, SPFx } from "@pnp/graph"; +import { graphfi } from "@pnp/graph"; import '@pnp/graph/calendars'; import '@pnp/graph/users'; -const graph = graphfi().using(SPFx(this.context)); +const graph = graphfi(...); const EVENT_ID = 'BBMkAGZjNmY6MDM3LWI3YTYtNERhZC05Y2FkLTgyZjcwZjE4OTI5ZQBGAAAAAAD8VQTDKKWNTY61gNKhnFzLBwBuCP8DF46ETJIEZ0XrTOaCAAAAAAENAABuCP8DF46ETJFEZ0EnTOaCAAFvdoJvAAA='; @@ -181,7 +181,7 @@ await graph.me.events.getById(EVENT_ID).delete(); ## Get Calendar for a Group ```TypeScript -import { graphfi, SPFx } from "@pnp/graph"; +import { graphfi } from "@pnp/graph"; import '@pnp/graph/calendars'; import '@pnp/graph/groups'; @@ -193,11 +193,11 @@ const calendar = await graph.groups.getById('21aaf779-f6d8-40bd-88c2-4a03f456ee8 ## Get Events for a Group ```TypeScript -import { graphfi, SPFx } from "@pnp/graph"; +import { graphfi } from "@pnp/graph"; import '@pnp/graph/calendars'; import '@pnp/graph/groups'; -const graph = graphfi().using(SPFx(this.context)); +const graph = graphfi(...); // You can do one of const events = await graph.groups.getById('21aaf779-f6d8-40bd-88c2-4a03f456ee82').calendar.events(); @@ -210,11 +210,11 @@ const events = await graph.groups.getById('21aaf779-f6d8-40bd-88c2-4a03f456ee82' Gets the events in a calendar during a specified date range. ```TypeScript -import { graphfi, SPFx } from "@pnp/graph"; +import { graphfi } from "@pnp/graph"; import '@pnp/graph/calendars'; import '@pnp/graph/users'; -const graph = graphfi().using(SPFx(this.context)); +const graph = graphfi(...); // basic request, note need to invoke the returned queryable const view = await graph.users.getById('user@tenant.onmicrosoft.com').calendarView("2020-01-01", "2020-03-01")(); @@ -233,11 +233,11 @@ const view4 = await graph.me.calendarView("2020-01-01", "2020-03-01")(); Gets the `emailAddress` objects that represent all the meeting rooms in the user's tenant or in a specific room list. ```TypeScript -import { graphfi, SPFx } from "@pnp/graph"; +import { graphfi } from "@pnp/graph"; import '@pnp/graph/calendars'; import '@pnp/graph/users'; -const graph = graphfi().using(SPFx(this.context)); +const graph = graphfi(...); // basic request, note need to invoke the returned queryable const rooms1 = await graph.users.getById('user@tenant.onmicrosoft.com').findRooms()(); // you can pass a room list to filter results @@ -253,11 +253,11 @@ Get the instances (occurrences) of an event for a specified time range. If the event is a `seriesMaster` type, this returns the occurrences and exceptions of the event in the specified time range. ```TypeScript -import { graphfi, SPFx } from "@pnp/graph"; +import { graphfi } from "@pnp/graph"; import '@pnp/graph/calendars'; import '@pnp/graph/users'; -const graph = graphfi().using(SPFx(this.context)); +const graph = graphfi(...); const event = graph.me.events.getById(''); // basic request, note need to invoke the returned queryable const instances = await event.instances("2020-01-01", "2020-03-01")(); diff --git a/docs/graph/cloud-communications.md b/docs/graph/cloud-communications.md index f37d8671b..44f557354 100644 --- a/docs/graph/cloud-communications.md +++ b/docs/graph/cloud-communications.md @@ -15,11 +15,11 @@ More information can be found in the official Graph documentation: Gets a list of all the contacts for the user. ```TypeScript -import { graphfi, SPFx } from "@pnp/graph"; +import { graphfi } from "@pnp/graph"; import "@pnp/graph/users"; import "@pnp/graph/cloud-communications"; -const graph = graphfi().using(SPFx(this.context)); +const graph = graphfi(...); const presenceMe = await graph.me.presence(); @@ -30,10 +30,10 @@ const presenceThem = await graph.users.getById("99999999-9999-9999-9999-99999999 ## Get presence for multiple users ```TypeScript -import { graphfi, SPFx } from "@pnp/graph"; +import { graphfi } from "@pnp/graph"; import "@pnp/graph/cloud-communications"; -const graph = graphfi().using(SPFx(this.context)); +const graph = graphfi(...); const presenceList = await graph.communications.getPresencesByUserId(["99999999-9999-9999-9999-999999999999"]); diff --git a/docs/graph/contacts.md b/docs/graph/contacts.md index 7e510f160..7a1ff1196 100644 --- a/docs/graph/contacts.md +++ b/docs/graph/contacts.md @@ -21,11 +21,11 @@ Contact ID, Folder ID, and Parent Folder ID use the following format "AAMkADY1OT Gets a list of all the contacts for the user. ```TypeScript -import { graphfi, SPFx } from "@pnp/graph"; +import { graphfi } from "@pnp/graph"; import "@pnp/graph/users" import "@pnp/graph/contacts" -const graph = graphfi().using(SPFx(this.context)); +const graph = graphfi(...); const contacts = await graph.users.getById('user@tenant.onmicrosoft.com').contacts(); @@ -38,11 +38,11 @@ const contacts2 = await graph.me.contacts(); Gets a specific contact by ID for the user. ```TypeScript -import { graphfi, SPFx } from "@pnp/graph"; +import { graphfi } from "@pnp/graph"; import "@pnp/graph/users"; import "@pnp/graph/contacts"; -const graph = graphfi().using(SPFx(this.context)); +const graph = graphfi(...); const contactID = "AAMkADY1OTQ5MTM0LTU2OTktNDI0Yy1iODFjLWNiY2RmMzNjODUxYwBGAAAAAAC75QV12PBiRIjb8MNVIrJrBwBgs0NT6NreR57m1u_D8SpPAAAAAAEOAABgs0NT6NreR57m1u_D8SpPAAFCCnApAAA="; @@ -57,12 +57,12 @@ const contact2 = await graph.me.contacts.getById(contactID)(); Adds a new contact for the user. ```TypeScript -import { graphfi, SPFx } from "@pnp/graph"; +import { graphfi } from "@pnp/graph"; import { EmailAddress } from "@microsoft/microsoft-graph-types"; import "@pnp/graph/users"; import "@pnp/graph/contacts"; -const graph = graphfi().using(SPFx(this.context)); +const graph = graphfi(...); const addedContact = await graph.users.getById('user@tenant.onmicrosoft.com').contacts.add('Pavel', 'Bansky', [{address: 'pavelb@fabrikam.onmicrosoft.com', name: 'Pavel Bansky' }], ['+1 732 555 0102']); @@ -75,11 +75,11 @@ const addedContact2 = await graph.me.contacts.add('Pavel', 'Bansky', [document.getElementById("thefileinput"); const file = input.files[0]; @@ -59,11 +59,11 @@ await graph.me.photo.setContent(file); ## Set Group Photo ```TypeScript -import { graphfi, SPFx } from "@pnp/graph"; +import { graphfi } from "@pnp/graph"; import "@pnp/graph/users"; import "@pnp/graph/photos"; -const graph = graphfi().using(SPFx(this.context)); +const graph = graphfi(...); const input = document.getElementById("thefileinput"); const file = input.files[0]; diff --git a/docs/graph/planner.md b/docs/graph/planner.md index ee7e5b10c..6535567c5 100644 --- a/docs/graph/planner.md +++ b/docs/graph/planner.md @@ -13,10 +13,10 @@ Using the planner.plans.getById() you can get a specific Plan. Planner.plans is not an available endpoint, you need to get a specific Plan. ```TypeScript -import { graphfi, SPFx } from "@pnp/graph"; +import { graphfi } from "@pnp/graph"; import "@pnp/graph/planner"; -const graph = graphfi().using(SPFx(this.context)); +const graph = graphfi(...); const plan = await graph.planner.plans.getById('planId')(); @@ -27,10 +27,10 @@ const plan = await graph.planner.plans.getById('planId')(); Using the planner.plans.add() you can create a new Plan. ```TypeScript -import { graphfi, SPFx } from "@pnp/graph"; +import { graphfi } from "@pnp/graph"; import "@pnp/graph/planner"; -const graph = graphfi().using(SPFx(this.context)); +const graph = graphfi(...); const newPlan = await graph.planner.plans.add('groupObjectId', 'title'); @@ -41,10 +41,10 @@ const newPlan = await graph.planner.plans.add('groupObjectId', 'title'); Using the tasks() you can get the Tasks in a Plan. ```TypeScript -import { graphfi, SPFx } from "@pnp/graph"; +import { graphfi } from "@pnp/graph"; import "@pnp/graph/planner"; -const graph = graphfi().using(SPFx(this.context)); +const graph = graphfi(...); const planTasks = await graph.planner.plans.getById('planId').tasks(); @@ -55,10 +55,10 @@ const planTasks = await graph.planner.plans.getById('planId').tasks(); Using the buckets() you can get the Buckets in a Plan. ```TypeScript -import { graphfi, SPFx } from "@pnp/graph"; +import { graphfi } from "@pnp/graph"; import "@pnp/graph/planner"; -const graph = graphfi().using(SPFx(this.context)); +const graph = graphfi(...); const planBuckets = await graph.planner.plans.getById('planId').buckets(); @@ -69,10 +69,10 @@ const planBuckets = await graph.planner.plans.getById('planId').buckets(); Using the details() you can get the details in a Plan. ```TypeScript -import { graphfi, SPFx } from "@pnp/graph"; +import { graphfi } from "@pnp/graph"; import "@pnp/graph/planner"; -const graph = graphfi().using(SPFx(this.context)); +const graph = graphfi(...); const planDetails = await graph.planner.plans.getById('planId').details(); @@ -83,10 +83,10 @@ const planDetails = await graph.planner.plans.getById('planId').details(); Using the delete() you can get delete a Plan. ```TypeScript -import { graphfi, SPFx } from "@pnp/graph"; +import { graphfi } from "@pnp/graph"; import "@pnp/graph/planner"; -const graph = graphfi().using(SPFx(this.context)); +const graph = graphfi(...); const delPlan = await graph.planner.plans.getById('planId').delete('planEtag'); @@ -97,10 +97,10 @@ const delPlan = await graph.planner.plans.getById('planId').delete('planEtag'); Using the update() you can get update a Plan. ```TypeScript -import { graphfi, SPFx } from "@pnp/graph"; +import { graphfi } from "@pnp/graph"; import "@pnp/graph/planner"; -const graph = graphfi().using(SPFx(this.context)); +const graph = graphfi(...); const updPlan = await graph.planner.plans.getById('planId').update({title: 'New Title', eTag: 'planEtag'}); @@ -112,10 +112,10 @@ Using the planner.tasks.getById() you can get a specific Task. Planner.tasks is not an available endpoint, you need to get a specific Task. ```TypeScript -import { graphfi, SPFx } from "@pnp/graph"; +import { graphfi } from "@pnp/graph"; import "@pnp/graph/planner"; -const graph = graphfi().using(SPFx(this.context)); +const graph = graphfi(...); const task = await graph.planner.tasks.getById('taskId')(); @@ -126,10 +126,10 @@ const task = await graph.planner.tasks.getById('taskId')(); Using the planner.tasks.add() you can create a new Task. ```TypeScript -import { graphfi, SPFx } from "@pnp/graph"; +import { graphfi } from "@pnp/graph"; import "@pnp/graph/planner"; -const graph = graphfi().using(SPFx(this.context)); +const graph = graphfi(...); const newTask = await graph.planner.tasks.add('planId', 'title'); @@ -140,10 +140,10 @@ const newTask = await graph.planner.tasks.add('planId', 'title'); Using the details() you can get the details in a Task. ```TypeScript -import { graphfi, SPFx } from "@pnp/graph"; +import { graphfi } from "@pnp/graph"; import "@pnp/graph/planner"; -const graph = graphfi().using(SPFx(this.context)); +const graph = graphfi(...); const taskDetails = await graph.planner.tasks.getById('taskId').details(); @@ -154,10 +154,10 @@ const taskDetails = await graph.planner.tasks.getById('taskId').details(); Using the delete() you can get delete a Task. ```TypeScript -import { graphfi, SPFx } from "@pnp/graph"; +import { graphfi } from "@pnp/graph"; import "@pnp/graph/planner"; -const graph = graphfi().using(SPFx(this.context)); +const graph = graphfi(...); const delTask = await graph.planner.tasks.getById('taskId').delete('taskEtag'); @@ -168,10 +168,10 @@ const delTask = await graph.planner.tasks.getById('taskId').delete('taskEtag'); Using the update() you can get update a Task. ```TypeScript -import { graphfi, SPFx } from "@pnp/graph"; +import { graphfi } from "@pnp/graph"; import "@pnp/graph/planner"; -const graph = graphfi().using(SPFx(this.context)); +const graph = graphfi(...); const updTask = await graph.planner.tasks.getById('taskId').update({properties, eTag:'taskEtag'}); @@ -183,10 +183,10 @@ Using the planner.buckets.getById() you can get a specific Bucket. planner.buckets is not an available endpoint, you need to get a specific Bucket. ```TypeScript -import { graphfi, SPFx } from "@pnp/graph"; +import { graphfi } from "@pnp/graph"; import "@pnp/graph/planner"; -const graph = graphfi().using(SPFx(this.context)); +const graph = graphfi(...); const bucket = await graph.planner.buckets.getById('bucketId')(); @@ -197,10 +197,10 @@ const bucket = await graph.planner.buckets.getById('bucketId')(); Using the planner.buckets.add() you can create a new Bucket. ```TypeScript -import { graphfi, SPFx } from "@pnp/graph"; +import { graphfi } from "@pnp/graph"; import "@pnp/graph/planner"; -const graph = graphfi().using(SPFx(this.context)); +const graph = graphfi(...); const newBucket = await graph.planner.buckets.add('name', 'planId'); @@ -211,10 +211,10 @@ const newBucket = await graph.planner.buckets.add('name', 'planId'); Using the update() you can get update a Bucket. ```TypeScript -import { graphfi, SPFx } from "@pnp/graph"; +import { graphfi } from "@pnp/graph"; import "@pnp/graph/planner"; -const graph = graphfi().using(SPFx(this.context)); +const graph = graphfi(...); const updBucket = await graph.planner.buckets.getById('bucketId').update({name: "Name", eTag:'bucketEtag'}); @@ -225,10 +225,10 @@ const updBucket = await graph.planner.buckets.getById('bucketId').update({name: Using the delete() you can get delete a Bucket. ```TypeScript -import { graphfi, SPFx } from "@pnp/graph"; +import { graphfi } from "@pnp/graph"; import "@pnp/graph/planner"; -const graph = graphfi().using(SPFx(this.context)); +const graph = graphfi(...); const delBucket = await graph.planner.buckets.getById('bucketId').delete(eTag:'bucketEtag'); @@ -239,10 +239,10 @@ const delBucket = await graph.planner.buckets.getById('bucketId').delete(eTag:'b Using the tasks() you can get Tasks in a Bucket. ```TypeScript -import { graphfi, SPFx } from "@pnp/graph"; +import { graphfi } from "@pnp/graph"; import "@pnp/graph/planner"; -const graph = graphfi().using(SPFx(this.context)); +const graph = graphfi(...); const bucketTasks = await graph.planner.buckets.getById('bucketId').tasks(); diff --git a/docs/graph/search.md b/docs/graph/search.md index 825fceb19..8097fc4d2 100644 --- a/docs/graph/search.md +++ b/docs/graph/search.md @@ -9,10 +9,10 @@ The search module allows you to access the Microsoft Graph Search API. You can r This example shows calling the search API via the `query` method of the root graph object. ```TypeScript -import { graphfi, SPFx } from "@pnp/graph"; +import { graphfi } from "@pnp/graph"; import "@pnp/graph/search"; -const graph = graphfi().using(SPFx(this.context)); +const graph = graphfi(...); const results = await graph.query({ entityTypes: ["site"], diff --git a/docs/graph/sites.md b/docs/graph/sites.md index 76ea21ee9..ea3eb27e5 100644 --- a/docs/graph/sites.md +++ b/docs/graph/sites.md @@ -7,10 +7,10 @@ The search module allows you to access the Microsoft Graph Sites API. ## Call graph.sites ```TypeScript -import { graphfi, SPFx } from "@pnp/graph"; +import { graphfi } from "@pnp/graph"; import "@pnp/graph/sites"; -const graph = graphfi().using(SPFx(this.context)); +const graph = graphfi(...); const sitesInfo = await graph.sites(); ``` @@ -18,10 +18,10 @@ const sitesInfo = await graph.sites(); ## Call graph.sites.getById ```TypeScript -import { graphfi, SPFx } from "@pnp/graph"; +import { graphfi } from "@pnp/graph"; import "@pnp/graph/sites"; -const graph = graphfi().using(SPFx(this.context)); +const graph = graphfi(...); const siteInfo = await graph.sites.getById("{site identifier}")(); ``` diff --git a/docs/graph/subscriptions.md b/docs/graph/subscriptions.md index 7220d4956..99e5d96c7 100644 --- a/docs/graph/subscriptions.md +++ b/docs/graph/subscriptions.md @@ -13,10 +13,10 @@ The ability to manage subscriptions is a capability introduced in version 1.2.9 Using the subscriptions(). If successful this method returns a 200 OK response code and a list of subscription objects in the response body. ```TypeScript -import { graphfi, SPFx } from "@pnp/graph"; +import { graphfi } from "@pnp/graph"; import "@pnp/graph/subscriptions"; -const graph = graphfi().using(SPFx(this.context)); +const graph = graphfi(...); const subscriptions = await graph.subscriptions(); @@ -27,10 +27,10 @@ const subscriptions = await graph.subscriptions(); Using the subscriptions.add(). Creating a subscription requires read scope to the resource. For example, to get notifications messages, your app needs the Mail.Read permission. To learn more about the scopes visit [this](https://docs.microsoft.com/en-us/graph/api/subscription-post-subscriptions?view=graph-rest-1.0) url. ```TypeScript -import { graphfi, SPFx } from "@pnp/graph"; +import { graphfi } from "@pnp/graph"; import "@pnp/graph/subscriptions"; -const graph = graphfi().using(SPFx(this.context)); +const graph = graphfi(...); const addedSubscription = await graph.subscriptions.add("created,updated", "https://webhook.azurewebsites.net/api/send/myNotifyClient", "me/mailFolders('Inbox')/messages", "2019-11-20T18:23:45.9356913Z"); @@ -41,10 +41,10 @@ const addedSubscription = await graph.subscriptions.add("created,updated", "http Using the subscriptions.getById() you can get one of the subscriptions ```TypeScript -import { graphfi, SPFx } from "@pnp/graph"; +import { graphfi } from "@pnp/graph"; import "@pnp/graph/subscriptions"; -const graph = graphfi().using(SPFx(this.context)); +const graph = graphfi(...); const subscription = await graph.subscriptions.getById('subscriptionId')(); @@ -55,10 +55,10 @@ const subscription = await graph.subscriptions.getById('subscriptionId')(); Using the subscriptions.getById().delete() you can remove one of the Subscriptions ```TypeScript -import { graphfi, SPFx } from "@pnp/graph"; +import { graphfi } from "@pnp/graph"; import "@pnp/graph/subscriptions"; -const graph = graphfi().using(SPFx(this.context)); +const graph = graphfi(...); const delSubscription = await graph.subscriptions.getById('subscriptionId').delete(); @@ -69,10 +69,10 @@ const delSubscription = await graph.subscriptions.getById('subscriptionId').dele Using the subscriptions.getById().update() you can update one of the Subscriptions ```TypeScript -import { graphfi, SPFx } from "@pnp/graph"; +import { graphfi } from "@pnp/graph"; import "@pnp/graph/subscriptions"; -const graph = graphfi().using(SPFx(this.context)); +const graph = graphfi(...); const updSubscription = await graph.subscriptions.getById('subscriptionId').update({changeType: "created,updated,deleted" }); diff --git a/docs/graph/teams.md b/docs/graph/teams.md index 4fce3bdd3..19242ce1e 100644 --- a/docs/graph/teams.md +++ b/docs/graph/teams.md @@ -6,11 +6,11 @@ you can add, update and delete items in Teams. ## Teams the user is a member of ```TypeScript -import { graphfi, SPFx } from "@pnp/graph"; +import { graphfi } from "@pnp/graph"; import "@pnp/graph/users"; import "@pnp/graph/teams"; -const graph = graphfi().using(SPFx(this.context)); +const graph = graphfi(...); const joinedTeams = await graph.users.getById('99dc1039-eb80-43b1-a09e-250d50a80b26').joinedTeams(); @@ -23,10 +23,10 @@ const myJoinedTeams = await graph.me.joinedTeams(); Using the teams.getById() you can get a specific Team. ```TypeScript -import { graphfi, SPFx } from "@pnp/graph"; +import { graphfi } from "@pnp/graph"; import "@pnp/graph/teams"; -const graph = graphfi().using(SPFx(this.context)); +const graph = graphfi(...); const team = await graph.teams.getById('3531f3fb-f9ee-4f43-982a-6c90d8226528')(); ``` @@ -41,11 +41,11 @@ Follow the example in Groups to create the group and get the GroupID. Then make Here we get the group via id and use `createTeam` ```TypeScript -import { graphfi, SPFx } from "@pnp/graph"; +import { graphfi } from "@pnp/graph"; import "@pnp/graph/teams"; import "@pnp/graph/groups"; -const graph = graphfi().using(SPFx(this.context)); +const graph = graphfi(...); const createdTeam = await graph.groups.getById('679c8ff4-f07d-40de-b02b-60ec332472dd').createTeam({ "memberSettings": { @@ -66,10 +66,10 @@ const createdTeam = await graph.groups.getById('679c8ff4-f07d-40de-b02b-60ec3324 The second way to create a new Team and corresponding Group is to do so in one call. This can be done by using the createTeam method. ```TypeScript -import { graphfi, SPFx } from "@pnp/graph"; +import { graphfi } from "@pnp/graph"; import "@pnp/graph/teams"; -const graph = graphfi().using(SPFx(this.context)); +const graph = graphfi(...); const team = { "template@odata.bind": "https://graph.microsoft.com/v1.0/teamsTemplates('standard')", @@ -92,10 +92,10 @@ const createdTeamStatus = await graph.teams.getById(createdTeam.teamId).getOpera ## Clone a Team ```TypeScript -import { graphfi, SPFx } from "@pnp/graph"; +import { graphfi } from "@pnp/graph"; import "@pnp/graph/teams"; -const graph = graphfi().using(SPFx(this.context)); +const graph = graphfi(...); const clonedTeam = await graph.teams.getById('3531f3fb-f9ee-4f43-982a-6c90d8226528').cloneTeam( 'Cloned','description','apps,tabs,settings,channels,members','public'); @@ -105,10 +105,10 @@ const clonedTeam = await graph.teams.getById('3531f3fb-f9ee-4f43-982a-6c90d82265 ## Get Teams Async Operation ```TypeScript -import { graphfi, SPFx } from "@pnp/graph"; +import { graphfi } from "@pnp/graph"; import "@pnp/graph/teams"; -const graph = graphfi().using(SPFx(this.context)); +const graph = graphfi(...); const clonedTeam = await graph.teams.getById('3531f3fb-f9ee-4f43-982a-6c90d8226528').cloneTeam( 'Cloned','description','apps,tabs,settings,channels,members','public'); @@ -118,10 +118,10 @@ const clonedTeamStatus = await graph.teams.getById(clonedTeam.teamId).getOperati ## Archive a Team ```TypeScript -import { graphfi, SPFx } from "@pnp/graph"; +import { graphfi } from "@pnp/graph"; import "@pnp/graph/teams"; -const graph = graphfi().using(SPFx(this.context)); +const graph = graphfi(...); const archived = await graph.teams.getById('3531f3fb-f9ee-4f43-982a-6c90d8226528').archive(); ``` @@ -129,10 +129,10 @@ const archived = await graph.teams.getById('3531f3fb-f9ee-4f43-982a-6c90d8226528 ## Unarchive a Team ```TypeScript -import { graphfi, SPFx } from "@pnp/graph"; +import { graphfi } from "@pnp/graph"; import "@pnp/graph/teams"; -const graph = graphfi().using(SPFx(this.context)); +const graph = graphfi(...); const archived = await graph.teams.getById('3531f3fb-f9ee-4f43-982a-6c90d8226528').unarchive(); ``` @@ -140,10 +140,10 @@ const archived = await graph.teams.getById('3531f3fb-f9ee-4f43-982a-6c90d8226528 ## Get all channels of a Team ```TypeScript -import { graphfi, SPFx } from "@pnp/graph"; +import { graphfi } from "@pnp/graph"; import "@pnp/graph/teams"; -const graph = graphfi().using(SPFx(this.context)); +const graph = graphfi(...); const channels = await graph.teams.getById('3531f3fb-f9ee-4f43-982a-6c90d8226528').channels(); ``` @@ -153,20 +153,20 @@ const channels = await graph.teams.getById('3531f3fb-f9ee-4f43-982a-6c90d8226528 Using the teams.getById() you can get a specific Team. ```TypeScript -import { graphfi, SPFx } from "@pnp/graph"; +import { graphfi } from "@pnp/graph"; import "@pnp/graph/teams"; -const graph = graphfi().using(SPFx(this.context)); +const graph = graphfi(...); const channel = await graph.teams.getById('3531f3fb-f9ee-4f43-982a-6c90d8226528').primaryChannel(); ``` ## Get channel by Id ```TypeScript -import { graphfi, SPFx } from "@pnp/graph"; +import { graphfi } from "@pnp/graph"; import "@pnp/graph/teams"; -const graph = graphfi().using(SPFx(this.context)); +const graph = graphfi(...); const channel = await graph.teams.getById('3531f3fb-f9ee-4f43-982a-6c90d8226528').channels.getById('19:65723d632b384ca89c81115c281428a3@thread.skype')(); @@ -175,9 +175,9 @@ const channel = await graph.teams.getById('3531f3fb-f9ee-4f43-982a-6c90d8226528' ## Create a new Channel ```TypeScript -import { graphfi, SPFx } from "@pnp/graph"; +import { graphfi } from "@pnp/graph"; -const graph = graphfi().using(SPFx(this.context)); +const graph = graphfi(...); const newChannel = await graph.teams.getById('3531f3fb-f9ee-4f43-982a-6c90d8226528').channels.create('New Channel', 'Description'); @@ -186,10 +186,10 @@ const newChannel = await graph.teams.getById('3531f3fb-f9ee-4f43-982a-6c90d82265 ## Get installed Apps ```TypeScript -import { graphfi, SPFx } from "@pnp/graph"; +import { graphfi } from "@pnp/graph"; import "@pnp/graph/teams"; -const graph = graphfi().using(SPFx(this.context)); +const graph = graphfi(...); const installedApps = await graph.teams.getById('3531f3fb-f9ee-4f43-982a-6c90d8226528').installedApps(); @@ -198,10 +198,10 @@ const installedApps = await graph.teams.getById('3531f3fb-f9ee-4f43-982a-6c90d82 ## Add an App ```TypeScript -import { graphfi, SPFx } from "@pnp/graph"; +import { graphfi } from "@pnp/graph"; import "@pnp/graph/teams"; -const graph = graphfi().using(SPFx(this.context)); +const graph = graphfi(...); const addedApp = await graph.teams.getById('3531f3fb-f9ee-4f43-982a-6c90d8226528').installedApps.add('https://graph.microsoft.com/v1.0/appCatalogs/teamsApps/12345678-9abc-def0-123456789a'); @@ -210,10 +210,10 @@ const addedApp = await graph.teams.getById('3531f3fb-f9ee-4f43-982a-6c90d8226528 ## Remove an App ```TypeScript -import { graphfi, SPFx } from "@pnp/graph"; +import { graphfi } from "@pnp/graph"; import "@pnp/graph/teams"; -const graph = graphfi().using(SPFx(this.context)); +const graph = graphfi(...); const removedApp = await graph.teams.getById('3531f3fb-f9ee-4f43-982a-6c90d8226528').installedApps.delete(); @@ -222,10 +222,10 @@ const removedApp = await graph.teams.getById('3531f3fb-f9ee-4f43-982a-6c90d82265 ## Get Tabs from a Channel ```TypeScript -import { graphfi, SPFx } from "@pnp/graph"; +import { graphfi } from "@pnp/graph"; import "@pnp/graph/teams"; -const graph = graphfi().using(SPFx(this.context)); +const graph = graphfi(...); const tabs = await graph.teams.getById('3531f3fb-f9ee-4f43-982a-6c90d8226528'). channels.getById('19:65723d632b384ca89c81115c281428a3@thread.skype').tabs(); @@ -235,10 +235,10 @@ channels.getById('19:65723d632b384ca89c81115c281428a3@thread.skype').tabs(); ## Get Tab by Id ```TypeScript -import { graphfi, SPFx } from "@pnp/graph"; +import { graphfi } from "@pnp/graph"; import "@pnp/graph/teams"; -const graph = graphfi().using(SPFx(this.context)); +const graph = graphfi(...); const tab = await graph.teams.getById('3531f3fb-f9ee-4f43-982a-6c90d8226528'). channels.getById('19:65723d632b384ca89c81115c281428a3@thread.skype').tabs.getById('Id')(); @@ -248,10 +248,10 @@ channels.getById('19:65723d632b384ca89c81115c281428a3@thread.skype').tabs.getByI ## Add a new Tab ```TypeScript -import { graphfi, SPFx } from "@pnp/graph"; +import { graphfi } from "@pnp/graph"; import "@pnp/graph/teams"; -const graph = graphfi().using(SPFx(this.context)); +const graph = graphfi(...); const newTab = await graph.teams.getById('3531f3fb-f9ee-4f43-982a-6c90d8226528'). channels.getById('19:65723d632b384ca89c81115c281428a3@thread.skype').tabs.add('Tab','https://graph.microsoft.com/v1.0/appCatalogs/teamsApps/12345678-9abc-def0-123456789a',{}); diff --git a/docs/graph/users.md b/docs/graph/users.md index 17e69d0ae..9bbf09a85 100644 --- a/docs/graph/users.md +++ b/docs/graph/users.md @@ -11,10 +11,10 @@ You can learn more about Microsoft Graph users by reading the [Official Microsof ## Current User ```TypeScript -import { graphfi, SPFx } from "@pnp/graph"; +import { graphfi } from "@pnp/graph"; import "@pnp/graph/users"; -const graph = graphfi().using(SPFx(this.context)); +const graph = graphfi(...); const currentUser = await graph.me(); ``` @@ -22,10 +22,10 @@ const currentUser = await graph.me(); ## Get All Users in the Organization ```TypeScript -import { graphfi, SPFx } from "@pnp/graph"; +import { graphfi } from "@pnp/graph"; import "@pnp/graph/users"; -const graph = graphfi().using(SPFx(this.context)); +const graph = graphfi(...); const allUsers = await graph.users(); ``` @@ -33,10 +33,10 @@ const allUsers = await graph.users(); ## Get a User by email address (or user id) ```TypeScript -import { graphfi, SPFx } from "@pnp/graph"; +import { graphfi } from "@pnp/graph"; import "@pnp/graph/users"; -const graph = graphfi().using(SPFx(this.context)); +const graph = graphfi(...); const matchingUser = await graph.users.getById('jane@contoso.com')(); ``` @@ -44,10 +44,10 @@ const matchingUser = await graph.users.getById('jane@contoso.com')(); ## User Properties ```TypeScript -import { graphfi, SPFx } from "@pnp/graph"; +import { graphfi } from "@pnp/graph"; import "@pnp/graph/users"; -const graph = graphfi().using(SPFx(this.context)); +const graph = graphfi(...); await graph.me.memberOf(); await graph.me.transitiveMemberOf(); @@ -56,10 +56,10 @@ await graph.me.transitiveMemberOf(); ## Update Current User ```TypeScript -import { graphfi, SPFx } from "@pnp/graph"; +import { graphfi } from "@pnp/graph"; import "@pnp/graph/users"; -const graph = graphfi().using(SPFx(this.context)); +const graph = graphfi(...); await graph.me.update({ displayName: 'John Doe' @@ -69,10 +69,10 @@ await graph.me.update({ ## People ```TypeScript -import { graphfi, SPFx } from "@pnp/graph"; +import { graphfi } from "@pnp/graph"; import "@pnp/graph/users"; -const graph = graphfi().using(SPFx(this.context)); +const graph = graphfi(...); const people = await graph.me.people(); @@ -83,10 +83,10 @@ const people = await graph.me.people.top(3)(); ## People ```TypeScript -import { graphfi, SPFx } from "@pnp/graph"; +import { graphfi } from "@pnp/graph"; import "@pnp/graph/users"; -const graph = graphfi().using(SPFx(this.context)); +const graph = graphfi(...); const people = await graph.me.people(); @@ -97,10 +97,10 @@ const people = await graph.me.people.top(3)(); ## Manager ```TypeScript -import { graphfi, SPFx } from "@pnp/graph"; +import { graphfi } from "@pnp/graph"; import "@pnp/graph/users"; -const graph = graphfi().using(SPFx(this.context)); +const graph = graphfi(...); const manager = await graph.me.manager(); ``` @@ -108,10 +108,10 @@ const manager = await graph.me.manager(); ## Direct Reports ```TypeScript -import { graphfi, SPFx } from "@pnp/graph"; +import { graphfi } from "@pnp/graph"; import "@pnp/graph/users"; -const graph = graphfi().using(SPFx(this.context)); +const graph = graphfi(...); const reports = await graph.me.directReports(); ``` @@ -119,11 +119,11 @@ const reports = await graph.me.directReports(); ## Photo ```TypeScript -import { graphfi, SPFx } from "@pnp/graph"; +import { graphfi } from "@pnp/graph"; import "@pnp/graph/users"; import "@pnp/graph/photos"; -const graph = graphfi().using(SPFx(this.context)); +const graph = graphfi(...); const currentUser = await graph.me.photo(); const specificUser = await graph.users.getById('jane@contoso.com').photo(); diff --git a/docs/queryable/extensions.md b/docs/queryable/extensions.md index 153010f02..f3a57ff37 100644 --- a/docs/queryable/extensions.md +++ b/docs/queryable/extensions.md @@ -104,6 +104,7 @@ You can register Extensions on an invocable factory or on a per-object basis, an The pattern you will likely find most useful is the ability to extend an invocable factory. This will apply your extensions to all instances created with that factory, meaning all IWebs or ILists will have the extension methods. The example below shows how to add a property to IWeb as well as a method to IList. ```TypeScript +import { spfi } from "@pnp/sp"; import "@pnp/sp/webs"; import "@pnp/sp/lists/web"; import { IWeb, Web } from "@pnp/sp/webs"; @@ -111,6 +112,8 @@ import { ILists, Lists } from "@pnp/sp/lists"; import { extendFactory } from "@pnp/queryable"; import { sp } from "@pnp/sp"; +const sp = spfi().using(...); + // sets up the types correctly when importing across your application declare module "@pnp/sp/webs/types" { @@ -144,11 +147,11 @@ extendFactory(Lists, { }); // regardless of how we access the web and lists collections our extensions remain with all new instance based on -const web = Web("https://tenant.sharepoint.com/sites/dev/"); +const web = Web([sp.web, "https://tenant.sharepoint.com/sites/dev/"]); const lists1 = await web.orderedLists(); console.log(JSON.stringify(lists1, null, 2)); -const lists2 = await Web("https://tenant.sharepoint.com/sites/dev/").orderedLists(); +const lists2 = await Web([sp.web, "https://tenant.sharepoint.com/sites/dev/"]).orderedLists(); console.log(JSON.stringify(lists2, null, 2)); const lists3 = await sp.web.orderedLists(); diff --git a/docs/sp/alias-parameters.md b/docs/sp/alias-parameters.md index 3d029bdf2..c0286d546 100644 --- a/docs/sp/alias-parameters.md +++ b/docs/sp/alias-parameters.md @@ -13,11 +13,11 @@ Example: "!@p1::\sites\dev" or "!@p2::\text.txt" ### Example without aliasing ```TypeScript -import { spfi, SPFx } from "@pnp/sp"; +import { spfi } from "@pnp/sp"; import "@pnp/sp/webs"; import "@pnp/sp/files"; import "@pnp/sp/folders"; -const sp = spfi("{tenant url}").using(SPFx(this.context)); +const sp = spfi(...); // still works as expected, no aliasing const query = sp.web.getFolderByServerRelativeUrl("/sites/dev/Shared Documents/").files.select("Title").top(3); @@ -32,12 +32,12 @@ console.log(r); ### Example with aliasing ```TypeScript -import { spfi, SPFx } from "@pnp/sp"; +import { spfi } from "@pnp/sp"; import "@pnp/sp/webs"; import "@pnp/sp/files"; import "@pnp/sp/folders"; -const sp = spfi("{tenant url}").using(SPFx(this.context)); +const sp = spfi(...); // same query with aliasing const query = sp.web.getFolderByServerRelativeUrl("!@p1::/sites/dev/Shared Documents/").files.select("Title").top(3); @@ -54,10 +54,10 @@ console.log(r); Aliasing is supported with batching as well: ```TypeScript -import { spfi, SPFx } from "@pnp/sp"; +import { spfi } from "@pnp/sp"; import "@pnp/sp/webs"; -const sp = spfi("{tenant url}").using(SPFx(this.context)); +const sp = spfi(...); // same query with aliasing and batching const [batchedWeb, execute] = await sp.web.batched(); diff --git a/docs/sp/alm.md b/docs/sp/alm.md index 30c48afbe..61d8a4019 100644 --- a/docs/sp/alm.md +++ b/docs/sp/alm.md @@ -11,11 +11,11 @@ Before you begin provisioning applications it is important to understand the rel There are several ways using @pnp/sp to get a reference to an app catalog. These methods are to provide you the greatest amount of flexibility in gaining access to the app catalog. Ultimately each method produces an AppCatalog instance differentiated only by the web to which it points. ```TypeScript -import { spfi, SPFx } from "@pnp/sp"; +import { spfi } from "@pnp/sp"; import "@pnp/sp/appcatalog"; import "@pnp/sp/webs"; -const sp = spfi("{tenant url}").using(SPFx(this.context)); +const sp = spfi(...); // get the current context web's app catalog const catalog = await sp.web.getAppCatalog()(); @@ -26,11 +26,11 @@ console.log(apps); ``` ```TypeScript -import { spfi, SPFx } from "@pnp/sp"; +import { spfi } from "@pnp/sp"; import "@pnp/sp/appcatalog"; import "@pnp/sp/webs"; -const sp = spfi("{tenant url}").using(SPFx(this.context)); +const sp = spfi(...); // you can get the tenant app catalog (or any app catalog) by using the getTenantAppCatalogWeb method const appCatWeb = await sp.getTenantAppCatalogWeb()(); @@ -53,10 +53,12 @@ const catalog: IAppCatalog = await AppCatalog("https://mytenant.sharepoint.com/s ```TypeScript // and finally you can combine use of the Web and AppCatalog classes to create an AppCatalog instance from an existing Web +import { spfi } from "@pnp/sp"; import { Web } from '@pnp/sp/webs'; import { AppCatalog } from '@pnp/sp/appcatalog'; -const web = Web("https://mytenant.sharepoint.com/sites/apps"); +const sp = spfi().using(...); +const web = Web([sp.web, "https://mytenant.sharepoint.com/sites/apps"]); const catalog = await AppCatalog(web)(); ``` diff --git a/docs/sp/attachments.md b/docs/sp/attachments.md index fe166733f..1c3f3d18d 100644 --- a/docs/sp/attachments.md +++ b/docs/sp/attachments.md @@ -5,7 +5,7 @@ The ability to attach file to list items allows users to track documents outside ## Get attachments ```TypeScript -import { spfi, SPFx } from "@pnp/sp"; +import { spfi } from "@pnp/sp"; import { IAttachmentInfo } from "@pnp/sp/attachments"; import { IItem } from "@pnp/sp/items/types"; import "@pnp/sp/webs"; @@ -13,7 +13,7 @@ import "@pnp/sp/lists/web"; import "@pnp/sp/items"; import "@pnp/sp/attachments"; -const sp = spfi("{tenant url}").using(SPFx(this.context)); +const sp = spfi(...); const item: IItem = sp.web.lists.getByTitle("MyList").items.getById(1); @@ -34,14 +34,14 @@ You can add an attachment to a list item using the add method. This method takes ![Batching Not Supported Banner](https://img.shields.io/badge/Batching%20Not%20Supported-important.svg) ```TypeScript -import { spfi, SPFx } from "@pnp/sp"; +import { spfi } from "@pnp/sp"; import { IItem } from "@pnp/sp/items"; import "@pnp/sp/webs"; import "@pnp/sp/lists/web"; import "@pnp/sp/items"; import "@pnp/sp/attachments"; -const sp = spfi("{tenant url}").using(SPFx(this.context)); +const sp = spfi(...); const item: IItem = sp.web.lists.getByTitle("MyList").items.getById(1); @@ -53,14 +53,14 @@ await item.attachmentFiles.add("file2.txt", "Here is my content"); You can read the content of an attachment as a string, Blob, ArrayBuffer, or json using the methods supplied. ```TypeScript -import { spfi, SPFx } from "@pnp/sp"; +import { spfi } from "@pnp/sp"; import { IItem } from "@pnp/sp/items/types"; import "@pnp/sp/webs"; import "@pnp/sp/lists/web"; import "@pnp/sp/items"; import "@pnp/sp/attachments"; -const sp = spfi("{tenant url}").using(SPFx(this.context)); +const sp = spfi(...); const item: IItem = sp.web.lists.getByTitle("MyList").items.getById(1); @@ -82,14 +82,14 @@ You can also update the content of an attachment. This API is limited compared t ![Batching Not Supported Banner](https://img.shields.io/badge/Batching%20Not%20Supported-important.svg) ```TypeScript -import { spfi, SPFx } from "@pnp/sp"; +import { spfi } from "@pnp/sp"; import { IItem } from "@pnp/sp/items/types"; import "@pnp/sp/webs"; import "@pnp/sp/lists/web"; import "@pnp/sp/items"; import "@pnp/sp/attachments"; -const sp = spfi("{tenant url}").using(SPFx(this.context)); +const sp = spfi(...); const item: IItem = sp.web.lists.getByTitle("MyList").items.getById(1); @@ -99,14 +99,14 @@ await item.attachmentFiles.getByName("file2.txt").setContent("My new content!!!" ## Delete Attachment ```TypeScript -import { spfi, SPFx } from "@pnp/sp"; +import { spfi } from "@pnp/sp"; import { IItem } from "@pnp/sp/items/types"; import "@pnp/sp/webs"; import "@pnp/sp/lists/web"; import "@pnp/sp/items"; import "@pnp/sp/attachments"; -const sp = spfi("{tenant url}").using(SPFx(this.context)); +const sp = spfi(...); const item: IItem = sp.web.lists.getByTitle("MyList").items.getById(1); @@ -118,14 +118,14 @@ await item.attachmentFiles.getByName("file2.txt").delete(); Delete the attachment and send it to recycle bin ```TypeScript -import { spfi, SPFx } from "@pnp/sp"; +import { spfi } from "@pnp/sp"; import { IItem } from "@pnp/sp/items/types"; import "@pnp/sp/webs"; import "@pnp/sp/lists/web"; import "@pnp/sp/items"; import "@pnp/sp/attachments"; -const sp = spfi("{tenant url}").using(SPFx(this.context)); +const sp = spfi(...); const item: IItem = sp.web.lists.getByTitle("MyList").items.getById(1); @@ -137,14 +137,14 @@ await item.attachmentFiles.getByName("file2.txt").recycle(); Delete multiple attachments and send them to recycle bin ```TypeScript -import { spfi, SPFx } from "@pnp/sp"; +import { spfi } from "@pnp/sp"; import { IList } from "@pnp/sp/lists/types"; import "@pnp/sp/webs"; import "@pnp/sp/lists/web"; import "@pnp/sp/items"; import "@pnp/sp/attachments"; -const sp = spfi("{tenant url}").using(SPFx(this.context)); +const sp = spfi(...); const [batchedSP, execute] = sp.batched(); diff --git a/docs/sp/behaviors.md b/docs/sp/behaviors.md index 7bddaf96c..58c3f6bb6 100644 --- a/docs/sp/behaviors.md +++ b/docs/sp/behaviors.md @@ -102,11 +102,11 @@ await sp.web(); This behavior is designed to work closely with SPFx. The only parameter is the current SPFx Context. `SPFx` is a composed behavior including DefaultHeaders, DefaultInit, BrowserFetchWithRetry, DefaultParse, and RequestDigest. A hook is supplied to RequestDigest that will attempt to use any existing legacyPageContext formDigestValue it can find, otherwise defaults to the base [RequestDigest](#requestdigest) behavior. It also sets a pre handler to ensure the url is absolute, using the SPFx context's pageContext.web.absoluteUrl as the base. ```TypeScript -import { spfi, SPFx } from "@pnp/sp"; +import { spfi } from "@pnp/sp"; import "@pnp/sp/webs"; // this.context represents the context object within an SPFx webpart, application customizer, or ACE. -const sp = spfi().using(SPFx(this.context)); +const sp = spfi(...); await sp.web(); ``` diff --git a/docs/sp/clientside-pages.md b/docs/sp/clientside-pages.md index 62e6abf3b..804a6e0a4 100644 --- a/docs/sp/clientside-pages.md +++ b/docs/sp/clientside-pages.md @@ -16,7 +16,7 @@ import "@pnp/sp/webs"; import "@pnp/sp/clientside-pages/web"; import { PromotedState } from "@pnp/sp/clientside-pages"; -const sp = spfi("{tenant url}").using(SPFx(this.context)); +const sp = spfi(...); // Create a page providing a file name const page = await sp.web.addClientsidePage("mypage1"); @@ -42,12 +42,12 @@ await page3.save(); ### Create using CreateClientsidePage method ```TypeScript -import { spfi, SPFx } from "@pnp/sp"; +import { spfi } from "@pnp/sp"; import "@pnp/sp/webs"; import { Web } from "@pnp/sp/webs"; import { CreateClientsidePage, PromotedState } from "@pnp/sp/clientside-pages"; -const sp = spfi("{tenant url}").using(SPFx(this.context)); +const sp = spfi(...); const page1 = await CreateClientsidePage(sp.web, "mypage2", "My Page Title"); @@ -67,7 +67,7 @@ const page2half = await CreateClientsidePage(sp.web, "mypage3", "My Page Title", await page2half.save(); // use the web factory to create a page in a specific web -const page3 = await CreateClientsidePage(Web("https://{absolute web url}"), "mypage4", "My Page Title"); +const page3 = await CreateClientsidePage(Web([sp, "https://{absolute web url}"]), "mypage4", "My Page Title"); // you must publish the new page await page3.save(); @@ -78,11 +78,11 @@ await page3.save(); Using this method you can easily create a full page app page given the component id. Don't forget the page will not be published and you will need to call save. ```TypeScript -import { spfi, SPFx } from "@pnp/sp"; +import { spfi } from "@pnp/sp"; import "@pnp/sp/webs"; import "@pnp/sp/clientside-pages"; -const sp = spfi("{tenant url}").using(SPFx(this.context)); +const sp = spfi(...); const page = await sp.web.addFullPageApp("name333", "My Title", "2CE4E250-B997-11EB-A9D2-C9D2FF95D000"); // ... other page actions @@ -99,18 +99,18 @@ There are a few ways to load pages, each of which results in an IClientsidePage This method takes a _server relative_ path to the page to load. ```TypeScript -import { spfi, SPFx } from "@pnp/sp"; +import { spfi } from "@pnp/sp"; import "@pnp/sp/webs"; import { Web } from "@pnp/sp/webs"; import "@pnp/sp/clientside-pages/web"; -const sp = spfi("{tenant url}").using(SPFx(this.context)); +const sp = spfi(...); // use from the sp.web fluent chain const page = await sp.web.loadClientsidePage("/sites/dev/sitepages/mypage3.aspx"); // use the web factory to target a specific web -const page2 = await Web("https://{absolute web url}").loadClientsidePage("/sites/dev/sitepages/mypage3.aspx"); +const page2 = await Web([sp.web, "https://{absolute web url}"]).loadClientsidePage("/sites/dev/sitepages/mypage3.aspx"); ``` ### Load using ClientsidePageFromFile @@ -118,12 +118,12 @@ const page2 = await Web("https://{absolute web url}").loadClientsidePage("/sites This method takes an IFile instance and loads an IClientsidePage instance. ```TypeScript -import { spfi, SPFx } from "@pnp/sp"; +import { spfi } from "@pnp/sp"; import { ClientsidePageFromFile } from "@pnp/sp/clientside-pages"; import "@pnp/sp/webs"; import "@pnp/sp/files/web"; -const sp = spfi("{tenant url}").using(SPFx(this.context)); +const sp = spfi(...); const page = await ClientsidePageFromFile(sp.web.getFileByServerRelativePath("/sites/dev/sitepages/mypage3.aspx")); ``` @@ -133,10 +133,10 @@ const page = await ClientsidePageFromFile(sp.web.getFileByServerRelativePath("/s Client-side pages are made up of sections, columns, and controls. Sections contain columns which contain controls. There are methods to operate on these within the page, in addition to the standard array methods available in JavaScript. These samples use a variable `page` that is understood to be an IClientsidePage instance which is either created or loaded as outlined in previous sections. ```TypeScript -import { spfi, SPFx } from "@pnp/sp"; +import { spfi } from "@pnp/sp"; import { IClientsidePage } from "@pnp/sp/clientside-pages"; -const sp = spfi("{tenant url}").using(SPFx(this.context)); +const sp = spfi(...); // our page instance const page: IClientsidePage = await sp.web.loadClientsidePage("/sites/dev/sitepages/home.aspx"); @@ -159,10 +159,10 @@ await page.save(); ### Manipulate Sections and Columns ```TypeScript -import { spfi, SPFx } from "@pnp/sp"; +import { spfi } from "@pnp/sp"; import { IClientsidePage } from "@pnp/sp/clientside-pages"; -const sp = spfi("{tenant url}").using(SPFx(this.context)); +const sp = spfi(...); // our page instance const page: IClientsidePage = await sp.web.loadClientsidePage("/sites/dev/sitepages/home.aspx"); @@ -184,10 +184,10 @@ await page.save(); The vertical section, if on the page, is stored within the sections array. However, you access it slightly differently to make things easier. ```TypeScript -import { spfi, SPFx } from "@pnp/sp"; +import { spfi } from "@pnp/sp"; import { IClientsidePage } from "@pnp/sp/clientside-pages"; -const sp = spfi("{tenant url}").using(SPFx(this.context)); +const sp = spfi(...); // our page instance const page: IClientsidePage = await sp.web.loadClientsidePage("/sites/dev/sitepages/home.aspx"); @@ -212,10 +212,10 @@ if (page.hasVerticalSection) { ### Reorder Sections ```TypeScript -import { spfi, SPFx } from "@pnp/sp"; +import { spfi } from "@pnp/sp"; import { IClientsidePage } from "@pnp/sp/clientside-pages"; -const sp = spfi("{tenant url}").using(SPFx(this.context)); +const sp = spfi(...); // our page instance const page: IClientsidePage = await sp.web.loadClientsidePage("/sites/dev/sitepages/home.aspx"); @@ -233,10 +233,10 @@ await page.save(); The sections and columns are arrays, so normal array operations work as expected ```TypeScript -import { spfi, SPFx } from "@pnp/sp"; +import { spfi } from "@pnp/sp"; import { IClientsidePage } from "@pnp/sp/clientside-pages"; -const sp = spfi("{tenant url}").using(SPFx(this.context)); +const sp = spfi(...); // our page instance const page: IClientsidePage = await sp.web.loadClientsidePage("/sites/dev/sitepages/home.aspx"); @@ -256,10 +256,10 @@ Once you have your sections and columns defined you will want to add/edit contro ### Add Text Content ```TypeScript -import { spfi, SPFx } from "@pnp/sp"; +import { spfi } from "@pnp/sp"; import { ClientsideText, IClientsidePage } from "@pnp/sp/clientside-pages"; -const sp = spfi("{tenant url}").using(SPFx(this.context)); +const sp = spfi(...); // our page instance const page: IClientsidePage = await sp.web.loadClientsidePage("/sites/dev/sitepages/home.aspx"); @@ -276,10 +276,10 @@ Adding controls involves loading the available client-side part definitions from ```TypeScript import "@pnp/sp/webs"; import "@pnp/sp/clientside-pages/web"; -import { spfi, SPFx } from "@pnp/sp"; +import { spfi } from "@pnp/sp"; import { ClientsideWebpart } from "@pnp/sp/clientside-pages"; -const sp = spfi("{tenant url}").using(SPFx(this.context)); +const sp = spfi(...); // this will be a ClientsidePageComponent array // this can be cached on the client in production scenarios @@ -315,7 +315,7 @@ await page.save(); There are many ways that client side web parts are implemented and we can't provide handling within the library for all possibilities. This example shows how to handle a property set within the serverProcessedContent, in this case a List part's display title. ```TypeScript -import { spfi, SPFx } from "@pnp/sp"; +import { spfi } from "@pnp/sp"; import { ClientsideWebpart } from "@pnp/sp/clientside-pages"; import "@pnp/sp/webs"; @@ -336,7 +336,7 @@ class ListWebpart extends ClientsideWebpart { } } -const sp = spfi("{tenant url}").using(SPFx(this.context)); +const sp = spfi(...); // now we load our page const page = await sp.web.loadClientsidePage("/sites/dev/SitePages/List-Web-Part.aspx"); @@ -360,10 +360,10 @@ There are other operation you can perform on a page in addition to manipulating You can get and set the page layout. Changing the layout after creating the page may have side effects and should be done cautiously. ```TypeScript -import { spfi, SPFx } from "@pnp/sp"; +import { spfi } from "@pnp/sp"; import { IClientsidePage } from "@pnp/sp/clientside-pages"; -const sp = spfi("{tenant url}").using(SPFx(this.context)); +const sp = spfi(...); // our page instance const page: IClientsidePage = await sp.web.loadClientsidePage("/sites/dev/sitepages/home.aspx"); @@ -379,10 +379,10 @@ await page.save(); ### bannerImageUrl ```TypeScript -import { spfi, SPFx } from "@pnp/sp"; +import { spfi } from "@pnp/sp"; import { IClientsidePage } from "@pnp/sp/clientside-pages"; -const sp = spfi("{tenant url}").using(SPFx(this.context)); +const sp = spfi(...); // our page instance const page: IClientsidePage = await sp.web.loadClientsidePage("/sites/dev/sitepages/home.aspx"); @@ -404,10 +404,10 @@ Allows you to set the thumbnail used for the page independently of the banner. > If you set the bannerImageUrl property and not thumbnailUrl the thumbnail will be reset to match the banner, mimicking the UI functionality. ```TypeScript -import { spfi, SPFx } from "@pnp/sp"; +import { spfi } from "@pnp/sp"; import { IClientsidePage } from "@pnp/sp/clientside-pages"; -const sp = spfi("{tenant url}").using(SPFx(this.context)); +const sp = spfi(...); // our page instance const page: IClientsidePage = await sp.web.loadClientsidePage("/sites/dev/sitepages/home.aspx"); @@ -423,10 +423,10 @@ await page.save(); ### topicHeader ```TypeScript -import { spfi, SPFx } from "@pnp/sp"; +import { spfi } from "@pnp/sp"; import { IClientsidePage } from "@pnp/sp/clientside-pages"; -const sp = spfi("{tenant url}").using(SPFx(this.context)); +const sp = spfi(...); // our page instance const page: IClientsidePage = await sp.web.loadClientsidePage("/sites/dev/sitepages/home.aspx"); @@ -446,10 +446,10 @@ await page.save(); ### title ```TypeScript -import { spfi, SPFx } from "@pnp/sp"; +import { spfi } from "@pnp/sp"; import { IClientsidePage } from "@pnp/sp/clientside-pages"; -const sp = spfi("{tenant url}").using(SPFx(this.context)); +const sp = spfi(...); // our page instance const page: IClientsidePage = await sp.web.loadClientsidePage("/sites/dev/sitepages/home.aspx"); @@ -467,10 +467,10 @@ await page.save(); > Descriptions are limited to 255 chars ```TypeScript -import { spfi, SPFx } from "@pnp/sp"; +import { spfi } from "@pnp/sp"; import { IClientsidePage } from "@pnp/sp/clientside-pages"; -const sp = spfi("{tenant url}").using(SPFx(this.context)); +const sp = spfi(...); // our page instance const page: IClientsidePage = await sp.web.loadClientsidePage("/sites/dev/sitepages/home.aspx"); @@ -488,10 +488,10 @@ await page.save(); Sets the layout type of the page. The valid values are: "FullWidthImage", "NoImage", "ColorBlock", "CutInShape" ```TypeScript -import { spfi, SPFx } from "@pnp/sp"; +import { spfi } from "@pnp/sp"; import { IClientsidePage } from "@pnp/sp/clientside-pages"; -const sp = spfi("{tenant url}").using(SPFx(this.context)); +const sp = spfi(...); // our page instance const page: IClientsidePage = await sp.web.loadClientsidePage("/sites/dev/sitepages/home.aspx"); @@ -509,10 +509,10 @@ await page.save(); Sets the header text alignment to one of "Left" or "Center" ```TypeScript -import { spfi, SPFx } from "@pnp/sp"; +import { spfi } from "@pnp/sp"; import { IClientsidePage } from "@pnp/sp/clientside-pages"; -const sp = spfi("{tenant url}").using(SPFx(this.context)); +const sp = spfi(...); // our page instance const page: IClientsidePage = await sp.web.loadClientsidePage("/sites/dev/sitepages/home.aspx"); @@ -530,10 +530,10 @@ await page.save(); Sets if the topic header is displayed on a page. ```TypeScript -import { spfi, SPFx } from "@pnp/sp"; +import { spfi } from "@pnp/sp"; import { IClientsidePage } from "@pnp/sp/clientside-pages"; -const sp = spfi("{tenant url}").using(SPFx(this.context)); +const sp = spfi(...); // our page instance const page: IClientsidePage = await sp.web.loadClientsidePage("/sites/dev/sitepages/home.aspx"); @@ -555,9 +555,9 @@ await page.save(); Sets if the publish date is displayed on a page. ```TypeScript -import { spfi, SPFx } from "@pnp/sp"; +import { spfi } from "@pnp/sp"; import { IClientsidePage } from "@pnp/sp/clientside-pages"; -const sp = spfi("{tenant url}").using(SPFx(this.context)); +const sp = spfi(...); // our page instance const page: IClientsidePage = await sp.web.loadClientsidePage("/sites/dev/sitepages/home.aspx"); @@ -577,12 +577,12 @@ await page.save(); ### Get / Set author details ```TypeScript -import { spfi, SPFx } from "@pnp/sp"; +import { spfi } from "@pnp/sp"; import { IClientsidePage } from "@pnp/sp/clientside-pages"; import "@pnp/sp/clientside-pages"; import "@pnp/sp/site-users"; -const sp = spfi("{tenant url}").using(SPFx(this.context)); +const sp = spfi(...); // our page instance const page: IClientsidePage = await sp.web.loadClientsidePage("/sites/dev/sitepages/home.aspx"); @@ -609,10 +609,10 @@ await page.save(); Loads the page from the server. This will overwrite any local unsaved changes. ```TypeScript -import { spfi, SPFx } from "@pnp/sp"; +import { spfi } from "@pnp/sp"; import { IClientsidePage } from "@pnp/sp/clientside-pages"; -const sp = spfi("{tenant url}").using(SPFx(this.context)); +const sp = spfi(...); // our page instance const page: IClientsidePage = await sp.web.loadClientsidePage("/sites/dev/sitepages/home.aspx"); @@ -622,13 +622,15 @@ await page.load(); ### save +>![Known Issue Banner](https://img.shields.io/badge/Known%20Issue-important.svg) Uncustomized home pages (i.e the home page that is generated with a site out of the box) cannot be updated by this library without becoming corrupted. + Saves any changes to the page, optionally keeping them in draft state. ```TypeScript -import { spfi, SPFx } from "@pnp/sp"; +import { spfi } from "@pnp/sp"; import { IClientsidePage } from "@pnp/sp/clientside-pages"; -const sp = spfi("{tenant url}").using(SPFx(this.context)); +const sp = spfi(...); // our page instance const page: IClientsidePage = await sp.web.loadClientsidePage("/sites/dev/sitepages/home.aspx"); @@ -645,10 +647,10 @@ await page.save(false); Discards any current checkout of the page by the current user. ```TypeScript -import { spfi, SPFx } from "@pnp/sp"; +import { spfi } from "@pnp/sp"; import { IClientsidePage } from "@pnp/sp/clientside-pages"; -const sp = spfi("{tenant url}").using(SPFx(this.context)); +const sp = spfi(...); // our page instance const page: IClientsidePage = await sp.web.loadClientsidePage("/sites/dev/sitepages/home.aspx"); @@ -661,10 +663,10 @@ await page.discardPageCheckout(); Promotes the page as a news article. ```TypeScript -import { spfi, SPFx } from "@pnp/sp"; +import { spfi } from "@pnp/sp"; import { IClientsidePage } from "@pnp/sp/clientside-pages"; -const sp = spfi("{tenant url}").using(SPFx(this.context)); +const sp = spfi(...); // our page instance const page: IClientsidePage = await sp.web.loadClientsidePage("/sites/dev/sitepages/home.aspx"); @@ -679,12 +681,12 @@ Used to control the availability of comments on a page. [![Known Issue Banner](https://img.shields.io/badge/Known%20Issue-important.svg)](https://github.com/pnp/pnpjs/issues/1383) ```TypeScript -import { spfi, SPFx } from "@pnp/sp"; +import { spfi } from "@pnp/sp"; // you need to import the comments sub-module or use the all preset import "@pnp/sp/comments/clientside-page"; import { IClientsidePage } from "@pnp/sp/clientside-pages"; -const sp = spfi("{tenant url}").using(SPFx(this.context)); +const sp = spfi(...); // our page instance const page: IClientsidePage = await sp.web.loadClientsidePage("/sites/dev/sitepages/home.aspx"); @@ -701,10 +703,10 @@ await page.disableComments(); Finds a control within the page by id. ```TypeScript -import { spfi, SPFx } from "@pnp/sp"; +import { spfi } from "@pnp/sp"; import { IClientsidePage, ClientsideText } from "@pnp/sp/clientside-pages"; -const sp = spfi("{tenant url}").using(SPFx(this.context)); +const sp = spfi(...); // our page instance const page: IClientsidePage = await sp.web.loadClientsidePage("/sites/dev/sitepages/home.aspx"); @@ -720,10 +722,10 @@ const control = page.findControlById("06d4cdf6-bce6-4200-8b93-66 Finds a control within the page using the supplied delegate. Can also be used to iterate through all controls in the page. ```TypeScript -import { spfi, SPFx } from "@pnp/sp"; +import { spfi } from "@pnp/sp"; import { IClientsidePage } from "@pnp/sp/clientside-pages"; -const sp = spfi("{tenant url}").using(SPFx(this.context)); +const sp = spfi(...); // our page instance const page: IClientsidePage = await sp.web.loadClientsidePage("/sites/dev/sitepages/home.aspx"); @@ -769,11 +771,11 @@ const info = await page.getLikedByInformation(); Creates a copy of the page, including all controls. ```TypeScript -import { spfi, SPFx } from "@pnp/sp"; +import { spfi } from "@pnp/sp"; import { IClientsidePage } from "@pnp/sp/clientside-pages"; import "@pnp/sp/webs"; -const sp = spfi("{tenant url}").using(SPFx(this.context)); +const sp = spfi(...); // our page instance const page: IClientsidePage = await sp.web.loadClientsidePage("/sites/dev/sitepages/home.aspx"); @@ -795,11 +797,11 @@ pageCopy2.save(); Copies the contents of a page to another existing page instance. ```TypeScript -import { spfi, SPFx } from "@pnp/sp"; +import { spfi } from "@pnp/sp"; import { IClientsidePage } from "@pnp/sp/clientside-pages"; import "@pnp/sp/webs"; -const sp = spfi("{tenant url}").using(SPFx(this.context)); +const sp = spfi(...); // our page instances, loaded in any of the ways shown above const source: IClientsidePage = await sp.web.loadClientsidePage("/sites/dev/sitepages/home.aspx"); @@ -825,10 +827,10 @@ Sets the banner image url and optionally additional properties. Allows you to se > Banner images need to exist within the same site collection as the page where you want to use them. ```TypeScript -import { spfi, SPFx } from "@pnp/sp"; +import { spfi } from "@pnp/sp"; import { IClientsidePage } from "@pnp/sp/clientside-pages"; -const sp = spfi("{tenant url}").using(SPFx(this.context)); +const sp = spfi(...); const page: IClientsidePage = await sp.web.loadClientsidePage("/sites/dev/sitepages/home.aspx"); @@ -917,10 +919,10 @@ await page.save(); Allows you to set the banner image from a source outside the current site collection. The image file will be copied to the SiteAssets library and referenced from there. ```TypeScript -import { spfi, SPFx } from "@pnp/sp"; +import { spfi } from "@pnp/sp"; import { IClientsidePage } from "@pnp/sp/clientside-pages"; -const sp = spfi("{tenant url}").using(SPFx(this.context)); +const sp = spfi(...); const page: IClientsidePage = await sp.web.loadClientsidePage("/sites/dev/sitepages/home.aspx"); @@ -934,10 +936,10 @@ await page.save(); You can optionally supply additional props for the banner image, these match the properties when calling [setBannerImage](#setbannerimage) ```TypeScript -import { spfi, SPFx } from "@pnp/sp"; +import { spfi } from "@pnp/sp"; import { IClientsidePage } from "@pnp/sp/clientside-pages"; -const sp = spfi("{tenant url}").using(SPFx(this.context)); +const sp = spfi(...); const page: IClientsidePage = await sp.web.loadClientsidePage("/sites/dev/sitepages/home.aspx"); @@ -1010,11 +1012,11 @@ await page.share(["email@place.com", "email2@otherplace.com"], "Please check out You can use the `addRepostPage` method to add a report page. The method returns the absolute url of the created page. All properties are optional but it is recommended to include as much as possible to improve the quality of the repost card's display. ```TypeScript -import { spfi, SPFx } from "@pnp/sp"; +import { spfi } from "@pnp/sp"; import "@pnp/sp/webs"; import "@pnp/sp/clientside-pages"; -const sp = spfi("{tenant url}").using(SPFx(this.context)); +const sp = spfi(...); const page = await sp.web.addRepostPage({ BannerImageUrl: "https://some.absolute/path/to/an/image.jpg", IsBannerImageUrlExternal: true, diff --git a/docs/sp/column-defaults.md b/docs/sp/column-defaults.md index a536677f7..9a3d61180 100644 --- a/docs/sp/column-defaults.md +++ b/docs/sp/column-defaults.md @@ -9,12 +9,12 @@ The column defaults sub-module allows you to manage the default column values on You can get the default values for a specific folder as shown below: ```TypeScript -import { spfi, SPFx } from "@pnp/sp"; +import { spfi } from "@pnp/sp"; import "@pnp/sp/webs"; import "@pnp/sp/folders/web"; import "@pnp/sp/column-defaults"; -const sp = spfi("{tenant url}").using(SPFx(this.context)); +const sp = spfi(...); const defaults = await sp.web.getFolderByServerRelativePath("/sites/dev/DefaultColumnValues/fld_GHk5").getDefaultColumnValues(); @@ -45,12 +45,12 @@ When setting the defaults for a folder you need to include the field's internal >_Note: Be very careful when setting the path as the site collection url is case sensitive_ ```TypeScript -import { spfi, SPFx } from "@pnp/sp"; +import { spfi } from "@pnp/sp"; import "@pnp/sp/webs"; import "@pnp/sp/folders/web"; import "@pnp/sp/column-defaults"; -const sp = spfi("{tenant url}").using(SPFx(this.context)); +const sp = spfi(...); await sp.web.getFolderByServerRelativePath("/sites/dev/DefaultColumnValues/fld_GHk5").setDefaultColumnValues([{ name: "TextField", @@ -67,12 +67,12 @@ await sp.web.getFolderByServerRelativePath("/sites/dev/DefaultColumnValues/fld_G You can also get all of the defaults for the entire library. ```TypeScript -import { spfi, SPFx } from "@pnp/sp"; +import { spfi } from "@pnp/sp"; import "@pnp/sp/webs"; import "@pnp/sp/lists/web"; import "@pnp/sp/column-defaults"; -const sp = spfi("{tenant url}").using(SPFx(this.context)); +const sp = spfi(...); const defaults = await sp.web.lists.getByTitle("DefaultColumnValues").getDefaultColumnValues(); @@ -103,12 +103,12 @@ You can also set the defaults for an entire library at once (root and all sub-fo >_Note: Be very careful when setting the path as the site collection url is case sensitive_ ```TypeScript -import { spfi, SPFx } from "@pnp/sp"; +import { spfi } from "@pnp/sp"; import "@pnp/sp/webs"; import "@pnp/sp/lists/web"; import "@pnp/sp/column-defaults"; -const sp = spfi("{tenant url}").using(SPFx(this.context)); +const sp = spfi(...); await sp.web.lists.getByTitle("DefaultColumnValues").setDefaultColumnValues([{ name: "TextField", @@ -122,12 +122,12 @@ await sp.web.lists.getByTitle("DefaultColumnValues").setDefaultColumnValues([{ If you want to clear all of the folder defaults you can use the clear method: ```TypeScript -import { spfi, SPFx } from "@pnp/sp"; +import { spfi } from "@pnp/sp"; import "@pnp/sp/webs"; import "@pnp/sp/folders/web"; import "@pnp/sp/column-defaults"; -const sp = spfi("{tenant url}").using(SPFx(this.context)); +const sp = spfi(...); await sp.web.getFolderByServerRelativePath("/sites/dev/DefaultColumnValues/fld_GHk5").clearDefaultColumnValues(); ``` @@ -137,12 +137,12 @@ await sp.web.getFolderByServerRelativePath("/sites/dev/DefaultColumnValues/fld_G If you need to clear all of the default column values in a library you can pass an empty array to the list's setDefaultColumnValues method. ```TypeScript -import { spfi, SPFx } from "@pnp/sp"; +import { spfi } from "@pnp/sp"; import "@pnp/sp/webs"; import "@pnp/sp/lists/web"; import "@pnp/sp/column-defaults"; -const sp = spfi("{tenant url}").using(SPFx(this.context)); +const sp = spfi(...); await sp.web.lists.getByTitle("DefaultColumnValues").setDefaultColumnValues([]); ``` @@ -212,13 +212,13 @@ The following is an example of the structure for setting the default column valu This example shows fully how to get the taxonomy values and set them as a default column value using PnPjs. ```TypeScript -import { spfi, SPFx } from "@pnp/sp"; +import { spfi } from "@pnp/sp"; import "@pnp/sp/webs"; import "@pnp/sp/folders"; import "@pnp/sp/column-defaults"; import "@pnp/sp/taxonomy"; -const sp = spfi("{tenant url}").using(SPFx(this.context)); +const sp = spfi(...); // get the term's info we want to use as the default const term = await sp.termStore.sets.getById("ea6fc521-d293-4f3d-9e84-f3a5bc0936ce").getTermById("775c9cf6-c3cd-4db9-8cfa-fc0aeefad93a")(); diff --git a/docs/sp/comments-likes.md b/docs/sp/comments-likes.md index 6ffdbf38f..b500e996b 100644 --- a/docs/sp/comments-likes.md +++ b/docs/sp/comments-likes.md @@ -15,12 +15,12 @@ The IClientsidePage interface has three methods to provide easier access to the You can add a comment using the addComment method as shown ```TypeScript -import { spfi, SPFx } from "@pnp/sp"; +import { spfi } from "@pnp/sp"; import { CreateClientsidePage } from "@pnp/sp/clientside-pages"; import "@pnp/sp/comments/clientside-page"; import "@pnp/sp/webs"; -const sp = spfi("{tenant url}").using(SPFx(this.context)); +const sp = spfi(...); const page = await CreateClientsidePage(sp.web, "mypage", "My Page Title", "Article"); // optionally publish the page first @@ -32,12 +32,12 @@ const comment = await page.addComment("A test comment"); ### Get Page Comments ```TypeScript -import { spfi, SPFx } from "@pnp/sp"; +import { spfi } from "@pnp/sp"; import { CreateClientsidePage } from "@pnp/sp/clientside-pages"; import "@pnp/sp/comments/clientside-page"; import "@pnp/sp/webs"; -const sp = spfi("{tenant url}").using(SPFx(this.context)); +const sp = spfi(...); const page = await CreateClientsidePage(sp.web, "mypage", "My Page Title", "Article"); // optionally publish the page first @@ -58,13 +58,13 @@ const comments = await page.getComments(); Used to control the availability of comments on a page ```TypeScript -import { spfi, SPFx } from "@pnp/sp"; +import { spfi } from "@pnp/sp"; import { IClientsidePage } from "@pnp/sp/clientside-pages"; // you need to import the comments sub-module or use the all preset import "@pnp/sp/comments/clientside-page"; import "@pnp/sp/webs"; -const sp = spfi("{tenant url}").using(SPFx(this.context)); +const sp = spfi(...); // our page instance const page: IClientsidePage = await sp.web.loadClientsidePage("/sites/dev/sitepages/home.aspx"); @@ -79,12 +79,12 @@ await page.disableComments(); ### GetById ```TypeScript -import { spfi, SPFx } from "@pnp/sp"; +import { spfi } from "@pnp/sp"; import { CreateClientsidePage } from "@pnp/sp/clientside-pages"; import "@pnp/sp/comments/clientside-page"; import "@pnp/sp/webs"; -const sp = spfi("{tenant url}").using(SPFx(this.context)); +const sp = spfi(...); const page = await CreateClientsidePage(sp.web, "mypage", "My Page Title", "Article"); // optionally publish the page first @@ -100,13 +100,13 @@ const commentData = await page.getCommentById(parseInt(comment.id, 10)); ## Item Comments ```TypeScript -import { spfi, SPFx } from "@pnp/sp"; +import { spfi } from "@pnp/sp"; import "@pnp/sp/webs"; import "@pnp/sp/files/web"; import "@pnp/sp/items"; import "@pnp/sp/comments/item"; -const sp = spfi("{tenant url}").using(SPFx(this.context)); +const sp = spfi(...); const item = await sp.web.getFileByServerRelativePath("/sites/dev/SitePages/Test_8q5L.aspx").getItem(); @@ -127,10 +127,10 @@ const comments = await item.comments(); You can also get the comments merged with instances of the Comment class to immediately start accessing the properties and methods: ```TypeScript -import { spfi, SPFx } from "@pnp/sp"; +import { spfi } from "@pnp/sp"; import { IComments } from "@pnp/sp/comments"; -const sp = spfi("{tenant url}").using(SPFx(this.context)); +const sp = spfi(...); const comments: IComments = await item.comments(); @@ -144,10 +144,10 @@ const comments = await item.comments.expand("replies", "likedBy", "replies/liked ### Add Comment ```TypeScript -import { spfi, SPFx } from "@pnp/sp"; +import { spfi } from "@pnp/sp"; import { ICommentInfo } from "@pnp/sp/comments"; -const sp = spfi("{tenant url}").using(SPFx(this.context)); +const sp = spfi(...); // you can add a comment as a string const comment = await item.comments.add("string comment"); @@ -161,10 +161,10 @@ const comment = await page.addComment(commentInfo); ### Delete a Comment ```TypeScript -import { spfi, SPFx } from "@pnp/sp"; +import { spfi } from "@pnp/sp"; import { IComments } from "@pnp/sp/comments"; -const sp = spfi("{tenant url}").using(SPFx(this.context)); +const sp = spfi(...); const comments: IComments = await item.comments(); @@ -175,10 +175,10 @@ comments[0].delete() ### Like Comment ```TypeScript -import { spfi, SPFx } from "@pnp/sp"; +import { spfi } from "@pnp/sp"; import { IComments } from "@pnp/sp/comments"; -const sp = spfi("{tenant url}").using(SPFx(this.context)); +const sp = spfi(...); const comments: IComments = await item.comments(); @@ -189,10 +189,10 @@ comments[0].like(); ### Unlike Comment ```TypeScript -import { spfi, SPFx } from "@pnp/sp"; +import { spfi } from "@pnp/sp"; import { IComments } from "@pnp/sp/comments"; -const sp = spfi("{tenant url}").using(SPFx(this.context)); +const sp = spfi(...); const comments: IComments = await item.comments(); @@ -202,10 +202,10 @@ comments[0].unlike() ### Reply to a Comment ```TypeScript -import { spfi, SPFx } from "@pnp/sp"; +import { spfi } from "@pnp/sp"; import { IComments } from "@pnp/sp/comments"; -const sp = spfi("{tenant url}").using(SPFx(this.context)); +const sp = spfi(...); const comments: IComments = await item.comments(); @@ -215,10 +215,10 @@ const comment = await comments[0].comments.add({ text: "#PnPjs is pretty ok!" }) ### Load Replies to a Comment ```TypeScript -import { spfi, SPFx } from "@pnp/sp"; +import { spfi } from "@pnp/sp"; import { IComments } from "@pnp/sp/comments"; -const sp = spfi("{tenant url}").using(SPFx(this.context)); +const sp = spfi(...); const comments: IComments = await item.comments(); @@ -230,11 +230,11 @@ const replies = await comments[0].replies(); You can like/unlike client-side pages, items, and comments on items. See above for how to like or unlike a comment. Below you can see how to like and unlike an items, as well as get the liked by data. ```TypeScript -import { spfi, SPFx } from "@pnp/sp"; +import { spfi } from "@pnp/sp"; import "@pnp/sp/comments/item"; import { ILikeData, ILikedByInformation } from "@pnp/sp/comments"; -const sp = spfi("{tenant url}").using(SPFx(this.context)); +const sp = spfi(...); const item = await sp.web.getFileByServerRelativePath("/sites/dev/SitePages/Home.aspx").getItem(); @@ -254,7 +254,7 @@ const likedByInfo: ILikedByInformation = await item.getLikedByInformation(); To like/unlike a client-side page and get liked by information. ```TypeScript -import { spfi, SPFx } from "@pnp/sp"; +import { spfi } from "@pnp/sp"; import { ILikedByInformation } from "@pnp/sp/comments"; import { IClientsidePage } from "@pnp/sp/clientside-pages"; @@ -262,7 +262,7 @@ import "@pnp/sp/webs"; import "@pnp/sp/clientside-pages"; import "@pnp/sp/comments/clientside-page"; -const sp = spfi("{tenant url}").using(SPFx(this.context)); +const sp = spfi(...); const page: IClientsidePage = await sp.web.loadClientsidePage("/sites/dev/sitepages/home.aspx"); diff --git a/docs/sp/content-types.md b/docs/sp/content-types.md index 215e23dc4..f9623c859 100644 --- a/docs/sp/content-types.md +++ b/docs/sp/content-types.md @@ -11,7 +11,7 @@ Content Types are used to define sets of columns in SharePoint. The following example shows how to add the built in Picture Content Type to the Documents library. ```TypeScript -const sp = spfi("{tenant url}").using(SPFx(this.context)); +const sp = spfi(...); sp.web.lists.getByTitle("Documents").contentTypes.addAvailableContentType("0x010102"); ``` @@ -21,7 +21,7 @@ sp.web.lists.getByTitle("Documents").contentTypes.addAvailableContentType("0x010 ```TypeScript import { IContentType } from "@pnp/sp/content-types"; -const sp = spfi("{tenant url}").using(SPFx(this.context)); +const sp = spfi(...); const d: IContentType = await sp.web.contentTypes.getById("0x01")(); @@ -34,7 +34,7 @@ console.log(d.name); To add a new Content Type to a collection, parameters id and name are required. For more information on creating content type IDs reference the [Microsoft Documentation](https://docs.microsoft.com/en-us/previous-versions/office/developer/sharepoint-2010/aa543822(v=office.14)). While this documentation references SharePoint 2010 the structure of the IDs has not changed. ```TypeScript -const sp = spfi("{tenant url}").using(SPFx(this.context)); +const sp = spfi(...); sp.web.contentTypes.add("0x01008D19F38845B0884EBEBE239FDF359184", "My Content Type"); ``` @@ -42,7 +42,7 @@ sp.web.contentTypes.add("0x01008D19F38845B0884EBEBE239FDF359184", "My Content Ty It is also possible to provide a description and group parameter. For other settings, we can use the parameter named 'additionalSettings' which is a TypedHash, meaning you can send whatever properties you'd like in the body (provided that the property is supported by the SharePoint API). ```TypeScript -const sp = spfi("{tenant url}").using(SPFx(this.context)); +const sp = spfi(...); //Adding a content type with id, name, description, group and setting it to read only mode (using additionalsettings) sp.web.contentTypes.add("0x01008D19F38845B0884EBEBE239FDF359184", "My Content Type", "This is my content type.", "_PnP Content Types", { ReadOnly: true }); @@ -57,11 +57,11 @@ sp.web.contentTypes.add("0x01008D19F38845B0884EBEBE239FDF359184", "My Content Ty Use this method to get a collection containing all the field links (SP.FieldLink) for a Content Type. ```TypeScript -import { spfi, SPFx } from "@pnp/sp"; +import { spfi } from "@pnp/sp"; import "@pnp/sp/webs"; import { ContentType, IContentType } from "@pnp/sp/content-types"; -const sp = spfi("{tenant url}").using(SPFx(this.context)); +const sp = spfi(...); // get field links from built in Content Type Document (Id: "0x0101") const d = await sp.web.contentTypes.getById("0x0101").fieldLinks(); @@ -75,11 +75,11 @@ console.log(d); To get a collection with all fields on the Content Type, simply use this method. ```TypeScript -import { spfi, SPFx } from "@pnp/sp"; +import { spfi } from "@pnp/sp"; import "@pnp/sp/webs"; import { ContentType, IContentType } from "@pnp/sp/content-types"; -const sp = spfi("{tenant url}").using(SPFx(this.context)); +const sp = spfi(...); // get fields from built in Content Type Document (Id: "0x0101") const d = await sp.web.contentTypes.getById("0x0101").fields(); @@ -91,11 +91,11 @@ console.log(d); ### Get parent Content Type ```TypeScript -import { spfi, SPFx } from "@pnp/sp"; +import { spfi } from "@pnp/sp"; import "@pnp/sp/webs"; import { ContentType, IContentType } from "@pnp/sp/content-types"; -const sp = spfi("{tenant url}").using(SPFx(this.context)); +const sp = spfi(...); // get parent Content Type from built in Content Type Document (Id: "0x0101") const d = await sp.web.contentTypes.getById("0x0101").parent(); @@ -107,11 +107,11 @@ console.log(d.Name) ### Get Content Type Workflow associations ```TypeScript -import { spfi, SPFx } from "@pnp/sp"; +import { spfi } from "@pnp/sp"; import "@pnp/sp/webs"; import { ContentType, IContentType } from "@pnp/sp/content-types"; -const sp = spfi("{tenant url}").using(SPFx(this.context)); +const sp = spfi(...); // get workflow associations from built in Content Type Document (Id: "0x0101") const d = await sp.web.contentTypes.getById("0x0101").workflowAssociations(); diff --git a/docs/sp/features.md b/docs/sp/features.md index dea134bfc..3c7fc93d3 100644 --- a/docs/sp/features.md +++ b/docs/sp/features.md @@ -13,9 +13,9 @@ Represents a collection of features. SharePoint Sites and Webs will have a colle Gets the information about a feature for the given GUID ```TypeScript -import { spfi, SPFx } from "@pnp/sp"; +import { spfi } from "@pnp/sp"; -const sp = spfi("{tenant url}").using(SPFx(this.context)); +const sp = spfi(...); //Example of GUID format a7a2793e-67cd-4dc1-9fd0-43f61581207a const webFeatureId = "guid-of-web-feature"; @@ -30,9 +30,9 @@ const siteFeature = await sp.site.features.getById(siteFeatureId)(); Adds (activates) a feature at the Site or Web level ```TypeScript -import { spfi, SPFx } from "@pnp/sp"; +import { spfi } from "@pnp/sp"; -const sp = spfi("{tenant url}").using(SPFx(this.context)); +const sp = spfi(...); //Example of GUID format a7a2793e-67cd-4dc1-9fd0-43f61581207a const webFeatureId = "guid-of-web-feature"; @@ -46,9 +46,9 @@ res = await sp.web.features.add(webFeatureId, true); Removes and deactivates the specified feature from the SharePoint Site or Web ```TypeScript -import { spfi, SPFx } from "@pnp/sp"; +import { spfi } from "@pnp/sp"; -const sp = spfi("{tenant url}").using(SPFx(this.context)); +const sp = spfi(...); //Example of GUID format a7a2793e-67cd-4dc1-9fd0-43f61581207a const webFeatureId = "guid-of-web-feature"; @@ -68,11 +68,11 @@ Represents an instance of a SharePoint feature. Deactivates the specified feature from the SharePoint Site or Web ```TypeScript -import { spfi, SPFx } from "@pnp/sp"; +import { spfi } from "@pnp/sp"; import "@pnp/sp/webs"; import "@pnp/sp/features"; -const sp = spfi("{tenant url}").using(SPFx(this.context)); +const sp = spfi(...); //Example of GUID format a7a2793e-67cd-4dc1-9fd0-43f61581207a const webFeatureId = "guid-of-web-feature"; diff --git a/docs/sp/fields.md b/docs/sp/fields.md index 4657a99b9..4bf62843f 100644 --- a/docs/sp/fields.md +++ b/docs/sp/fields.md @@ -11,14 +11,14 @@ Fields in SharePoint can be applied to both webs and lists. When referencing a w Gets a field from the collection by id (guid). Note that the library will handle a guid formatted with curly braces (i.e. '{03b05ff4-d95d-45ed-841d-3855f77a2483}') as well as without curly braces (i.e. '03b05ff4-d95d-45ed-841d-3855f77a2483'). The Id parameter is also case insensitive. ```TypeScript -import { spfi, SPFx } from "@pnp/sp"; +import { spfi } from "@pnp/sp"; import { IField, IFieldInfo } from "@pnp/sp/fields/types"; import "@pnp/sp/webs"; import "@pnp/sp/lists/web"; import "@pnp/sp/fields"; // set up sp root object -const sp = spfi("{tenant url}").using(SPFx(this.context)); +const sp = spfi(...); // get the field by Id for web const field: IField = sp.web.fields.getById("03b05ff4-d95d-45ed-841d-3855f77a2483"); // get the field by Id for list 'My List' @@ -36,13 +36,13 @@ console.log(r.Title); You can also get a field from the collection by title. ```TypeScript -import { spfi, SPFx } from "@pnp/sp"; +import { spfi } from "@pnp/sp"; import { IField, IFieldInfo } from "@pnp/sp/fields/types"; import "@pnp/sp/webs"; import "@pnp/sp/lists" import "@pnp/sp/fields"; -const sp = spfi("{tenant url}").using(SPFx(this.context)); +const sp = spfi(...); // get the field with the title 'Author' for web const field: IField = sp.web.fields.getByTitle("Author"); // get the field with the title 'Title' for list 'My List' @@ -60,13 +60,13 @@ console.log(r.Id); You can also get a field from the collection regardless of if the string is the fields internal name or title which can be different. ```TypeScript -import { spfi, SPFx } from "@pnp/sp"; +import { spfi } from "@pnp/sp"; import { IField, IFieldInfo } from "@pnp/sp/fields/types"; import "@pnp/sp/webs"; import "@pnp/sp/lists" import "@pnp/sp/fields"; -const sp = spfi("{tenant url}").using(SPFx(this.context)); +const sp = spfi(...); // get the field with the internal name 'ModifiedBy' for web const field: IField = sp.web.fields.getByInternalNameOrTitle("ModifiedBy"); // get the field with the internal name 'ModifiedBy' for list 'My List' @@ -84,14 +84,14 @@ console.log(r.Id); Create a new field by defining an XML schema that assigns all the properties for the field. ```TypeScript -import { spfi, SPFx } from "@pnp/sp"; +import { spfi } from "@pnp/sp"; import { IField, IFieldAddResult } from "@pnp/sp/fields/types"; import "@pnp/sp/webs"; import "@pnp/sp/lists"; import "@pnp/sp/fields"; -const sp = spfi("{tenant url}").using(SPFx(this.context)); +const sp = spfi(...); // define the schema for your new field, in this case a date field with a default date of today. const fieldSchema = `[today]`; @@ -113,13 +113,13 @@ console.log(r.Id); Use the add method to create a new field where you define the field type ```TypeScript -import { spfi, SPFx } from "@pnp/sp"; +import { spfi } from "@pnp/sp"; import { IField, IFieldAddResult, FieldTypes } from "@pnp/sp/fields/types"; import "@pnp/sp/webs"; import "@pnp/sp/lists"; import "@pnp/sp/fields"; -const sp = spfi("{tenant url}").using(SPFx(this.context)); +const sp = spfi(...); // create a new field called 'My Field' in web. const field: IFieldAddResult = await sp.web.fields.add("My Field", FieldTypes.Text, { FieldTypeKind: 3, Group: "My Group" }); @@ -138,13 +138,13 @@ console.log(r.Id); Use the createFieldAsXml method to add a site field to a list. ```TypeScript -import { spfi, SPFx } from "@pnp/sp"; +import { spfi } from "@pnp/sp"; import { IFieldAddResult, FieldTypes } from "@pnp/sp/fields/types"; import "@pnp/sp/webs"; import "@pnp/sp/lists"; import "@pnp/sp/fields"; -const sp = spfi("{tenant url}").using(SPFx(this.context)); +const sp = spfi(...); // create a new field called 'My Field' in web. const field: IFieldAddResult = await sp.web.fields.add("My Field", FieldTypes.Text, { FieldTypeKind: 3, Group: "My Group" }); @@ -160,13 +160,13 @@ console.log(r.data.Id); Use the addText method to create a new text field. ```TypeScript -import { spfi, SPFx } from "@pnp/sp"; +import { spfi } from "@pnp/sp"; import { IFieldAddResult, FieldTypes } from "@pnp/sp/fields/types"; import "@pnp/sp/webs"; import "@pnp/sp/lists"; import "@pnp/sp/fields"; -const sp = spfi("{tenant url}").using(SPFx(this.context)); +const sp = spfi(...); // create a new text field called 'My Field' in web. const field: IFieldAddResult = await sp.web.fields.addText("My Field", { MaxLength: 255, Group: "My Group" }); @@ -185,13 +185,13 @@ console.log(r.Id); Use the addCalculated method to create a new calculated field. ```TypeScript -import { spfi, SPFx } from "@pnp/sp"; +import { spfi } from "@pnp/sp"; import { DateTimeFieldFormatType, FieldTypes } from "@pnp/sp/fields/types"; import "@pnp/sp/webs"; import "@pnp/sp/lists"; import "@pnp/sp/fields"; -const sp = spfi("{tenant url}").using(SPFx(this.context)); +const sp = spfi(...); // create a new calculated field called 'My Field' in web const field = await sp.web.fields.addCalculated("My Field", { Formula: "=Modified+1", DateFormat: DateTimeFieldFormatType.DateOnly, FieldTypeKind: FieldTypes.DateTime, Group: "MyGroup" }); @@ -210,13 +210,13 @@ console.log(r.Id); Use the addDateTime method to create a new date/time field. ```TypeScript -import { spfi, SPFx } from "@pnp/sp"; +import { spfi } from "@pnp/sp"; import { DateTimeFieldFormatType, CalendarType, DateTimeFieldFriendlyFormatType } from "@pnp/sp/fields/types"; import "@pnp/sp/webs"; import "@pnp/sp/lists"; import "@pnp/sp/fields"; -const sp = spfi("{tenant url}").using(SPFx(this.context)); +const sp = spfi(...); // create a new date/time field called 'My Field' in web const field = await sp.web.fields.addDateTime("My Field", { DisplayFormat: DateTimeFieldFormatType.DateOnly, DateTimeCalendarType: CalendarType.Gregorian, FriendlyDisplayFormat: DateTimeFieldFriendlyFormatType.Disabled, Group: "My Group" }); @@ -235,12 +235,12 @@ console.log(r.Id); Use the addCurrency method to create a new currency field. ```TypeScript -import { spfi, SPFx } from "@pnp/sp"; +import { spfi } from "@pnp/sp"; import "@pnp/sp/webs"; import "@pnp/sp/lists"; import "@pnp/sp/fields"; -const sp = spfi("{tenant url}").using(SPFx(this.context)); +const sp = spfi(...); // create a new currency field called 'My Field' in web const field = await sp.web.fields.addCurrency("My Field", { MinimumValue: 0, MaximumValue: 100, CurrencyLocaleId: 1033, Group: "My Group" }); @@ -260,12 +260,12 @@ Use the addMultilineText method to create a new multi-line text field. >For Enhanced Rich Text mode, see the next section. ```TypeScript -import { spfi, SPFx } from "@pnp/sp"; +import { spfi } from "@pnp/sp"; import "@pnp/sp/webs"; import "@pnp/sp/lists"; import "@pnp/sp/fields"; -const sp = spfi("{tenant url}").using(SPFx(this.context)); +const sp = spfi(...); // create a new multi-line text field called 'My Field' in web const field = await sp.web.fields.addMultilineText("My Field", { NumberOfLines: 6, RichText: true, RestrictedMode: false, AppendOnly: false, AllowHyperlink: true, Group: "My Group" }); @@ -284,12 +284,12 @@ console.log(r.Id); The REST endpoint doesn't support setting the `RichTextMode` field therefore you will need to revert to Xml to create the field. The following is an example that will create a multi-line text field in Enhanced Rich Text mode. ```TypeScript -import { spfi, SPFx } from "@pnp/sp"; +import { spfi } from "@pnp/sp"; import "@pnp/sp/webs"; import "@pnp/sp/lists"; import "@pnp/sp/fields"; -const sp = spfi("{tenant url}").using(SPFx(this.context)); +const sp = spfi(...); //Create a new multi-line text field called 'My Field' in web const field = await sp.web.lists.getByTitle("My List").fields.createFieldAsXml( @@ -308,12 +308,12 @@ console.log(r.Id); Use the addNumber method to create a new number field. ```TypeScript -import { spfi, SPFx } from "@pnp/sp"; +import { spfi } from "@pnp/sp"; import "@pnp/sp/webs"; import "@pnp/sp/lists"; import "@pnp/sp/fields"; -const sp = spfi("{tenant url}").using(SPFx(this.context)); +const sp = spfi(...); // create a new number field called 'My Field' in web const field = await sp.web.fields.addNumber("My Field", { MinimumValue: 1, MaximumValue: 100, Group: "My Group" }); @@ -332,13 +332,13 @@ console.log(r.Id); Use the addUrl method to create a new url field. ```TypeScript -import { spfi, SPFx } from "@pnp/sp"; +import { spfi } from "@pnp/sp"; import { UrlFieldFormatType } from "@pnp/sp/fields/types"; import "@pnp/sp/webs"; import "@pnp/sp/lists"; import "@pnp/sp/fields"; -const sp = spfi("{tenant url}").using(SPFx(this.context)); +const sp = spfi(...); // create a new url field called 'My Field' in web const field = await sp.web.fields.addUrl("My Field", { DisplayFormat: UrlFieldFormatType.Hyperlink, Group: "My Group" }); @@ -357,13 +357,13 @@ console.log(r.Id); Use the addUser method to create a new user field. ```TypeScript -import { spfi, SPFx } from "@pnp/sp"; +import { spfi } from "@pnp/sp"; import { FieldUserSelectionMode } from "@pnp/sp/fields/types"; import "@pnp/sp/webs"; import "@pnp/sp/lists"; import "@pnp/sp/fields"; -const sp = spfi("{tenant url}").using(SPFx(this.context)); +const sp = spfi(...); // create a new user field called 'My Field' in web const field = await sp.web.fields.addUser("My Field", { { SelectionMode: FieldUserSelectionMode.PeopleOnly, Group: "My Group" }); @@ -382,14 +382,14 @@ console.log(r.Id); Use the addLookup method to create a new lookup field. ```TypeScript -import { spfi, SPFx } from "@pnp/sp"; +import { spfi } from "@pnp/sp"; import { FieldTypes } from "@pnp/sp/fields/types"; import "@pnp/sp/webs"; import "@pnp/sp/lists"; import "@pnp/sp/fields"; -const sp = spfi("{tenant url}").using(SPFx(this.context)); +const sp = spfi(...); const list = await sp.web.lists.getByTitle("My Lookup List")(); // create a new lookup field called 'My Field' based on an existing list 'My Lookup List' showing 'Title' field in web. @@ -415,13 +415,13 @@ await fieldAddResult.field.update({ Description: 'New Description' }, "SP.FieldL Use the addChoice method to create a new choice field. ```TypeScript -import { spfi, SPFx } from "@pnp/sp"; +import { spfi } from "@pnp/sp"; import { ChoiceFieldFormatType } from "@pnp/sp/fields/types"; import "@pnp/sp/webs"; import "@pnp/sp/lists"; import "@pnp/sp/fields"; -const sp = spfi("{tenant url}").using(SPFx(this.context)); +const sp = spfi(...); const choices = [`ChoiceA`, `ChoiceB`, `ChoiceC`]; // create a new choice field called 'My Field' in web @@ -441,13 +441,13 @@ console.log(r.Id); Use the addMultiChoice method to create a new multi-choice field. ```TypeScript -import { spfi, SPFx } from "@pnp/sp"; +import { spfi } from "@pnp/sp"; import { ChoiceFieldFormatType } from "@pnp/sp/fields/types"; import "@pnp/sp/webs"; import "@pnp/sp/lists"; import "@pnp/sp/fields"; -const sp = spfi("{tenant url}").using(SPFx(this.context)); +const sp = spfi(...); const choices = [`ChoiceA`, `ChoiceB`, `ChoiceC`]; // create a new multi-choice field called 'My Field' in web @@ -467,12 +467,12 @@ console.log(r.Id); Use the addBoolean method to create a new boolean field. ```TypeScript -import { spfi, SPFx } from "@pnp/sp"; +import { spfi } from "@pnp/sp"; import "@pnp/sp/webs"; import "@pnp/sp/lists"; import "@pnp/sp/fields"; -const sp = spfi("{tenant url}").using(SPFx(this.context)); +const sp = spfi(...); // create a new boolean field called 'My Field' in web const field = await sp.web.fields.addBoolean("My Field", { Group: "My Group" }); @@ -491,12 +491,12 @@ console.log(r.Id); Use the addDependentLookupField method to create a new dependent lookup field. ```TypeScript -import { spfi, SPFx } from "@pnp/sp"; +import { spfi } from "@pnp/sp"; import "@pnp/sp/webs"; import "@pnp/sp/lists"; import "@pnp/sp/fields"; -const sp = spfi("{tenant url}").using(SPFx(this.context)); +const sp = spfi(...); const field = await sp.web.fields.addLookup("My Field", { LookupListId: list.Id, LookupFieldName: "Title" }); // create a new dependent lookup field called 'My Dep Field' showing 'Description' based on an existing 'My Field' lookup field in web. @@ -517,12 +517,12 @@ console.log(r.Id); Use the addLocation method to create a new location field. ```TypeScript -import { spfi, SPFx } from "@pnp/sp"; +import { spfi } from "@pnp/sp"; import "@pnp/sp/webs"; import "@pnp/sp/lists"; import "@pnp/sp/fields"; -const sp = spfi("{tenant url}").using(SPFx(this.context)); +const sp = spfi(...); // create a new location field called 'My Field' in web const field = await sp.web.fields.addLocation("My Field", { Group: "My Group" }); @@ -541,11 +541,11 @@ console.log(r.Id); Use the delete method to delete a field. ```TypeScript -import { spfi, SPFx } from "@pnp/sp"; +import { spfi } from "@pnp/sp"; import "@pnp/sp/webs"; import "@pnp/sp/fields"; -const sp = spfi("{tenant url}").using(SPFx(this.context)); +const sp = spfi(...); await sp.web.fields.addBoolean("Temp Field", { Group: "My Group" }); await sp.web.fields.addBoolean("Temp Field 2", { Group: "My Group" }); @@ -567,12 +567,12 @@ const result2 = await sp.web.lists.getByTitle("My List").fields.getByTitle("Temp Use the update method to update a field. ```TypeScript -import { spfi, SPFx } from "@pnp/sp"; +import { spfi } from "@pnp/sp"; import "@pnp/sp/webs"; import "@pnp/sp/lists"; import "@pnp/sp/fields"; -const sp = spfi("{tenant url}").using(SPFx(this.context)); +const sp = spfi(...); // update the field called 'My Field' with a description in web, returns FieldUpdateResult const fieldUpdate = await sp.web.fields.getByTitle("My Field").update({ Description: "My Description" }); @@ -589,12 +589,12 @@ const fieldUpdate2 = await sp.web.lists.getByTitle("My List").fields.getByTitle( Use the setShowInDisplayForm method to add a field to the display form. ```TypeScript -import { spfi, SPFx } from "@pnp/sp"; +import { spfi } from "@pnp/sp"; import "@pnp/sp/webs"; import "@pnp/sp/lists"; import "@pnp/sp/fields"; -const sp = spfi("{tenant url}").using(SPFx(this.context)); +const sp = spfi(...); // show field called 'My Field' in display form throughout web await sp.web.fields.getByTitle("My Field").setShowInDisplayForm(true); @@ -607,12 +607,12 @@ await sp.web.lists.getByTitle("My List").fields.getByTitle("My Field").setShowIn Use the setShowInEditForm method to add a field to the edit form. ```TypeScript -import { spfi, SPFx } from "@pnp/sp"; +import { spfi } from "@pnp/sp"; import "@pnp/sp/webs"; import "@pnp/sp/lists"; import "@pnp/sp/fields"; -const sp = spfi("{tenant url}").using(SPFx(this.context)); +const sp = spfi(...); // show field called 'My Field' in edit form throughout web await sp.web.fields.getByTitle("My Field").setShowInEditForm(true); @@ -625,12 +625,12 @@ await sp.web.lists.getByTitle("My List").fields.getByTitle("My Field").setShowIn Use the setShowInNewForm method to add a field to the display form. ```TypeScript -import { spfi, SPFx } from "@pnp/sp"; +import { spfi } from "@pnp/sp"; import "@pnp/sp/webs"; import "@pnp/sp/lists"; import "@pnp/sp/fields"; -const sp = spfi("{tenant url}").using(SPFx(this.context)); +const sp = spfi(...); // show field called 'My Field' in new form throughout web await sp.web.fields.getByTitle("My Field").setShowInNewForm(true); diff --git a/docs/sp/files.md b/docs/sp/files.md index 8485857e0..d14e57c50 100644 --- a/docs/sp/files.md +++ b/docs/sp/files.md @@ -7,12 +7,12 @@ One of the more challenging tasks on the client side is working with SharePoint Reading files from the client using REST is covered in the below examples. The important thing to remember is choosing which format you want the file in so you can appropriately process it. You can retrieve a file as Blob, Buffer, JSON, or Text. If you have a special requirement you could also write your [own parser](../queryable/behaviors.md#parsers). ```typescript -import { spfi, SPFx } from "@pnp/sp"; +import { spfi } from "@pnp/sp"; import "@pnp/sp/webs"; import "@pnp/sp/files"; import "@pnp/sp/folders"; -const sp = spfi("{tenant url}").using(SPFx(this.context)); +const sp = spfi(...); const blob: Blob = await sp.web.getFileByServerRelativePath("/sites/dev/documents/file.avi").getBlob(); @@ -31,11 +31,11 @@ const text2: string = await sp.web.getFolderByServerRelativePath("/sites/dev/doc This method supports opening files from sharing links or absolute urls. The file must reside in the site from which you are trying to open the file. ```TypeScript -import { spfi, SPFx } from "@pnp/sp"; +import { spfi } from "@pnp/sp"; import "@pnp/sp/webs"; import "@pnp/sp/files/web"; -const sp = spfi("{tenant url}").using(SPFx(this.context)); +const sp = spfi(...); const url = "{absolute file url OR sharing url}"; @@ -142,12 +142,12 @@ const fr = await sp.web.lists.getByTitle("Documents").rootFolder.files.addChunke You can also update the file properties of a newly uploaded file using code similar to the below snippet: ```TypeScript -import { spfi, SPFx } from "@pnp/sp"; +import { spfi } from "@pnp/sp"; import "@pnp/sp/webs"; import "@pnp/sp/files"; import "@pnp/sp/folders"; -const sp = spfi("{tenant url}").using(SPFx(this.context)); +const sp = spfi(...); const file = await sp.web.getFolderByServerRelativePath("/sites/dev/Shared%20Documents/test/").files.addUsingPath("file.name", "content", {Overwrite: true}); const item = await file.file.getItem(); await item.update({ @@ -163,12 +163,12 @@ You can of course use similar methods to update existing files as shown below. T ![Batching Not Supported Banner](https://img.shields.io/badge/Batching%20Not%20Supported-important.svg) ```typescript -import { spfi, SPFx } from "@pnp/sp"; +import { spfi } from "@pnp/sp"; import "@pnp/sp/webs"; import "@pnp/sp/files"; import "@pnp/sp/folders"; -const sp = spfi("{tenant url}").using(SPFx(this.context)); +const sp = spfi(...); await sp.web.getFileByServerRelativePath("/sites/dev/documents/test.txt").setContent("New string content for the file."); await sp.web.getFileByServerRelativePath("/sites/dev/documents/test.mp4").setContentChunked(file); @@ -183,12 +183,12 @@ The library provides helper methods for checking in, checking out, and approving Check in takes two optional arguments, comment and check in type. ```TypeScript -import { spfi, SPFx } from "@pnp/sp"; +import { spfi } from "@pnp/sp"; import { CheckinType } from "@pnp/sp/files"; import "@pnp/sp/webs"; import "@pnp/sp/files"; -const sp = spfi("{tenant url}").using(SPFx(this.context)); +const sp = spfi(...); // default options with empty comment and CheckinType.Major await sp.web.getFileByServerRelativePath("/sites/dev/shared documents/file.txt").checkin(); @@ -208,11 +208,11 @@ console.log("File checked in!"); Check out takes no arguments. ```TypeScript -import { spfi, SPFx } from "@pnp/sp"; +import { spfi } from "@pnp/sp"; import "@pnp/sp/webs"; import "@pnp/sp/files"; -const sp = spfi("{tenant url}").using(SPFx(this.context)); +const sp = spfi(...); sp.web.getFileByServerRelativePath("/sites/dev/shared documents/file.txt").checkout(); console.log("File checked out!"); @@ -223,11 +223,11 @@ console.log("File checked out!"); You can also approve or deny files in libraries that use approval. Approve takes a single required argument of comment, the comment is optional for deny. ```TypeScript -import { spfi, SPFx } from "@pnp/sp"; +import { spfi } from "@pnp/sp"; import "@pnp/sp/webs"; import "@pnp/sp/files"; -const sp = spfi("{tenant url}").using(SPFx(this.context)); +const sp = spfi(...); await sp.web.getFileByServerRelativePath("/sites/dev/shared documents/file.txt").approve("Approval Comment"); console.log("File approved!"); @@ -246,11 +246,11 @@ console.log("File denied!"); You can both publish and unpublish a file using the library. Both methods take an optional comment argument. ```TypeScript -import { spfi, SPFx } from "@pnp/sp"; +import { spfi } from "@pnp/sp"; import "@pnp/sp/webs"; import "@pnp/sp/files"; -const sp = spfi("{tenant url}").using(SPFx(this.context)); +const sp = spfi(...); // publish with no comment await sp.web.getFileByServerRelativePath("/sites/dev/shared documents/file.txt").publish(); @@ -309,7 +309,7 @@ import "@pnp/sp/files"; import "@pnp/sp/folders"; import "@pnp/sp/security"; -const sp = spfi("{tenant url}").using(SPFx(this.context)); +const sp = spfi(...); const item = await sp.web.getFileByServerRelativePath("/sites/dev/Shared Documents/test.txt").getItem(); console.log(item); @@ -332,7 +332,7 @@ import "@pnp/sp/folders"; import "@pnp/sp/items"; import "@pnp/sp/security"; -const sp = spfi("{tenant url}").using(SPFx(this.context)); +const sp = spfi(...); // also supports typing the objects so your type will be a union type const item = await sp.web.getFileByServerRelativePath("/sites/dev/Shared Documents/test.txt").getItem<{ Id: number, Title: string }>("Id", "Title"); @@ -350,11 +350,11 @@ console.log(perms); It's possible to move a file to a new destination within a site collection ```TypeScript -import { spfi, SPFx } from "@pnp/sp"; +import { spfi } from "@pnp/sp"; import "@pnp/sp/webs"; import "@pnp/sp/files"; -const sp = spfi("{tenant url}").using(SPFx(this.context)); +const sp = spfi(...); // destination is a server-relative url of a new file const destinationUrl = `/sites/dev/SiteAssets/new-file.docx`; @@ -367,11 +367,11 @@ await sp.web.getFileByServerRelativePath("/sites/dev/Shared Documents/test.docx" It's possible to copy a file to a new destination within a site collection ```TypeScript -import { spfi, SPFx } from "@pnp/sp"; +import { spfi } from "@pnp/sp"; import "@pnp/sp/webs"; import "@pnp/sp/files"; -const sp = spfi("{tenant url}").using(SPFx(this.context)); +const sp = spfi(...); // destination is a server-relative url of a new file const destinationUrl = `/sites/dev/SiteAssets/new-file.docx`; @@ -384,11 +384,11 @@ await sp.web.getFileByServerRelativePath("/sites/dev/Shared Documents/test.docx" It's possible to copy a file to a new destination within the same or a different site collection ```TypeScript -import { spfi, SPFx } from "@pnp/sp"; +import { spfi } from "@pnp/sp"; import "@pnp/sp/webs"; import "@pnp/sp/files"; -const sp = spfi("{tenant url}").using(SPFx(this.context)); +const sp = spfi(...); // destination is a server-relative url of a new file const destinationUrl = `/sites/dev2/SiteAssets/new-file.docx`; @@ -401,12 +401,12 @@ await sp.web.getFileByServerRelativePath("/sites/dev/Shared Documents/test.docx" You can get a file by Id from a web. ```TypeScript -import { spfi, SPFx } from "@pnp/sp"; +import { spfi } from "@pnp/sp"; import "@pnp/sp/webs"; import "@pnp/sp/files"; import { IFile } from "@pnp/sp/files"; -const sp = spfi("{tenant url}").using(SPFx(this.context)); +const sp = spfi(...); const file: IFile = sp.web.getFileById("2b281c7b-ece9-4b76-82f9-f5cf5e152ba0"); ``` @@ -416,11 +416,11 @@ const file: IFile = sp.web.getFileById("2b281c7b-ece9-4b76-82f9-f5cf5e152ba0"); Deletes a file ```TypeScript -import { spfi, SPFx } from "@pnp/sp"; +import { spfi } from "@pnp/sp"; import "@pnp/sp/webs"; import "@pnp/sp/files"; -const sp = spfi("{tenant url}").using(SPFx(this.context)); +const sp = spfi(...); await sp.web.getFolderByServerRelativePath("{folder relative path}").files.getByUrl("filename.txt").delete(); ``` @@ -429,11 +429,11 @@ await sp.web.getFolderByServerRelativePath("{folder relative path}").files.getBy Deletes a file with options ```TypeScript -import { spfi, SPFx } from "@pnp/sp"; +import { spfi } from "@pnp/sp"; import "@pnp/sp/webs"; import "@pnp/sp/files"; -const sp = spfi("{tenant url}").using(SPFx(this.context)); +const sp = spfi(...); await sp.web.getFolderByServerRelativePath("{folder relative path}").files.getByUrl("filename.txt").deleteWithParams({ BypassSharedLock: true, }); @@ -444,10 +444,10 @@ await sp.web.getFolderByServerRelativePath("{folder relative path}").files.getBy Checks to see if a file exists ```TypeScript -import { spfi, SPFx } from "@pnp/sp"; +import { spfi } from "@pnp/sp"; import "@pnp/sp/webs"; import "@pnp/sp/files"; -const sp = spfi("{tenant url}").using(SPFx(this.context)); +const sp = spfi(...); const exists = await sp.web.getFolderByServerRelativePath("{folder relative path}").files.getByUrl("name.txt").exists(); ``` diff --git a/docs/sp/folders.md b/docs/sp/folders.md index af4056b35..94c010969 100644 --- a/docs/sp/folders.md +++ b/docs/sp/folders.md @@ -11,13 +11,13 @@ Represents a collection of folders. SharePoint webs, lists, and list items have ### Get folders collection for various SharePoint objects ```TypeScript -import { spfi, SPFx } from "@pnp/sp"; +import { spfi } from "@pnp/sp"; import "@pnp/sp/webs"; import "@pnp/sp/items"; import "@pnp/sp/folders"; import "@pnp/sp/lists"; -const sp = spfi("{tenant url}").using(SPFx(this.context)); +const sp = spfi(...); // gets web's folders const webFolders = await sp.web.folders(); @@ -34,11 +34,11 @@ const itemFolders = await sp.web.lists.getByTitle("My List").items.getById(1).fo Adds a new folder to collection of folders ```TypeScript -import { spfi, SPFx } from "@pnp/sp"; +import { spfi } from "@pnp/sp"; import "@pnp/sp/webs"; import "@pnp/sp/folders"; -const sp = spfi("{tenant url}").using(SPFx(this.context)); +const sp = spfi(...); // creates a new folder for web with specified url const folderAddResult = await sp.web.folders.addUsingPath("folder url"); @@ -49,11 +49,11 @@ const folderAddResult = await sp.web.folders.addUsingPath("folder url"); Gets a folder instance from a collection by folder's name ```TypeScript -import { spfi, SPFx } from "@pnp/sp"; +import { spfi } from "@pnp/sp"; import "@pnp/sp/webs"; import "@pnp/sp/folders"; -const sp = spfi("{tenant url}").using(SPFx(this.context)); +const sp = spfi(...); const folder = await sp.web.folders.getByUrl("folder name")(); ``` @@ -67,13 +67,13 @@ Represents an instance of a SharePoint folder. ### Get a folder object associated with different SharePoint artifacts (web, list, list item) ```TypeScript -import { spfi, SPFx } from "@pnp/sp"; +import { spfi } from "@pnp/sp"; import "@pnp/sp/webs"; import "@pnp/sp/folders"; import "@pnp/sp/lists"; import "@pnp/sp/items"; -const sp = spfi("{tenant url}").using(SPFx(this.context)); +const sp = spfi(...); // web's folder const rootFolder = await sp.web.rootFolder(); @@ -90,11 +90,11 @@ const itemFolder = await sp.web.lists.getByTitle("234").items.getById(1).folder( Gets list item associated with a folder ```TypeScript -import { spfi, SPFx } from "@pnp/sp"; +import { spfi } from "@pnp/sp"; import "@pnp/sp/webs"; import "@pnp/sp/folders"; -const sp = spfi("{tenant url}").using(SPFx(this.context)); +const sp = spfi(...); const folderItem = await sp.web.rootFolder.folders.getByUrl("SiteAssets").folders.getByUrl("My Folder").getItem(); ``` @@ -104,11 +104,11 @@ const folderItem = await sp.web.rootFolder.folders.getByUrl("SiteAssets").folder It's possible to move a folder to a new destination within a site collection ```TypeScript -import { spfi, SPFx } from "@pnp/sp"; +import { spfi } from "@pnp/sp"; import "@pnp/sp/webs"; import "@pnp/sp/folders"; -const sp = spfi("{tenant url}").using(SPFx(this.context)); +const sp = spfi(...); // destination is a server-relative url of a new folder const destinationUrl = `/sites/my-site/SiteAssets/new-folder`; @@ -121,11 +121,11 @@ await sp.web.rootFolder.folders.getByUrl("SiteAssets").folders.getByUrl("My Fold It's possible to copy a folder to a new destination within a site collection ```TypeScript -import { spfi, SPFx } from "@pnp/sp"; +import { spfi } from "@pnp/sp"; import "@pnp/sp/webs"; import "@pnp/sp/folders"; -const sp = spfi("{tenant url}").using(SPFx(this.context)); +const sp = spfi(...); // destination is a server-relative url of a new folder const destinationUrl = `/sites/my-site/SiteAssets/new-folder`; @@ -138,11 +138,11 @@ await sp.web.rootFolder.folders.getByUrl("SiteAssets").folders.getByUrl("My Fold It's possible to move a folder to a new destination within the same or a different site collection ```TypeScript -import { spfi, SPFx } from "@pnp/sp"; +import { spfi } from "@pnp/sp"; import "@pnp/sp/webs"; import "@pnp/sp/folders"; -const sp = spfi("{tenant url}").using(SPFx(this.context)); +const sp = spfi(...); // destination is a server-relative url of a new folder const destinationUrl = `/sites/my-site/SiteAssets/new-folder`; @@ -155,11 +155,11 @@ await sp.web.rootFolder.folders.getByUrl("SiteAssets").folders.getByUrl("My Fold It's possible to copy a folder to a new destination within the same or a different site collection ```TypeScript -import { spfi, SPFx } from "@pnp/sp"; +import { spfi } from "@pnp/sp"; import "@pnp/sp/webs"; import "@pnp/sp/folders"; -const sp = spfi("{tenant url}").using(SPFx(this.context)); +const sp = spfi(...); // destination is a server-relative url of a new folder const destinationUrl = `/sites/my-site/SiteAssets/new-folder`; @@ -172,11 +172,11 @@ await sp.web.rootFolder.folders.getByUrl("SiteAssets").folders.getByUrl("My Fold Deletes a folder ```TypeScript -import { spfi, SPFx } from "@pnp/sp"; +import { spfi } from "@pnp/sp"; import "@pnp/sp/webs"; import "@pnp/sp/folders"; -const sp = spfi("{tenant url}").using(SPFx(this.context)); +const sp = spfi(...); await sp.web.rootFolder.folders.getByUrl("My Folder").delete(); ``` @@ -186,11 +186,11 @@ await sp.web.rootFolder.folders.getByUrl("My Folder").delete(); Deletes a folder with options ```TypeScript -import { spfi, SPFx } from "@pnp/sp"; +import { spfi } from "@pnp/sp"; import "@pnp/sp/webs"; import "@pnp/sp/folders"; -const sp = spfi("{tenant url}").using(SPFx(this.context)); +const sp = spfi(...); await sp.web.rootFolder.folders.getByUrl("My Folder").deleteWithParams({ BypassSharedLock: true, @@ -203,11 +203,11 @@ await sp.web.rootFolder.folders.getByUrl("My Folder").deleteWithParams({ Recycles a folder ```TypeScript -import { spfi, SPFx } from "@pnp/sp"; +import { spfi } from "@pnp/sp"; import "@pnp/sp/webs"; import "@pnp/sp/folders"; -const sp = spfi("{tenant url}").using(SPFx(this.context)); +const sp = spfi(...); await sp.web.rootFolder.folders.getByUrl("My Folder").recycle(); ``` @@ -217,11 +217,11 @@ await sp.web.rootFolder.folders.getByUrl("My Folder").recycle(); Gets folder's server relative url ```TypeScript -import { spfi, SPFx } from "@pnp/sp"; +import { spfi } from "@pnp/sp"; import "@pnp/sp/webs"; import "@pnp/sp/folders"; -const sp = spfi("{tenant url}").using(SPFx(this.context)); +const sp = spfi(...); const relUrl = await sp.web.rootFolder.folders.getByUrl("SiteAssets").select('ServerRelativeUrl')(); ``` @@ -231,11 +231,11 @@ const relUrl = await sp.web.rootFolder.folders.getByUrl("SiteAssets").select('Se Updates folder's properties ```TypeScript -import { spfi, SPFx } from "@pnp/sp"; +import { spfi } from "@pnp/sp"; import "@pnp/sp/webs"; import "@pnp/sp/folders"; -const sp = spfi("{tenant url}").using(SPFx(this.context)); +const sp = spfi(...); await sp.web.getFolderByServerRelativePath("Shared Documents/Folder2").update({ "Name": "New name", @@ -247,11 +247,11 @@ await sp.web.getFolderByServerRelativePath("Shared Documents/Folder2").update({ Gets content type order of a folder ```TypeScript -import { spfi, SPFx } from "@pnp/sp"; +import { spfi } from "@pnp/sp"; import "@pnp/sp/webs"; import "@pnp/sp/folders"; -const sp = spfi("{tenant url}").using(SPFx(this.context)); +const sp = spfi(...); const order = await sp.web.getFolderByServerRelativePath("Shared Documents").select('contentTypeOrder')(); ``` @@ -261,11 +261,11 @@ const order = await sp.web.getFolderByServerRelativePath("Shared Documents").sel Gets all child folders associated with the current folder ```TypeScript -import { spfi, SPFx } from "@pnp/sp"; +import { spfi } from "@pnp/sp"; import "@pnp/sp/webs"; import "@pnp/sp/folders"; -const sp = spfi("{tenant url}").using(SPFx(this.context)); +const sp = spfi(...); const folders = await sp.web.rootFolder.folders(); ``` @@ -275,12 +275,12 @@ const folders = await sp.web.rootFolder.folders(); Gets all files inside a folder ```TypeScript -import { spfi, SPFx } from "@pnp/sp"; +import { spfi } from "@pnp/sp"; import "@pnp/sp/webs"; import "@pnp/sp/folders"; import "@pnp/sp/files/folder"; -const sp = spfi("{tenant url}").using(SPFx(this.context)); +const sp = spfi(...); const files = await sp.web.getFolderByServerRelativePath("Shared Documents").files(); ``` @@ -290,11 +290,11 @@ const files = await sp.web.getFolderByServerRelativePath("Shared Documents").fil Gets this folder's list item field values ```TypeScript -import { spfi, SPFx } from "@pnp/sp"; +import { spfi } from "@pnp/sp"; import "@pnp/sp/webs"; import "@pnp/sp/folders"; -const sp = spfi("{tenant url}").using(SPFx(this.context)); +const sp = spfi(...); const itemFields = await sp.web.getFolderByServerRelativePath("Shared Documents/My Folder").listItemAllFields(); ``` @@ -304,11 +304,11 @@ const itemFields = await sp.web.getFolderByServerRelativePath("Shared Documents/ Gets the parent folder, if available ```TypeScript -import { spfi, SPFx } from "@pnp/sp"; +import { spfi } from "@pnp/sp"; import "@pnp/sp/webs"; import "@pnp/sp/folders"; -const sp = spfi("{tenant url}").using(SPFx(this.context)); +const sp = spfi(...); const parentFolder = await sp.web.getFolderByServerRelativePath("Shared Documents/My Folder").parentFolder(); ``` @@ -318,11 +318,11 @@ const parentFolder = await sp.web.getFolderByServerRelativePath("Shared Document Gets this folder's properties ```TypeScript -import { spfi, SPFx } from "@pnp/sp"; +import { spfi } from "@pnp/sp"; import "@pnp/sp/webs"; import "@pnp/sp/folders"; -const sp = spfi("{tenant url}").using(SPFx(this.context)); +const sp = spfi(...); const properties = await sp.web.getFolderByServerRelativePath("Shared Documents/Folder2").properties(); ``` @@ -332,11 +332,11 @@ const properties = await sp.web.getFolderByServerRelativePath("Shared Documents/ Gets a value that specifies the content type order. ```TypeScript -import { spfi, SPFx } from "@pnp/sp"; +import { spfi } from "@pnp/sp"; import "@pnp/sp/webs"; import "@pnp/sp/folders"; -const sp = spfi("{tenant url}").using(SPFx(this.context)); +const sp = spfi(...); const contentTypeOrder = await sp.web.getFolderByServerRelativePath("Shared Documents/Folder2").select('uniqueContentTypeOrder')(); ``` @@ -346,11 +346,11 @@ const contentTypeOrder = await sp.web.getFolderByServerRelativePath("Shared Docu You can rename a folder by updating `FileLeafRef` property: ```TypeScript -import { spfi, SPFx } from "@pnp/sp"; +import { spfi } from "@pnp/sp"; import "@pnp/sp/webs"; import "@pnp/sp/folders"; -const sp = spfi("{tenant url}").using(SPFx(this.context)); +const sp = spfi(...); const folder = sp.web.getFolderByServerRelativePath("Shared Documents/My Folder"); @@ -363,13 +363,13 @@ const result = await item.update({ FileLeafRef: "Folder2" }); Below code creates a new folder under Document library and assigns custom folder content type to a newly created folder. Additionally it sets a field of a custom folder content type. ```TypeScript -import { spfi, SPFx } from "@pnp/sp"; +import { spfi } from "@pnp/sp"; import "@pnp/sp/webs"; import "@pnp/sp/items"; import "@pnp/sp/folders"; import "@pnp/sp/lists"; -const sp = spfi("{tenant url}").using(SPFx(this.context)); +const sp = spfi(...); const newFolderResult = await sp.web.rootFolder.folders.getByUrl("Shared Documents").folders.addUsingPath("My New Folder"); const item = await newFolderResult.folder.listItemAllFields(); @@ -386,12 +386,12 @@ await sp.web.lists.getByTitle("Documents").items.getById(item.ID).update({ You can use the addSubFolderUsingPath method to add a folder with some special chars supported ```TypeScript -import { spfi, SPFx } from "@pnp/sp"; +import { spfi } from "@pnp/sp"; import "@pnp/sp/webs"; import "@pnp/sp/folders"; import { IFolder } from "@pnp/sp/folders"; -const sp = spfi("{tenant url}").using(SPFx(this.context)); +const sp = spfi(...); // add a folder to site assets const folder: IFolder = await sp.web.rootFolder.folders.getByUrl("SiteAssets").addSubFolderUsingPath("folder name"); @@ -402,12 +402,12 @@ const folder: IFolder = await sp.web.rootFolder.folders.getByUrl("SiteAssets").a You can get a folder by Id from a web. ```TypeScript -import { spfi, SPFx } from "@pnp/sp"; +import { spfi } from "@pnp/sp"; import "@pnp/sp/webs"; import "@pnp/sp/folders"; import { IFolder } from "@pnp/sp/folders"; -const sp = spfi("{tenant url}").using(SPFx(this.context)); +const sp = spfi(...); const folder: IFolder = sp.web.getFolderById("2b281c7b-ece9-4b76-82f9-f5cf5e152ba0"); ``` @@ -417,11 +417,11 @@ const folder: IFolder = sp.web.getFolderById("2b281c7b-ece9-4b76-82f9-f5cf5e152b Gets information about folder, including details about the parent list, parent list root folder, and parent web. ```TypeScript -import { spfi, SPFx } from "@pnp/sp"; +import { spfi } from "@pnp/sp"; import "@pnp/sp/webs"; import "@pnp/sp/folders"; -const sp = spfi("{tenant url}").using(SPFx(this.context)); +const sp = spfi(...); const folder: IFolder = sp.web.getFolderById("2b281c7b-ece9-4b76-82f9-f5cf5e152ba0"); await folder.getParentInfos(); diff --git a/docs/sp/forms.md b/docs/sp/forms.md index 4503819e9..a1b6b19b0 100644 --- a/docs/sp/forms.md +++ b/docs/sp/forms.md @@ -11,11 +11,11 @@ Forms in SharePoint are the Display, New, and Edit forms associated with a list. Gets a form from the collection by id (guid). Note that the library will handle a guid formatted with curly braces (i.e. '{03b05ff4-d95d-45ed-841d-3855f77a2483}') as well as without curly braces (i.e. '03b05ff4-d95d-45ed-841d-3855f77a2483'). The Id parameter is also case insensitive. ```TypeScript -import { spfi, SPFx } from "@pnp/sp"; +import { spfi } from "@pnp/sp"; import "@pnp/sp/forms"; import "@pnp/sp/lists"; -const sp = spfi("{tenant url}").using(SPFx(this.context)); +const sp = spfi(...); // get the field by Id for web const form = sp.web.lists.getByTitle("Documents").forms.getById("{c4486774-f1e2-4804-96f3-91edf3e22a19}")(); diff --git a/docs/sp/hubsites.md b/docs/sp/hubsites.md index a1dc0d093..c3e4414b3 100644 --- a/docs/sp/hubsites.md +++ b/docs/sp/hubsites.md @@ -9,11 +9,11 @@ This module helps you with working with hub sites in your tenant. ### Get a Listing of All Hub sites ```TypeScript -import { spfi, SPFx } from "@pnp/sp"; +import { spfi } from "@pnp/sp"; import { IHubSiteInfo } from "@pnp/sp/hubsites"; import "@pnp/sp/hubsites"; -const sp = spfi("{tenant url}").using(SPFx(this.context)); +const sp = spfi(...); // invoke the hub sites object const hubsites: IHubSiteInfo[] = await sp.hubSites(); @@ -27,11 +27,11 @@ const hubsites2: IHubSiteInfo[] = await sp.hubSites.select("ID", "Title", "Relat Using the getById method on the hubsites module to get a hub site by site Id (guid). ```TypeScript -import { spfi, SPFx } from "@pnp/sp"; +import { spfi } from "@pnp/sp"; import { IHubSiteInfo } from "@pnp/sp/hubsites"; import "@pnp/sp/hubsites"; -const sp = spfi("{tenant url}").using(SPFx(this.context)); +const sp = spfi(...); const hubsite: IHubSiteInfo = await sp.hubSites.getById("3504348e-b2be-49fb-a2a9-2d748db64beb")(); @@ -44,11 +44,11 @@ console.log(hubsite.Title); We provide a helper method to load the ISite instance from the HubSite ```TypeScript -import { spfi, SPFx } from "@pnp/sp"; +import { spfi } from "@pnp/sp"; import { ISite } from "@pnp/sp/sites"; import "@pnp/sp/hubsites"; -const sp = spfi("{tenant url}").using(SPFx(this.context)); +const sp = spfi(...); const site: ISite = await sp.hubSites.getById("3504348e-b2be-49fb-a2a9-2d748db64beb").getSite(); @@ -60,12 +60,12 @@ console.log(siteData.Title); ### Get Hub site data for a web ```TypeScript -import { spfi, SPFx } from "@pnp/sp"; +import { spfi } from "@pnp/sp"; import { IHubSiteWebData } from "@pnp/sp/hubsites"; import "@pnp/sp/webs"; import "@pnp/sp/hubsites/web"; -const sp = spfi("{tenant url}").using(SPFx(this.context)); +const sp = spfi(...); const webData: Partial = await sp.web.hubSiteData(); @@ -78,11 +78,11 @@ const webData2: Partial = await sp.web.hubSiteData(true); Allows you to apply theme updates from the parent hub site collection. ```TypeScript -import { spfi, SPFx } from "@pnp/sp"; +import { spfi } from "@pnp/sp"; import "@pnp/sp/webs"; import "@pnp/sp/hubsites/web"; -const sp = spfi("{tenant url}").using(SPFx(this.context)); +const sp = spfi(...); await sp.web.syncHubSiteTheme(); ``` @@ -96,11 +96,11 @@ You manage hub sites at the Site level. Id of the hub site collection you want to join. If you want to disassociate the site collection from hub site, then pass the siteId as 00000000-0000-0000-0000-000000000000 ```TypeScript -import { spfi, SPFx } from "@pnp/sp"; +import { spfi } from "@pnp/sp"; import "@pnp/sp/sites"; import "@pnp/sp/hubsites/site"; -const sp = spfi("{tenant url}").using(SPFx(this.context)); +const sp = spfi(...); // join a site to a hub site await sp.site.joinHubSite("{parent hub site id}"); @@ -114,11 +114,11 @@ await sp.site.joinHubSite("00000000-0000-0000-0000-000000000000"); Registers the current site collection as hub site collection ```TypeScript -import { spfi, SPFx } from "@pnp/sp"; +import { spfi } from "@pnp/sp"; import "@pnp/sp/sites"; import "@pnp/sp/hubsites/site"; -const sp = spfi("{tenant url}").using(SPFx(this.context)); +const sp = spfi(...); // register current site as a hub site await sp.site.registerHubSite(); @@ -129,11 +129,11 @@ await sp.site.registerHubSite(); Un-registers the current site collection as hub site collection. ```TypeScript -import { spfi, SPFx } from "@pnp/sp"; +import { spfi } from "@pnp/sp"; import "@pnp/sp/sites"; import "@pnp/sp/hubsites/site"; -const sp = spfi("{tenant url}").using(SPFx(this.context)); +const sp = spfi(...); // make a site no longer a hub await sp.site.unRegisterHubSite(); diff --git a/docs/sp/items.md b/docs/sp/items.md index f1c4141cf..5202cadbf 100644 --- a/docs/sp/items.md +++ b/docs/sp/items.md @@ -9,12 +9,12 @@ Getting items from a list is one of the basic actions that most applications req ### Basic Get ```TypeScript -import { spfi, SPFx } from "@pnp/sp"; +import { spfi } from "@pnp/sp"; import "@pnp/sp/webs"; import "@pnp/sp/lists"; import "@pnp/sp/items"; -const sp = spfi("{tenant url}").using(SPFx(this.context)); +const sp = spfi(...); // get all the items from a list const items: any[] = await sp.web.lists.getByTitle("My List").items(); @@ -34,12 +34,12 @@ console.log(items2); Working with paging can be a challenge as it is based on skip tokens and item ids, something that is hard to guess at runtime. To simplify things you can use the getPaged method on the Items class to assist. Note that there isn't a way to move backwards in the collection, this is by design. The pattern you should use to support backwards navigation in the results is to cache the results into a local array and use the standard array operators to get previous pages. Alternatively you can append the results to the UI, but this can have performance impact for large result sets. ```TypeScript -import { spfi, SPFx } from "@pnp/sp"; +import { spfi } from "@pnp/sp"; import "@pnp/sp/webs"; import "@pnp/sp/lists"; import "@pnp/sp/items"; -const sp = spfi("{tenant url}").using(SPFx(this.context)); +const sp = spfi(...); // basic case to get paged items form a list const items = await sp.web.lists.getByTitle("BigList").items.getPaged(); @@ -77,11 +77,11 @@ if (items.hasNext) { The GetListItemChangesSinceToken method allows clients to track changes on a list. Changes, including deleted items, are returned along with a token that represents the moment in time when those changes were requested. By including this token when you call GetListItemChangesSinceToken, the server looks for only those changes that have occurred since the token was generated. Sending a GetListItemChangesSinceToken request without including a token returns the list schema, the full list contents and a token. ```TypeScript -import { spfi, SPFx } from "@pnp/sp"; +import { spfi } from "@pnp/sp"; import "@pnp/sp/webs"; import "@pnp/sp/lists"; -const sp = spfi("{tenant url}").using(SPFx(this.context)); +const sp = spfi(...); // Using RowLimit. Enables paging const changes = await sp.web.lists.getByTitle("BigList").getListItemChangesSinceToken({RowLimit: '5'}); @@ -103,13 +103,13 @@ Using the items collection's getAll method you can get all of the items in a lis > In v3 there is a separate import for get-all to include the functionality. This is to remove the code from bundles for folks who do not need it. ```TypeScript -import { spfi, SPFx } from "@pnp/sp"; +import { spfi } from "@pnp/sp"; import "@pnp/sp/webs"; import "@pnp/sp/lists"; import "@pnp/sp/items"; import "@pnp/sp/items/get-all"; -const sp = spfi("{tenant url}").using(SPFx(this.context)); +const sp = spfi(...); // basic usage const allItems: any[] = await sp.web.lists.getByTitle("BigList").items.getAll(); @@ -133,12 +133,12 @@ console.log(allItems.length); When working with lookup fields you need to use the expand operator along with select to get the related fields from the lookup column. This works for both the items collection and item instances. ```TypeScript -import { spfi, SPFx } from "@pnp/sp"; +import { spfi } from "@pnp/sp"; import "@pnp/sp/webs"; import "@pnp/sp/lists"; import "@pnp/sp/items"; -const sp = spfi("{tenant url}").using(SPFx(this.context)); +const sp = spfi(...); const items = await sp.web.lists.getByTitle("LookupList").items.select("Title", "Lookup/Title", "Lookup/ID").expand("Lookup")(); console.log(items); @@ -152,11 +152,11 @@ console.log(item); To filter on a metadata field you must use the getItemsByCAMLQuery method as $filter does not support these fields. ```TypeScript -import { spfi, SPFx } from "@pnp/sp"; +import { spfi } from "@pnp/sp"; import "@pnp/sp/webs"; import "@pnp/sp/lists/web"; -const sp = spfi("{tenant url}").using(SPFx(this.context)); +const sp = spfi(...); const r = await sp.web.lists.getByTitle("TaxonomyList").getItemsByCAMLQuery({ ViewXml: `Term 2`, @@ -168,7 +168,7 @@ const r = await sp.web.lists.getByTitle("TaxonomyList").getItemsByCAMLQuery({ The PublishingPageImage and some other publishing-related fields aren't stored in normal fields, rather in the MetaInfo field. To get these values you need to use the technique shown below, and originally outlined in [this thread](https://github.com/SharePoint/PnP-JS-Core/issues/178). Note that a lot of information can be stored in this field so will pull back potentially a significant amount of data, so limit the rows as possible to aid performance. ```TypeScript -import { spfi, SPFx } from "@pnp/sp"; +import { spfi } from "@pnp/sp"; import "@pnp/sp/webs"; import "@pnp/sp/lists"; import "@pnp/sp/items"; @@ -207,13 +207,13 @@ catch (e) { There are several ways to add items to a list. The simplest just uses the _add_ method of the items collection passing in the properties as a plain object. ```TypeScript -import { spfi, SPFx } from "@pnp/sp"; +import { spfi } from "@pnp/sp"; import "@pnp/sp/webs"; import "@pnp/sp/lists"; import "@pnp/sp/items"; import { IItemAddResult } from "@pnp/sp/items"; -const sp = spfi("{tenant url}").using(SPFx(this.context)); +const sp = spfi(...); // add an item to the list const iar: IItemAddResult = await sp.web.lists.getByTitle("My List").items.add({ @@ -229,12 +229,12 @@ console.log(iar); You can also set the content type id when you create an item as shown in the example below. For more information on content type IDs reference the [Microsoft Documentation](https://docs.microsoft.com/en-us/previous-versions/office/developer/sharepoint-2010/aa543822(v=office.14)). While this documentation references SharePoint 2010 the structure of the IDs has not changed. ```TypeScript -import { spfi, SPFx } from "@pnp/sp"; +import { spfi } from "@pnp/sp"; import "@pnp/sp/webs"; import "@pnp/sp/lists"; import "@pnp/sp/items"; -const sp = spfi("{tenant url}").using(SPFx(this.context)); +const sp = spfi(...); await sp.web.lists.getById("4D5A36EA-6E84-4160-8458-65C436DB765C").items.add({ Title: "Test 1", @@ -249,13 +249,13 @@ There are two types of user fields, those that allow a single value and those th Next, you need to remember there are two types of user fields, those that take a single value and those that allow multiple - these are updated in different ways. For single value user fields you supply just the user's id. For multiple value fields, you need to supply an object with a "results" property and an array. Examples for both are shown below. ```TypeScript -import { spfi, SPFx } from "@pnp/sp"; +import { spfi } from "@pnp/sp"; import "@pnp/sp/webs"; import "@pnp/sp/lists"; import "@pnp/sp/items"; import { getGUID } from "@pnp/core"; -const sp = spfi("{tenant url}").using(SPFx(this.context)); +const sp = spfi(...); const i = await sp.web.lists.getByTitle("PeopleFields").items.add({ Title: getGUID(), @@ -269,12 +269,12 @@ console.log(i); If you want to update or add user field values when using **validateUpdateListItem** you need to use the form shown below. You can specify multiple values in the array. ```TypeScript -import { spfi, SPFx } from "@pnp/sp"; +import { spfi } from "@pnp/sp"; import "@pnp/sp/webs"; import "@pnp/sp/lists"; import "@pnp/sp/items"; -const sp = spfi("{tenant url}").using(SPFx(this.context)); +const sp = spfi(...); const result = await sp.web.lists.getByTitle("UserFieldList").items.getById(1).validateUpdateListItem([{ FieldName: "UserField", @@ -297,13 +297,13 @@ What is said for User Fields is, in general, relevant to Lookup Fields: - Numeric Ids for lookups' items should be passed as values ```TypeScript -import { spfi, SPFx } from "@pnp/sp"; +import { spfi } from "@pnp/sp"; import "@pnp/sp/webs"; import "@pnp/sp/lists"; import "@pnp/sp/items"; import { getGUID } from "@pnp/core"; -const sp = spfi("{tenant url}").using(SPFx(this.context)); +const sp = spfi(...); await sp.web.lists.getByTitle("LookupFields").items.add({ Title: getGUID(), @@ -315,12 +315,12 @@ await sp.web.lists.getByTitle("LookupFields").items.add({ ### Add Multiple Items ```TypeScript -import { spfi, SPFx } from "@pnp/sp"; +import { spfi } from "@pnp/sp"; import "@pnp/sp/webs"; import "@pnp/sp/lists"; import "@pnp/sp/items"; -const sp = spfi("{tenant url}").using(SPFx(this.context)); +const sp = spfi(...); const list = sp.web.lists.getByTitle("rapidadd"); @@ -345,12 +345,12 @@ console.log("Done"); The update method is very similar to the add method in that it takes a plain object representing the fields to update. The property names are the internal names of the fields. If you aren't sure you can always do a get request for an item in the list and see the field names that come back - you would use these same names to update the item. ```TypeScript -import { spfi, SPFx } from "@pnp/sp"; +import { spfi } from "@pnp/sp"; import "@pnp/sp/webs"; import "@pnp/sp/lists"; import "@pnp/sp/items"; -const sp = spfi("{tenant url}").using(SPFx(this.context)); +const sp = spfi(...); const list = sp.web.lists.getByTitle("MyList"); @@ -365,12 +365,12 @@ console.log(i); ### Getting and updating a collection using filter ```TypeScript -import { spfi, SPFx } from "@pnp/sp"; +import { spfi } from "@pnp/sp"; import "@pnp/sp/webs"; import "@pnp/sp/lists"; import "@pnp/sp/items"; -const sp = spfi("{tenant url}").using(SPFx(this.context)); +const sp = spfi(...); // you are getting back a collection here const items: any[] = await sp.web.lists.getByTitle("MyList").items.top(1).filter("Title eq 'A Title'")(); @@ -390,12 +390,12 @@ if (items.length > 0) { This approach avoids multiple calls for the same list's entity type name. ```TypeScript -import { spfi, SPFx } from "@pnp/sp"; +import { spfi } from "@pnp/sp"; import "@pnp/sp/webs"; import "@pnp/sp/lists"; import "@pnp/sp/items"; -const sp = spfi("{tenant url}").using(SPFx(this.context)); +const sp = spfi(...); const list = sp.web.lists.getByTitle("rapidupdate"); @@ -424,13 +424,13 @@ _Based on [this excellent article](https://www.aerieconsulting.com/blog/update-u As he says you must update a hidden field to get this to work via REST. My meta data field accepting multiple values is called "MultiMetaData". ```TypeScript -import { spfi, SPFx } from "@pnp/sp"; +import { spfi } from "@pnp/sp"; import "@pnp/sp/webs"; import "@pnp/sp/lists"; import "@pnp/sp/items"; import "@pnp/sp/fields"; -const sp = spfi("{tenant url}").using(SPFx(this.context)); +const sp = spfi(...); // first we need to get the hidden field's internal name. // The Title of that hidden field is, in my case and in the linked article just the visible field name with "_0" appended. @@ -468,12 +468,12 @@ const update = await sp.web.lists.getByTitle("Price").items.getById(7).select('* To send an item to the recycle bin use recycle. ```TypeScript -import { spfi, SPFx } from "@pnp/sp"; +import { spfi } from "@pnp/sp"; import "@pnp/sp/webs"; import "@pnp/sp/lists"; import "@pnp/sp/items"; -const sp = spfi("{tenant url}").using(SPFx(this.context)); +const sp = spfi(...); const list = sp.web.lists.getByTitle("MyList"); @@ -485,12 +485,12 @@ const recycleBinIdentifier = await list.items.getById(1).recycle(); Delete is as simple as calling the .delete method. It optionally takes an eTag if you need to manage concurrency. ```TypeScript -import { spfi, SPFx } from "@pnp/sp"; +import { spfi } from "@pnp/sp"; import "@pnp/sp/webs"; import "@pnp/sp/lists"; import "@pnp/sp/items"; -const sp = spfi("{tenant url}").using(SPFx(this.context)); +const sp = spfi(...); const list = sp.web.lists.getByTitle("MyList"); @@ -502,12 +502,12 @@ await list.items.getById(1).delete(); Deletes the item object with options. ```TypeScript -import { spfi, SPFx } from "@pnp/sp"; +import { spfi } from "@pnp/sp"; import "@pnp/sp/webs"; import "@pnp/sp/lists"; import "@pnp/sp/items"; -const sp = spfi("{tenant url}").using(SPFx(this.context)); +const sp = spfi(...); const list = sp.web.lists.getByTitle("MyList"); @@ -526,13 +526,13 @@ Field's `EntityPropertyName` value should be used. The easiest way to get know EntityPropertyName is to use the following snippet: ```TypeScript -import { spfi, SPFx } from "@pnp/sp"; +import { spfi } from "@pnp/sp"; import "@pnp/sp/webs"; import "@pnp/sp/lists"; import "@pnp/sp/items"; import "@pnp/sp/fields"; -const sp = spfi("{tenant url}").using(SPFx(this.context)); +const sp = spfi(...); const response = await sp.web.lists @@ -557,11 +557,11 @@ Lookup fields' names should be ended with additional `Id` suffix. E.g. for `Edit Gets information about an item, including details about the parent list, parent list root folder, and parent web. ```TypeScript -import { spfi, SPFx } from "@pnp/sp"; +import { spfi } from "@pnp/sp"; import "@pnp/sp/webs"; import "@pnp/sp/items"; -const sp = spfi("{tenant url}").using(SPFx(this.context)); +const sp = spfi(...); const item: any = await sp.web.lists.getByTitle("My List").items.getById(1)(); await item.getParentInfos(); diff --git a/docs/sp/lists.md b/docs/sp/lists.md index 8169b1556..a343a5f5c 100644 --- a/docs/sp/lists.md +++ b/docs/sp/lists.md @@ -11,11 +11,11 @@ Lists in SharePoint are collections of information built in a structural way usi Gets a list from the collection by id (guid). Note that the library will handle a guid formatted with curly braces (i.e. '{03b05ff4-d95d-45ed-841d-3855f77a2483}') as well as without curly braces (i.e. '03b05ff4-d95d-45ed-841d-3855f77a2483'). The Id parameter is also case insensitive. ```TypeScript -import { spfi, SPFx } from "@pnp/sp"; +import { spfi } from "@pnp/sp"; import "@pnp/sp/webs"; import "@pnp/sp/lists"; -const sp = spfi("{tenant url}").using(SPFx(this.context)); +const sp = spfi(...); // get the list by Id const list = sp.web.lists.getById("03b05ff4-d95d-45ed-841d-3855f77a2483"); @@ -32,11 +32,11 @@ console.log(r.Title); You can also get a list from the collection by title. ```TypeScript -import { spfi, SPFx } from "@pnp/sp"; +import { spfi } from "@pnp/sp"; import "@pnp/sp/webs"; import "@pnp/sp/lists"; -const sp = spfi("{tenant url}").using(SPFx(this.context)); +const sp = spfi(...); // get the default document library 'Documents' const list = sp.web.lists.getByTitle("Documents"); @@ -53,11 +53,11 @@ console.log(r.Id); You can add a list to the web's list collection using the .add-method. To invoke this method in its most simple form, you can provide only a title as a parameter. This will result in a standard out of the box list with all default settings, and the title you provide. ```TypeScript -import { spfi, SPFx } from "@pnp/sp"; +import { spfi } from "@pnp/sp"; import "@pnp/sp/webs"; import "@pnp/sp/lists"; -const sp = spfi("{tenant url}").using(SPFx(this.context)); +const sp = spfi(...); // create a new list, passing only the title const listAddResult = await sp.web.lists.add("My new list"); @@ -90,11 +90,11 @@ Ensures that the specified list exists in the collection (note: this method not ![Batching Not Supported Banner](https://img.shields.io/badge/Batching%20Not%20Supported-important.svg) ```TypeScript -import { spfi, SPFx } from "@pnp/sp"; +import { spfi } from "@pnp/sp"; import "@pnp/sp/webs"; import "@pnp/sp/lists"; -const sp = spfi("{tenant url}").using(SPFx(this.context)); +const sp = spfi(...); // ensure that a list exists. If it doesn't it will be created with the provided title (the rest of the settings will be default): const listEnsureResult = await sp.web.lists.ensure("My List"); @@ -115,11 +115,11 @@ console.log(r.Id); If the list already exists, the other settings you provide will be used to update the existing list. ```TypeScript -import { spfi, SPFx } from "@pnp/sp"; +import { spfi } from "@pnp/sp"; import "@pnp/sp/webs"; import "@pnp/sp/lists"; -const sp = spfi("{tenant url}").using(SPFx(this.context)); +const sp = spfi(...); // add a new list to the lists collection of the web sp.web.lists.add("My List 2").then(async () => { @@ -139,11 +139,11 @@ console.log(r.Description); Gets a list that is the default asset location for images or other files, which the users upload to their wiki pages. ```TypeScript -import { spfi, SPFx } from "@pnp/sp"; +import { spfi } from "@pnp/sp"; import "@pnp/sp/webs"; import "@pnp/sp/lists"; -const sp = spfi("{tenant url}").using(SPFx(this.context)); +const sp = spfi(...); // get Site Assets library const siteAssetsList = await sp.web.lists.ensureSiteAssetsLibrary(); @@ -159,11 +159,11 @@ console.log(r.Title); Gets a list that is the default location for wiki pages. ```TypeScript -import { spfi, SPFx } from "@pnp/sp"; +import { spfi } from "@pnp/sp"; import "@pnp/sp/webs"; import "@pnp/sp/lists"; -const sp = spfi("{tenant url}").using(SPFx(this.context)); +const sp = spfi(...); // get Site Pages library const siteAssetsList = await sp.web.lists.ensureSitePagesLibrary(); @@ -401,11 +401,11 @@ console.log(entityTypeFullName); ### Add a list item using path (folder), validation and set field values ```TypeScript -import { spfi, SPFx } from "@pnp/sp"; +import { spfi } from "@pnp/sp"; import "@pnp/sp/webs"; import "@pnp/sp/lists"; -const sp = spfi("{tenant url}").using(SPFx(this.context)); +const sp = spfi(...); const list = await sp.webs.lists.getByTitle("MyList").select("Title", "ParentWebUrl")(); const formValues: IListItemFormUpdateValue[] = [ @@ -426,11 +426,11 @@ list.addValidateUpdateItemUsingPath(formValues,`${list.ParentWebUrl}/Lists/${lis Get all content types for a list ```TypeScript -import { spfi, SPFx } from "@pnp/sp"; +import { spfi } from "@pnp/sp"; import "@pnp/sp/webs"; import "@pnp/sp/lists"; -const sp = spfi("{tenant url}").using(SPFx(this.context)); +const sp = spfi(...); import "@pnp/sp/content-types/list"; const list = sp.web.lists.getByTitle("Documents"); @@ -450,11 +450,11 @@ const r = await list.contentTypes(); Get all the fields for a list ```TypeScript -import { spfi, SPFx } from "@pnp/sp"; +import { spfi } from "@pnp/sp"; import "@pnp/sp/webs"; import "@pnp/sp/lists"; -const sp = spfi("{tenant url}").using(SPFx(this.context)); +const sp = spfi(...); import "@pnp/sp/fields/list"; const list = sp.web.lists.getByTitle("Documents"); @@ -464,11 +464,11 @@ const r = await list.fields(); Add a field to the site, then add the site field to a list ```TypeScript -import { spfi, SPFx } from "@pnp/sp"; +import { spfi } from "@pnp/sp"; import "@pnp/sp/webs"; import "@pnp/sp/lists"; -const sp = spfi("{tenant url}").using(SPFx(this.context)); +const sp = spfi(...); const fld = await sp.site.rootWeb.fields.addText("MyField"); await sp.web.lists.getByTitle("MyList").fields.createFieldAsXml(fld.data.SchemaXml); ``` @@ -478,12 +478,12 @@ await sp.web.lists.getByTitle("MyList").fields.createFieldAsXml(fld.data.SchemaX Get the root folder of a list. ```TypeScript -import { spfi, SPFx } from "@pnp/sp"; +import { spfi } from "@pnp/sp"; import "@pnp/sp/webs"; import "@pnp/sp/lists"; import "@pnp/sp/folders/list"; -const sp = spfi("{tenant url}").using(SPFx(this.context)); +const sp = spfi(...); const list = sp.web.lists.getByTitle("Documents"); const r = await list.rootFolder(); @@ -512,12 +512,12 @@ const r = await list.items(); Get the default view of the list ```TypeScript -import { spfi, SPFx } from "@pnp/sp"; +import { spfi } from "@pnp/sp"; import "@pnp/sp/webs"; import "@pnp/sp/lists"; import "@pnp/sp/views/list"; -const sp = spfi("{tenant url}").using(SPFx(this.context)); +const sp = spfi(...); const list = sp.web.lists.getByTitle("Documents"); const views = await list.views(); const defaultView = await list.defaultView(); @@ -544,12 +544,12 @@ For more information on how to call security methods for lists, please refer to Get all subscriptions on the list ```TypeScript -import { spfi, SPFx } from "@pnp/sp"; +import { spfi } from "@pnp/sp"; import "@pnp/sp/webs"; import "@pnp/sp/lists"; import "@pnp/sp/subscriptions/list"; -const sp = spfi("{tenant url}").using(SPFx(this.context)); +const sp = spfi(...); const list = sp.web.lists.getByTitle("Documents"); const subscriptions = await list.subscriptions(); ``` @@ -559,12 +559,12 @@ const subscriptions = await list.subscriptions(); Get a collection of the list's user custom actions. ```TypeScript -import { spfi, SPFx } from "@pnp/sp"; +import { spfi } from "@pnp/sp"; import "@pnp/sp/webs"; import "@pnp/sp/lists"; import "@pnp/sp/user-custom-actions/web" -const sp = spfi("{tenant url}").using(SPFx(this.context)); +const sp = spfi(...); const list = sp.web.lists.getByTitle("Documents"); const r = await list.userCustomActions(); ``` @@ -574,11 +574,11 @@ const r = await list.userCustomActions(); Gets information about an list, including details about the parent list root folder, and parent web. ```TypeScript -import { spfi, SPFx } from "@pnp/sp"; +import { spfi } from "@pnp/sp"; import "@pnp/sp/webs"; import "@pnp/sp/lists"; -const sp = spfi("{tenant url}").using(SPFx(this.context)); +const sp = spfi(...); const list = sp.web.lists.getByTitle("Documents"); await list.getParentInfos(); diff --git a/docs/sp/navigation.md b/docs/sp/navigation.md index a315fcd39..53730cf3e 100644 --- a/docs/sp/navigation.md +++ b/docs/sp/navigation.md @@ -17,10 +17,10 @@ NOTE: the , separator can be escaped using the \ as escape character as done in * property3,containingcomma ```TypeScript -import { spfi, SPFx } from "@pnp/sp"; +import { spfi } from "@pnp/sp"; import "@pnp/sp/navigation"; -const sp = spfi("{tenant url}").using(SPFx(this.context)); +const sp = spfi(...); // Will return a menu state of the default SiteMapProvider 'SPSiteMapProvider' where the dump starts a the RootNode (within the site) with a depth of 10 levels. const state = await sp.navigation.getMenuState(); @@ -37,10 +37,10 @@ const state3 = await sp.navigation.getMenuState(null, 5, "CurrentNavSiteMapProvi Tries to get a SiteMapNode.Key for a given URL within a site collection. If the SiteMapNode cannot be found an Exception is returned. The method is using SiteMapProvider.FindSiteMapNodeFromKey(string rawUrl) to lookup the SiteMapNode. Depending on the actual implementation of FindSiteMapNodeFromKey the matching can differ for different SiteMapProviders. ```TypeScript -import { spfi, SPFx } from "@pnp/sp"; +import { spfi } from "@pnp/sp"; import "@pnp/sp/navigation"; -const sp = spfi("{tenant url}").using(SPFx(this.context)); +const sp = spfi(...); const key = await sp.navigation.getMenuNodeKey("/sites/dev/Lists/SPPnPJSExampleList/AllItems.aspx"); ``` @@ -61,11 +61,11 @@ The navigation object contains two properties "quicklaunch" and "topnavigationba ### Get navigation ```TypeScript -import { spfi, SPFx } from "@pnp/sp"; +import { spfi } from "@pnp/sp"; import "@pnp/sp/webs"; import "@pnp/sp/navigation"; -const sp = spfi("{tenant url}").using(SPFx(this.context)); +const sp = spfi(...); const top = await sp.web.navigation.topNavigationBar(); const quick = await sp.web.navigation.quicklaunch(); @@ -74,11 +74,11 @@ const quick = await sp.web.navigation.quicklaunch(); For the following examples we will refer to a variable named "nav" that is understood to be one of topNavigationBar or quicklaunch: ```TypeScript -import { spfi, SPFx } from "@pnp/sp"; +import { spfi } from "@pnp/sp"; import "@pnp/sp/webs"; import "@pnp/sp/navigation"; -const sp = spfi("{tenant url}").using(SPFx(this.context)); +const sp = spfi(...); // note we are just getting a ref to the nav object, not executing a request const nav = sp.web.navigation.topNavigationBar; // -- OR -- diff --git a/docs/sp/permissions.md b/docs/sp/permissions.md index e0a61d0e1..2a96a0b12 100644 --- a/docs/sp/permissions.md +++ b/docs/sp/permissions.md @@ -9,11 +9,11 @@ Permissions in SharePoint are assigned to the set of securable objects which inc This gets a collection of all the role assignments on a given securable. The property returns a RoleAssignments collection which supports the OData collection operators. ```TypeScript -import { spfi, SPFx } from "@pnp/sp"; +import { spfi } from "@pnp/sp"; import "@pnp/sp/web"; import "@pnp/sp/security"; -const sp = spfi("{tenant url}").using(SPFx(this.context)); +const sp = spfi(...); const roles = await sp.web.roleAssignments(); ``` @@ -23,11 +23,11 @@ const roles = await sp.web.roleAssignments(); This method can be used to find the securable parent up the hierarchy that has unique permissions. If everything inherits permissions this will be the Site. If a sub web has unique permissions it will be the web, and so on. ```TypeScript -import { spfi, SPFx } from "@pnp/sp"; +import { spfi } from "@pnp/sp"; import "@pnp/sp/web"; import "@pnp/sp/security"; -const sp = spfi("{tenant url}").using(SPFx(this.context)); +const sp = spfi(...); const obj = await sp.web.firstUniqueAncestorSecurableObject(); ``` @@ -37,11 +37,11 @@ const obj = await sp.web.firstUniqueAncestorSecurableObject(); This method returns the BasePermissions for a given user or the current user. This value contains the High and Low values for a user on the securable you have queried. ```TypeScript -import { spfi, SPFx } from "@pnp/sp"; +import { spfi } from "@pnp/sp"; import "@pnp/sp/web"; import "@pnp/sp/security"; -const sp = spfi("{tenant url}").using(SPFx(this.context)); +const sp = spfi(...); const perms = await sp.web.getUserEffectivePermissions("i:0#.f|membership|user@site.com"); @@ -53,11 +53,11 @@ const perms2 = await sp.web.getCurrentUserEffectivePermissions(); Because the High and Low values in the BasePermission don't obviously mean anything you can use these methods along with the PermissionKind enumeration to check actual rights on the securable. ```TypeScript -import { spfi, SPFx } from "@pnp/sp"; +import { spfi } from "@pnp/sp"; import "@pnp/sp/web"; import { PermissionKind } from "@pnp/sp/security"; -const sp = spfi("{tenant url}").using(SPFx(this.context)); +const sp = spfi(...); const perms = await sp.web.userHasPermissions("i:0#.f|membership|user@site.com", PermissionKind.ApproveItems); @@ -69,11 +69,11 @@ const perms2 = await sp.web.currentUserHasPermissions(PermissionKind.ApproveItem If you need to check multiple permissions it can be more efficient to get the BasePermissions once and then use the hasPermissions method to check them as shown below. ```TypeScript -import { spfi, SPFx } from "@pnp/sp"; +import { spfi } from "@pnp/sp"; import "@pnp/sp/web"; import { PermissionKind } from "@pnp/sp/security"; -const sp = spfi("{tenant url}").using(SPFx(this.context)); +const sp = spfi(...); const perms = await sp.web.getCurrentUserEffectivePermissions(); if (sp.web.hasPermissions(perms, PermissionKind.AddListItems) && sp.web.hasPermissions(perms, PermissionKind.DeleteVersions)) { diff --git a/docs/sp/profiles.md b/docs/sp/profiles.md index 2054325c2..18f105d20 100644 --- a/docs/sp/profiles.md +++ b/docs/sp/profiles.md @@ -7,7 +7,7 @@ The profile services allows you to work with the SharePoint User Profile Store. Profiles is accessed directly from the root sp object. ```typescript -import { spfi, SPFx } from "@pnp/sp"; +import { spfi } from "@pnp/sp"; import "@pnp/sp/profiles"; ``` @@ -18,7 +18,7 @@ getEditProfileLink(): Promise ``` ```typescript -const sp = spfi("{tenant url}").using(SPFx(this.context)); +const sp = spfi(...); const editProfileLink = await sp.profiles.getEditProfileLink(); ``` @@ -31,7 +31,7 @@ getIsMyPeopleListPublic(): Promise ``` ```typescript -const sp = spfi("{tenant url}").using(SPFx(this.context)); +const sp = spfi(...); const isPublic = await sp.profiles.getIsMyPeopleListPublic(); ``` @@ -44,7 +44,7 @@ amIFollowedBy(loginName: string): Promise ``` ```typescript -const sp = spfi("{tenant url}").using(SPFx(this.context)); +const sp = spfi(...); const loginName = "i:0#.f|membership|testuser@mytenant.onmicrosoft.com"; const isFollowedBy = await sp.profiles.amIFollowedBy(loginName); ``` @@ -58,7 +58,7 @@ amIFollowing(loginName: string): Promise ``` ```typescript -const sp = spfi("{tenant url}").using(SPFx(this.context)); +const sp = spfi(...); const loginName = "i:0#.f|membership|testuser@mytenant.onmicrosoft.com"; const following = await sp.profiles.amIFollowing(loginName); ``` @@ -72,7 +72,7 @@ getFollowedTags(maxCount = 20): Promise ``` ```typescript -const sp = spfi("{tenant url}").using(SPFx(this.context)); +const sp = spfi(...); const tags = await sp.profiles.getFollowedTags(); ``` @@ -85,7 +85,7 @@ getFollowersFor(loginName: string): Promise ``` ```typescript -const sp = spfi("{tenant url}").using(SPFx(this.context)); +const sp = spfi(...); const loginName = "i:0#.f|membership|testuser@mytenant.onmicrosoft.com"; const followers = await sp.profiles.getFollowersFor(loginName); followers.forEach((value) => { @@ -102,7 +102,7 @@ myFollowers(): ISPCollection ``` ```typescript -const sp = spfi("{tenant url}").using(SPFx(this.context)); +const sp = spfi(...); const folowers = await sp.profiles.myFollowers(); ``` @@ -115,7 +115,7 @@ myProperties(): ISPInstance ``` ```typescript -const sp = spfi("{tenant url}").using(SPFx(this.context)); +const sp = spfi(...); const profile = await sp.profiles.myProperties(); console.log(profile.DisplayName); console.log(profile.Email); @@ -134,7 +134,7 @@ console.log("Account Name: " + profile.userProperties.AccountName); ```TypeScript // you can also select properties to return before -const sp = spfi("{tenant url}").using(SPFx(this.context)); +const sp = spfi(...); const profile = await sp.profiles.myProperties.select("Title", "Email")(); console.log(profile.Email); console.log(profile.Title); @@ -147,7 +147,7 @@ getPeopleFollowedBy(loginName: string): Promise ``` ```typescript -const sp = spfi("{tenant url}").using(SPFx(this.context)); +const sp = spfi(...); const loginName = "i:0#.f|membership|testuser@mytenant.onmicrosoft.com"; const folowers = await sp.profiles.getFollowersFor(loginName); followers.forEach((value) => { @@ -162,7 +162,7 @@ getPropertiesFor(loginName: string): Promise ``` ```typescript -const sp = spfi("{tenant url}").using(SPFx(this.context)); +const sp = spfi(...); const loginName = "i:0#.f|membership|testuser@mytenant.onmicrosoft.com"; const profile = await sp.profiles.getPropertiesFor(loginName); console.log(profile.DisplayName); @@ -190,7 +190,7 @@ trendingTags(): Promise ``` ```typescript -const sp = spfi("{tenant url}").using(SPFx(this.context)); +const sp = spfi(...); const tags = await sp.profiles.trendingTags(); tags.Items.forEach((tag) => { ... @@ -204,7 +204,7 @@ getUserProfilePropertyFor(loginName: string, propertyName: string): Promise ``` ```typescript -const sp = spfi("{tenant url}").using(SPFx(this.context)); +const sp = spfi(...); const loginName = "i:0#.f|membership|testuser@mytenant.onmicrosoft.com"; await sp.profiles.hideSuggestion(loginName); ``` @@ -235,7 +235,7 @@ isFollowing(follower: string, followee: string): Promise ``` ```typescript -const sp = spfi("{tenant url}").using(SPFx(this.context)); +const sp = spfi(...); const follower = "i:0#.f|membership|testuser@mytenant.onmicrosoft.com"; const followee = "i:0#.f|membership|testuser2@mytenant.onmicrosoft.com"; const isFollowing = await sp.profiles.isFollowing(follower, followee); @@ -253,14 +253,14 @@ setMyProfilePic(profilePicSource: Blob): Promise ``` ```typescript -import { spfi, SPFx } from "@pnp/sp"; +import { spfi } from "@pnp/sp"; import "@pnp/sp/webs"; import "@pnp/sp/lists/web"; import "@pnp/sp/profiles"; import "@pnp/sp/folders"; import "@pnp/sp/files"; -const sp = spfi("{tenant url}").using(SPFx(this.context)); +const sp = spfi(...); // get the blob object through a request or from a file input const blob = await sp.web.lists.getByTitle("Documents").rootFolder.files.getByName("profile.jpg").getBlob(); @@ -279,7 +279,7 @@ setSingleValueProfileProperty(accountName: string, propertyName: string, propert ``` ```typescript -const sp = spfi("{tenant url}").using(SPFx(this.context)); +const sp = spfi(...); const loginName = "i:0#.f|membership|testuser@mytenant.onmicrosoft.com"; await sp.profiles.setSingleValueProfileProperty(loginName, "CellPhone", "(123) 555-1212"); ``` @@ -295,7 +295,7 @@ setMultiValuedProfileProperty(accountName: string, propertyName: string, propert ``` ```typescript -const sp = spfi("{tenant url}").using(SPFx(this.context)); +const sp = spfi(...); const loginName = "i:0#.f|membership|testuser@mytenant.onmicrosoft.com"; const propertyName = "SPS-Skills"; const propertyValues = ["SharePoint", "Office 365", "Architecture", "Azure"]; @@ -319,7 +319,7 @@ createPersonalSiteEnqueueBulk(...emails: string[]): Promise ``` ```typescript -const sp = spfi("{tenant url}").using(SPFx(this.context)); +const sp = spfi(...); let userEmails: string[] = ["testuser1@mytenant.onmicrosoft.com", "testuser2@mytenant.onmicrosoft.com"]; await sp.profiles.createPersonalSiteEnqueueBulk(userEmails); ``` @@ -331,7 +331,7 @@ ownerUserProfile(): Promise ``` ```typescript -const sp = spfi("{tenant url}").using(SPFx(this.context)); +const sp = spfi(...); const profile = await sp.profiles.ownerUserProfile(); ``` @@ -342,7 +342,7 @@ userProfile(): Promise ``` ```typescript -const sp = spfi("{tenant url}").using(SPFx(this.context)); +const sp = spfi(...); const profile = await sp.profiles.userProfile(); ``` @@ -353,7 +353,7 @@ createPersonalSite(interactiveRequest = false): Promise ``` ```typescript -const sp = spfi("{tenant url}").using(SPFx(this.context)); +const sp = spfi(...); await sp.profiles.createPersonalSite(); ``` @@ -366,7 +366,7 @@ shareAllSocialData(share: boolean): Promise ``` ```typescript -const sp = spfi("{tenant url}").using(SPFx(this.context)); +const sp = spfi(...); await sp.profiles.shareAllSocialData(true); ``` @@ -379,7 +379,7 @@ clientPeoplePickerResolveUser(queryParams: IClientPeoplePickerQueryParameters): ``` ```typescript -const sp = spfi("{tenant url}").using(SPFx(this.context)); +const sp = spfi(...); const result = await sp.profiles.clientPeoplePickerSearchUser({ AllowEmailAddresses: true, AllowMultipleEntities: false, @@ -397,7 +397,7 @@ clientPeoplePickerSearchUser(queryParams: IClientPeoplePickerQueryParameters): P ``` ```typescript -const sp = spfi("{tenant url}").using(SPFx(this.context)); +const sp = spfi(...); const result = await sp.profiles.clientPeoplePickerSearchUser({ AllowEmailAddresses: true, AllowMultipleEntities: false, diff --git a/docs/sp/regional-settings.md b/docs/sp/regional-settings.md index 2794d1ed3..41beed815 100644 --- a/docs/sp/regional-settings.md +++ b/docs/sp/regional-settings.md @@ -7,11 +7,11 @@ The regional settings module helps with managing dates and times across various [![Invokable Banner](https://img.shields.io/badge/Invokable-informational.svg)](../concepts/invokable.md) [![Selective Imports Banner](https://img.shields.io/badge/Selective%20Imports-informational.svg)](../concepts/selective-imports.md) ```TypeScript -import { spfi, SPFx } from "@pnp/sp"; +import { spfi } from "@pnp/sp"; import "@pnp/sp/webs"; import "@pnp/sp/regional-settings/web"; -const sp = spfi("{tenant url}").using(SPFx(this.context)); +const sp = spfi(...); // get all the web's regional settings const s = await sp.web.regionalSettings(); @@ -25,11 +25,11 @@ const s2 = await sp.web.regionalSettings.select("DecimalSeparator", "ListSeparat You can get a list of the installed languages in the web. ```TypeScript -import { spfi, SPFx } from "@pnp/sp"; +import { spfi } from "@pnp/sp"; import "@pnp/sp/webs"; import "@pnp/sp/regional-settings/web"; -const sp = spfi("{tenant url}").using(SPFx(this.context)); +const sp = spfi(...); const s = await sp.web.regionalSettings.getInstalledLanguages(); ``` @@ -41,11 +41,11 @@ const s = await sp.web.regionalSettings.getInstalledLanguages(); You can also get information about the selected timezone in the web and all of the defined timezones. ```TypeScript -import { spfi, SPFx } from "@pnp/sp"; +import { spfi } from "@pnp/sp"; import "@pnp/sp/webs"; import "@pnp/sp/regional-settings/web"; -const sp = spfi("{tenant url}").using(SPFx(this.context)); +const sp = spfi(...); // get the web's configured timezone const s = await sp.web.regionalSettings.timeZone(); @@ -74,11 +74,11 @@ const s7 = await sp.web.regionalSettings.timeZone.utcToLocalTime(new Date(2019, Some objects allow you to read language specific title information as shown in the following sample. This applies to Web, List, Field, Content Type, and User Custom Actions. ```TypeScript -import { spfi, SPFx } from "@pnp/sp"; +import { spfi } from "@pnp/sp"; import "@pnp/sp/webs"; import "@pnp/sp/regional-settings"; -const sp = spfi("{tenant url}").using(SPFx(this.context)); +const sp = spfi(...); // // The below methods appears on diff --git a/docs/sp/related-items.md b/docs/sp/related-items.md index b63871eef..4f1e37368 100644 --- a/docs/sp/related-items.md +++ b/docs/sp/related-items.md @@ -16,7 +16,7 @@ import "@pnp/sp/files/list"; import { IList } from "@pnp/sp/lists"; import { getRandomString } from "@pnp/core"; -const sp = spfi("{tenant url}").using(SPFx(this.context)); +const sp = spfi(...); // setup some lists (or just use existing ones this is just to show the complete process) // we need two lists to use for creating related items, they need to use template 107 (task list) diff --git a/docs/sp/search.md b/docs/sp/search.md index a717025fc..b169c0c46 100644 --- a/docs/sp/search.md +++ b/docs/sp/search.md @@ -9,11 +9,11 @@ Using search you can access content throughout your organization in a secure and Search is accessed directly from the root sp object and can take either a string representing the query text, a plain object matching the ISearchQuery interface, or a SearchQueryBuilder instance. ```TypeScript -import { spfi, SPFx } from "@pnp/sp"; +import { spfi } from "@pnp/sp"; import "@pnp/sp/search"; import { ISearchQuery, SearchResults, SearchQueryBuilder } from "@pnp/sp/search"; -const sp = spfi("{tenant url}").using(SPFx(this.context)); +const sp = spfi(...); // text search using SharePoint default values for other parameters const results: SearchResults = await sp.search("test"); @@ -48,11 +48,11 @@ console.log(results3.PrimarySearchResults); You can use the searchWithCaching method to enable cache support for your search results this option works with any of the options for providing a query, just replace "search" with "searchWithCaching" in your method chain and gain all the benefits of caching. The second parameter is optional and allows you to specify the cache options ```TypeScript -import { spfi, SPFx } from "@pnp/sp"; +import { spfi } from "@pnp/sp"; import "@pnp/sp/search"; import { ISearchQuery, SearchResults, SearchQueryBuilder } from "@pnp/sp/search"; -const sp = spfi("{tenant url}").using(SPFx(this.context)); +const sp = spfi(...); sp.searchWithCaching({ Querytext: "test", @@ -79,11 +79,11 @@ console.log(results2.TotalRows); Paging is controlled by a start row and page size parameter. You can specify both arguments in your initial query however you can use the getPage method to jump to any page. The second parameter page size is optional and will use the previous RowLimit or default to 10. ```TypeScript -import { spfi, SPFx } from "@pnp/sp"; +import { spfi } from "@pnp/sp"; import "@pnp/sp/search"; import { SearchResults, SearchQueryBuilder } from "@pnp/sp/search"; -const sp = spfi("{tenant url}").using(SPFx(this.context)); +const sp = spfi(...); // this will hold our current results let currentResults: SearchResults = null; @@ -120,11 +120,11 @@ async function prev() { The SearchQueryBuilder allows you to build your queries in a fluent manner. It also accepts constructor arguments for query text and a base query plain object, should you have a shared configuration for queries in an application you can define them once. The methods and properties match those on the SearchQuery interface. Boolean properties add the flag to the query while methods require that you supply one or more arguments. Also arguments supplied later in the chain will overwrite previous values. ```TypeScript -import { spfi, SPFx } from "@pnp/sp"; +import { spfi } from "@pnp/sp"; import "@pnp/sp/search"; import { SearchQueryBuilder, SearchResults, ISearchQuery } from "@pnp/sp/search"; -const sp = spfi("{tenant url}").using(SPFx(this.context)); +const sp = spfi(...); // basic usage let q = SearchQueryBuilder().text("test").rowLimit(4).enablePhonetic; @@ -155,11 +155,11 @@ const results3 = sp.search(q4); Search suggest works in much the same way as search, except against the suggest end point. It takes a string or a plain object that matches ISuggestQuery. ```TypeScript -import { spfi, SPFx } from "@pnp/sp"; +import { spfi } from "@pnp/sp"; import "@pnp/sp/search"; import { ISuggestQuery, ISuggestResult } from "@pnp/sp/search"; -const sp = spfi("{tenant url}").using(SPFx(this.context)); +const sp = spfi(...); const results = await sp.searchSuggest("test"); @@ -174,11 +174,11 @@ const results2 = await sp.searchSuggest({ You can also configure a search or suggest query against any valid SP url using the factory methods. ```TypeScript -import { spfi, SPFx } from "@pnp/sp"; +import { spfi } from "@pnp/sp"; import "@pnp/sp/search"; import { Search, Suggest } from "@pnp/sp/search"; -const sp = spfi("{tenant url}").using(SPFx(this.context)); +const sp = spfi(...); // set the url for search const searcher = Search("https://mytenant.sharepoint.com/sites/dev"); diff --git a/docs/sp/security.md b/docs/sp/security.md index 405440778..ce700d791 100644 --- a/docs/sp/security.md +++ b/docs/sp/security.md @@ -23,7 +23,7 @@ import "@pnp/sp/security"; ## Securable Methods ```TypeScript -import { spfi, SPFx } from "@pnp/sp"; +import { spfi } from "@pnp/sp"; import "@pnp/sp/webs"; import "@pnp/sp/lists"; import "@pnp/sp/security/list"; @@ -31,7 +31,7 @@ import "@pnp/sp/site-users/web"; import { IList } from "@pnp/sp/lists"; import { PermissionKind } from "@pnp/sp/security"; -const sp = spfi("{tenant url}").using(SPFx(this.context)); +const sp = spfi(...); // ensure we have a list const ler = await sp.web.lists.ensure("SecurityTestingList"); @@ -70,11 +70,11 @@ await list.resetRoleInheritance(); ## Web Specific methods ```TypeScript -import { spfi, SPFx } from "@pnp/sp"; +import { spfi } from "@pnp/sp"; import "@pnp/sp/webs"; import "@pnp/sp/security/web"; -const sp = spfi("{tenant url}").using(SPFx(this.context)); +const sp = spfi(...); // role definitions (see section below) const defs = await sp.web.roleDefinitions(); @@ -85,7 +85,7 @@ const defs = await sp.web.roleDefinitions(); Allows you to list and manipulate the set of role assignments for the given securable. Again we show usage using list, but the examples apply to web and item as well. ```TypeScript -import { spfi, SPFx } from "@pnp/sp"; +import { spfi } from "@pnp/sp"; import "@pnp/sp/webs"; import "@pnp/sp/lists"; import "@pnp/sp/security/web"; @@ -93,7 +93,7 @@ import "@pnp/sp/site-users/web"; import { IList } from "@pnp/sp/lists"; import { PermissionKind } from "@pnp/sp/security"; -const sp = spfi("{tenant url}").using(SPFx(this.context)); +const sp = spfi(...); // ensure we have a list const ler = await sp.web.lists.ensure("SecurityTestingList"); @@ -137,11 +137,11 @@ await list.roleAssignments.getById(ra.Id).delete(); ## Role Definitions ```TypeScript -import { spfi, SPFx } from "@pnp/sp"; +import { spfi } from "@pnp/sp"; import "@pnp/sp/webs"; import "@pnp/sp/security/web"; -const sp = spfi("{tenant url}").using(SPFx(this.context)); +const sp = spfi(...); // read role definitions const defs = await sp.web.roleDefinitions(); diff --git a/docs/sp/sharing.md b/docs/sp/sharing.md index 16447ccde..ea7400da0 100644 --- a/docs/sp/sharing.md +++ b/docs/sp/sharing.md @@ -16,9 +16,9 @@ To import and attach the sharing methods to all four of the sharable types inclu import "@pnp/sp/sharing"; import "@pnp/sp/webs"; import "@pnp/sp/site-users/web"; -import { spfi, SPFx } from "@pnp/sp"; +import { spfi } from "@pnp/sp"; -const sp = spfi("{tenant url}").using(SPFx(this.context)); +const sp = spfi(...); const user = await sp.web.siteUsers.getByEmail("user@site.com")(); const r = await sp.web.shareWith(user.LoginName); @@ -32,9 +32,9 @@ Import only the web's sharing methods into the library import "@pnp/sp/sharing/web"; import "@pnp/sp/webs"; import "@pnp/sp/site-users/web"; -import { spfi, SPFx } from "@pnp/sp"; +import { spfi } from "@pnp/sp"; -const sp = spfi("{tenant url}").using(SPFx(this.context)); +const sp = spfi(...); const user = await sp.web.siteUsers.getByEmail("user@site.com")(); const r = await sp.web.shareWith(user.LoginName); @@ -47,13 +47,13 @@ const r = await sp.web.shareWith(user.LoginName); Creates a sharing link for the given resource with an optional expiration. ```TypeScript -import { spfi, SPFx } from "@pnp/sp"; +import { spfi } from "@pnp/sp"; import "@pnp/sp/webs"; import "@pnp/sp/sharing"; import { SharingLinkKind, IShareLinkResponse } from "@pnp/sp/sharing"; import { dateAdd } from "@pnp/core"; -const sp = spfi("{tenant url}").using(SPFx(this.context)); +const sp = spfi(...); const result = await sp.web.getFolderByServerRelativeUrl("/sites/dev/Shared Documents/folder1").getShareLink(SharingLinkKind.AnonymousView); @@ -74,14 +74,14 @@ Shares the given resource with the specified permissions (View or Edit) and opti ![Batching Not Supported Banner](https://img.shields.io/badge/Batching%20Not%20Supported-important.svg) ```TypeScript -import { spfi, SPFx } from "@pnp/sp"; +import { spfi } from "@pnp/sp"; import "@pnp/sp/webs"; import "@pnp/sp/sharing"; import "@pnp/sp/folders/web"; import "@pnp/sp/files/web"; import { ISharingResult, SharingRole } from "@pnp/sp/sharing"; -const sp = spfi("{tenant url}").using(SPFx(this.context)); +const sp = spfi(...); const result = await sp.web.shareWith("i:0#.f|membership|user@site.com"); @@ -113,12 +113,12 @@ await sp.web.getFileByServerRelativeUrl("/sites/dev/Shared Documents/test.txt"). Allows you to share any shareable object in a web by providing the appropriate parameters. These two methods differ in that shareObject will try and fix up your query based on the supplied parameters where shareObjectRaw will send your supplied json object directly to the server. The later method is provided for the greatest amount of flexibility. ```TypeScript -import { spfi, SPFx } from "@pnp/sp"; +import { spfi } from "@pnp/sp"; import "@pnp/sp/webs"; import "@pnp/sp/sharing"; import { ISharingResult, SharingRole } from "@pnp/sp/sharing"; -const sp = spfi("{tenant url}").using(SPFx(this.context)); +const sp = spfi(...); // Share an object in this web const result = await sp.web.shareObject("https://mysite.sharepoint.com/sites/dev/Docs/test.txt", "i:0#.f|membership|user@site.com", SharingRole.View); @@ -143,12 +143,12 @@ await sp.web.shareObjectRaw({ **Applies to: Web** ```TypeScript -import { spfi, SPFx } from "@pnp/sp"; +import { spfi } from "@pnp/sp"; import "@pnp/sp/webs"; import "@pnp/sp/sharing"; import { ISharingResult } from "@pnp/sp/sharing"; -const sp = spfi("{tenant url}").using(SPFx(this.context)); +const sp = spfi(...); const result = await sp.web.unshareObject("https://mysite.sharepoint.com/sites/dev/Docs/test.txt"); ``` @@ -160,13 +160,13 @@ const result = await sp.web.unshareObject("https://mysite.sharepoint.com/sites/d Checks Permissions on the list of Users and returns back role the users have on the Item. ```TypeScript -import { spfi, SPFx } from "@pnp/sp"; +import { spfi } from "@pnp/sp"; import "@pnp/sp/webs"; import "@pnp/sp/sharing/folders"; import "@pnp/sp/folders/web"; import { SharingEntityPermission } from "@pnp/sp/sharing"; -const sp = spfi("{tenant url}").using(SPFx(this.context)); +const sp = spfi(...); // check the sharing permissions for a folder const perms = await sp.web.getFolderByServerRelativeUrl("/sites/dev/Shared Documents/test").checkSharingPermissions([{ alias: "i:0#.f|membership|user@site.com" }]); @@ -179,13 +179,13 @@ const perms = await sp.web.getFolderByServerRelativeUrl("/sites/dev/Shared Docum Get Sharing Information. ```TypeScript -import { spfi, SPFx } from "@pnp/sp"; +import { spfi } from "@pnp/sp"; import "@pnp/sp/webs"; import "@pnp/sp/sharing"; import "@pnp/sp/folders"; import { ISharingInformation } from "@pnp/sp/sharing"; -const sp = spfi("{tenant url}").using(SPFx(this.context)); +const sp = spfi(...); // Get the sharing information for a folder const info = await sp.web.getFolderByServerRelativeUrl("/sites/dev/Shared Documents/test").getSharingInformation(); @@ -198,13 +198,13 @@ const info = await sp.web.getFolderByServerRelativeUrl("/sites/dev/Shared Docume Gets the sharing settings ```TypeScript -import { spfi, SPFx } from "@pnp/sp"; +import { spfi } from "@pnp/sp"; import "@pnp/sp/webs"; import "@pnp/sp/sharing"; import "@pnp/sp/folders"; import { IObjectSharingSettings } from "@pnp/sp/sharing"; -const sp = spfi("{tenant url}").using(SPFx(this.context)); +const sp = spfi(...); // Gets the sharing object settings const settings: IObjectSharingSettings = await sp.web.getFolderByServerRelativeUrl("/sites/dev/Shared Documents/test").getObjectSharingSettings(); @@ -217,13 +217,13 @@ const settings: IObjectSharingSettings = await sp.web.getFolderByServerRelativeU Unshares a given resource ```TypeScript -import { spfi, SPFx } from "@pnp/sp"; +import { spfi } from "@pnp/sp"; import "@pnp/sp/webs"; import "@pnp/sp/sharing"; import "@pnp/sp/folders"; import { ISharingResult } from "@pnp/sp/sharing"; -const sp = spfi("{tenant url}").using(SPFx(this.context)); +const sp = spfi(...); const result: ISharingResult = await sp.web.getFolderByServerRelativeUrl("/sites/dev/Shared Documents/test").unshare(); ``` @@ -233,13 +233,13 @@ const result: ISharingResult = await sp.web.getFolderByServerRelativeUrl("/sites **Applies to: Item, Folder, File** ```TypeScript -import { spfi, SPFx } from "@pnp/sp"; +import { spfi } from "@pnp/sp"; import "@pnp/sp/webs"; import "@pnp/sp/sharing"; import "@pnp/sp/folders"; import { ISharingResult, SharingLinkKind } from "@pnp/sp/sharing"; -const sp = spfi("{tenant url}").using(SPFx(this.context)); +const sp = spfi(...); const result: ISharingResult = await sp.web.getFolderByServerRelativeUrl("/sites/dev/Shared Documents/test").deleteSharingLinkByKind(SharingLinkKind.AnonymousEdit); ``` @@ -249,13 +249,13 @@ const result: ISharingResult = await sp.web.getFolderByServerRelativeUrl("/sites **Applies to: Item, Folder, File** ```TypeScript -import { spfi, SPFx } from "@pnp/sp"; +import { spfi } from "@pnp/sp"; import "@pnp/sp/webs"; import "@pnp/sp/sharing"; import "@pnp/sp/folders"; import { SharingLinkKind } from "@pnp/sp/sharing"; -const sp = spfi("{tenant url}").using(SPFx(this.context)); +const sp = spfi(...); await sp.web.getFolderByServerRelativeUrl("/sites/dev/Shared Documents/test").unshareLink(SharingLinkKind.AnonymousEdit); diff --git a/docs/sp/site-designs.md b/docs/sp/site-designs.md index a9916305a..957d22f30 100644 --- a/docs/sp/site-designs.md +++ b/docs/sp/site-designs.md @@ -10,10 +10,10 @@ Check out [SharePoint site design and site script overview](https://docs.microso ## Create a new site design ```TypeScript -import { spfi, SPFx } from "@pnp/sp"; +import { spfi } from "@pnp/sp"; import "@pnp/sp/site-designs"; -const sp = spfi("{tenant url}").using(SPFx(this.context)); +const sp = spfi(...); // WebTemplate: 64 Team site template, 68 Communication site template const siteDesign = await sp.siteDesigns.createSiteDesign({ @@ -28,10 +28,10 @@ console.log(siteDesign.Title); ## Applying a site design to a site ```TypeScript -import { spfi, SPFx } from "@pnp/sp"; +import { spfi } from "@pnp/sp"; import "@pnp/sp/site-designs"; -const sp = spfi("{tenant url}").using(SPFx(this.context)); +const sp = spfi(...); // Limited to 30 actions in a site script, but runs synchronously await sp.siteDesigns.applySiteDesign("75b9d8fe-4381-45d9-88c6-b03f483ae6a8","https://contoso.sharepoint.com/sites/teamsite-pnpjs001"); @@ -43,10 +43,10 @@ const task = await sp.web.addSiteDesignTask("75b9d8fe-4381-45d9-88c6-b03f483ae6a ## Retrieval ```TypeScript -import { spfi, SPFx } from "@pnp/sp"; +import { spfi } from "@pnp/sp"; import "@pnp/sp/site-designs"; -const sp = spfi("{tenant url}").using(SPFx(this.context)); +const sp = spfi(...); // Retrieving all site designs const allSiteDesigns = await sp.siteDesigns.getSiteDesigns(); @@ -60,10 +60,10 @@ console.log(siteDesign.Title); ## Update and delete ```TypeScript -import { spfi, SPFx } from "@pnp/sp"; +import { spfi } from "@pnp/sp"; import "@pnp/sp/site-designs"; -const sp = spfi("{tenant url}").using(SPFx(this.context)); +const sp = spfi(...); // Update const updatedSiteDesign = await sp.siteDesigns.updateSiteDesign({ Id: "75b9d8fe-4381-45d9-88c6-b03f483ae6a8", Title: "SiteDesignUpdatedTitle001" }); @@ -75,10 +75,10 @@ await sp.siteDesigns.deleteSiteDesign("75b9d8fe-4381-45d9-88c6-b03f483ae6a8"); ## Setting Rights/Permissions ```TypeScript -import { spfi, SPFx } from "@pnp/sp"; +import { spfi } from "@pnp/sp"; import "@pnp/sp/site-designs"; -const sp = spfi("{tenant url}").using(SPFx(this.context)); +const sp = spfi(...); // Get const rights = await sp.siteDesigns.getSiteDesignRights("75b9d8fe-4381-45d9-88c6-b03f483ae6a8"); @@ -98,10 +98,10 @@ await sp.siteDesigns.revokeSiteDesignRights("75b9d8fe-4381-45d9-88c6-b03f483ae6a ## Get a history of site designs that have run on a web ```TypeScript -import { spfi, SPFx } from "@pnp/sp"; +import { spfi } from "@pnp/sp"; import "@pnp/sp/site-designs"; -const sp = spfi("{tenant url}").using(SPFx(this.context)); +const sp = spfi(...); const runs = await sp.web.getSiteDesignRuns(); const runs2 = await sp.siteDesigns.getSiteDesignRun("https://TENANT.sharepoint.com/sites/mysite"); diff --git a/docs/sp/site-groups.md b/docs/sp/site-groups.md index 9f21f9280..ac7bd2539 100644 --- a/docs/sp/site-groups.md +++ b/docs/sp/site-groups.md @@ -9,11 +9,11 @@ The site groups module provides methods to manage groups for a sharepoint site. ### Get all site groups ```TypeScript -import { spfi, SPFx } from "@pnp/sp"; +import { spfi } from "@pnp/sp"; import "@pnp/sp/webs"; import "@pnp/sp/site-groups/web"; -const sp = spfi("{tenant url}").using(SPFx(this.context)); +const sp = spfi(...); // gets all site groups of the web const groups = await sp.web.siteGroups(); @@ -24,11 +24,11 @@ const groups = await sp.web.siteGroups(); You can get the associated Owner, Member and Visitor groups of a web ```TypeScript -import { spfi, SPFx } from "@pnp/sp"; +import { spfi } from "@pnp/sp"; import "@pnp/sp/webs"; import "@pnp/sp/site-groups/web"; -const sp = spfi("{tenant url}").using(SPFx(this.context)); +const sp = spfi(...); // Gets the associated visitors group of a web const visitorGroup = await sp.web.associatedVisitorGroup(); @@ -44,11 +44,11 @@ const ownerGroup = await sp.web.associatedOwnerGroup(); ### Create the default associated groups for a web ```TypeScript -import { spfi, SPFx } from "@pnp/sp"; +import { spfi } from "@pnp/sp"; import "@pnp/sp/webs"; import "@pnp/sp/site-groups/web"; -const sp = spfi("{tenant url}").using(SPFx(this.context)); +const sp = spfi(...); // Breaks permission inheritance and creates the default associated groups for the web @@ -67,11 +67,11 @@ await sp.web.createDefaultAssociatedGroups("PnP Site", owner1, copyRoleAssignmen ### Create a new site group ```TypeScript -import { spfi, SPFx } from "@pnp/sp"; +import { spfi } from "@pnp/sp"; import "@pnp/sp/webs"; import "@pnp/sp/site-groups/web"; -const sp = spfi("{tenant url}").using(SPFx(this.context)); +const sp = spfi(...); // Creates a new site group with the specified title await sp.web.siteGroups.add({"Title":"new group name"}); @@ -90,14 +90,15 @@ await sp.web.siteGroups.add({"Title":"new group name"}); ======= >>>>>>> 52a91d788431066d44d536df1352b6ce855675e3 + ### Getting and updating the groups of a sharepoint web ```TypeScript -import { spfi, SPFx } from "@pnp/sp"; +import { spfi } from "@pnp/sp"; import "@pnp/sp/webs"; import "@pnp/sp/site-groups"; -const sp = spfi("{tenant url}").using(SPFx(this.context)); +const sp = spfi(...); // get the group using a group id const groupID = 33; @@ -120,11 +121,11 @@ await sp.web.siteGroups.removeByLoginName(groupName); ### Getting all users of a group ```TypeScript -import { spfi, SPFx } from "@pnp/sp"; +import { spfi } from "@pnp/sp"; import "@pnp/sp/webs"; import "@pnp/sp/site-groups"; -const sp = spfi("{tenant url}").using(SPFx(this.context)); +const sp = spfi(...); // get all users of group const groupID = 7; @@ -136,11 +137,11 @@ const users = await sp.web.siteGroups.getById(groupID).users(); Unfortunately for now setting the owner of a group as another or same SharePoint group is currently unsupported in REST. Setting the owner as a user is supported. ```TypeScript -import { spfi, SPFx } from "@pnp/sp"; +import { spfi } from "@pnp/sp"; import "@pnp/sp/webs"; import "@pnp/sp/site-groups"; -const sp = spfi("{tenant url}").using(SPFx(this.context)); +const sp = spfi(...); // Update the owner with a user id await sp.web.siteGroups.getById(7).setUserAsOwner(4); diff --git a/docs/sp/site-scripts.md b/docs/sp/site-scripts.md index 503b2761d..34c5d3d3e 100644 --- a/docs/sp/site-scripts.md +++ b/docs/sp/site-scripts.md @@ -5,10 +5,10 @@ ## Create a new site script ```TypeScript -import { spfi, SPFx } from "@pnp/sp"; +import { spfi } from "@pnp/sp"; import "@pnp/sp/site-scripts"; -const sp = spfi("{tenant url}").using(SPFx(this.context)); +const sp = spfi(...); const sitescriptContent = { "$schema": "schema.json", @@ -30,10 +30,10 @@ console.log(siteScript.Title); ## Retrieval ```TypeScript -import { spfi, SPFx } from "@pnp/sp"; +import { spfi } from "@pnp/sp"; import "@pnp/sp/site-scripts"; -const sp = spfi("{tenant url}").using(SPFx(this.context)); +const sp = spfi(...); // Retrieving all site scripts const allSiteScripts = await sp.siteScripts.getSiteScripts(); @@ -47,10 +47,10 @@ console.log(siteScript.Title); ## Update and delete ```TypeScript -import { spfi, SPFx } from "@pnp/sp"; +import { spfi } from "@pnp/sp"; import "@pnp/sp/site-scripts"; -const sp = spfi("{tenant url}").using(SPFx(this.context)); +const sp = spfi(...); // Update const updatedSiteScript = await sp.siteScripts.updateSiteScript({ Id: "884ed56b-1aab-4653-95cf-4be0bfa5ef0a", Title: "New Title" }); @@ -63,10 +63,10 @@ await sp.siteScripts.deleteSiteScript("884ed56b-1aab-4653-95cf-4be0bfa5ef0a"); ## Get site script from a list ```TypeScript -import { spfi, SPFx } from "@pnp/sp"; +import { spfi } from "@pnp/sp"; import "@pnp/sp/site-scripts"; -const sp = spfi("{tenant url}").using(SPFx(this.context)); +const sp = spfi(...); // Using the absolute URL of the list const ss = await sp.siteScripts.getSiteScriptFromList("https://TENANT.sharepoint.com/Lists/mylist"); @@ -78,7 +78,7 @@ const ss2 = await sp.web.lists.getByTitle("mylist").getSiteScript(); ## Get site script from a web ```TypeScript -import { spfi, SPFx } from "@pnp/sp"; +import { spfi } from "@pnp/sp"; import "@pnp/sp/site-scripts"; const extractInfo = { @@ -99,10 +99,10 @@ const ss2 = await sp.web.getSiteScript(extractInfo); ## Execute Site Script Action ```TypeScript -import { spfi, SPFx } from "@pnp/sp"; +import { spfi } from "@pnp/sp"; import "@pnp/sp/site-scripts"; -const sp = spfi("{tenant url}").using(SPFx(this.context)); +const sp = spfi(...); const siteScript = "your site script action..."; @@ -112,7 +112,7 @@ const ss = await sp.siteScripts.executeSiteScriptAction(siteScript); ### Execute site script for a specific web ```TypeScript -import { spfi, SPFx } from "@pnp/sp"; +import { spfi } from "@pnp/sp"; import { SiteScripts } "@pnp/sp/site-scripts"; const siteScript = "your site script action..."; diff --git a/docs/sp/site-users.md b/docs/sp/site-users.md index 4edfc112b..24f94855d 100644 --- a/docs/sp/site-users.md +++ b/docs/sp/site-users.md @@ -9,11 +9,11 @@ The site users module provides methods to manage users for a sharepoint site. ### Get all site user ```TypeScript -import { spfi, SPFx } from "@pnp/sp"; +import { spfi } from "@pnp/sp"; import "@pnp/sp/webs"; import "@pnp/sp/site-users/web"; -const sp = spfi("{tenant url}").using(SPFx(this.context)); +const sp = spfi(...); const users = await sp.web.siteUsers(); ``` @@ -21,11 +21,11 @@ const users = await sp.web.siteUsers(); ### Get Current user ```TypeScript -import { spfi, SPFx } from "@pnp/sp"; +import { spfi } from "@pnp/sp"; import "@pnp/sp/webs"; import "@pnp/sp/site-users/web"; -const sp = spfi("{tenant url}").using(SPFx(this.context)); +const sp = spfi(...); let user = await sp.web.currentUser(); ``` @@ -33,11 +33,11 @@ let user = await sp.web.currentUser(); ### Get user by id ```TypeScript -import { spfi, SPFx } from "@pnp/sp"; +import { spfi } from "@pnp/sp"; import "@pnp/sp/webs"; import "@pnp/sp/site-users/web"; -const sp = spfi("{tenant url}").using(SPFx(this.context)); +const sp = spfi(...); const id = 6; user = await sp.web.getUserById(id); @@ -46,11 +46,11 @@ user = await sp.web.getUserById(id); ### Ensure user ```TypeScript -import { spfi, SPFx } from "@pnp/sp"; +import { spfi } from "@pnp/sp"; import "@pnp/sp/webs"; import "@pnp/sp/site-users/web"; -const sp = spfi("{tenant url}").using(SPFx(this.context)); +const sp = spfi(...); const username = "usernames@microsoft.com"; result = await sp.web.ensureUser(username); @@ -69,14 +69,15 @@ result = await sp.web.ensureUser(username); ======= >>>>>>> 52a91d788431066d44d536df1352b6ce855675e3 + ### Get user Groups ```TypeScript -import { spfi, SPFx } from "@pnp/sp"; +import { spfi } from "@pnp/sp"; import "@pnp/sp/webs"; import "@pnp/sp/site-users/web"; -const sp = spfi("{tenant url}").using(SPFx(this.context)); +const sp = spfi(...); let groups = await sp.web.currentUser.groups(); ``` @@ -84,11 +85,11 @@ let groups = await sp.web.currentUser.groups(); ### Add user to Site collection ```TypeScript -import { spfi, SPFx } from "@pnp/sp"; +import { spfi } from "@pnp/sp"; import "@pnp/sp/webs"; import "@pnp/sp/site-users/web"; -const sp = spfi("{tenant url}").using(SPFx(this.context)); +const sp = spfi(...); const user = await sp.web.ensureUser("userLoginname") const users = await sp.web.siteUsers; @@ -99,11 +100,11 @@ await users.add(user.data.LoginName); ### Get user ```TypeScript -import { spfi, SPFx } from "@pnp/sp"; +import { spfi } from "@pnp/sp"; import "@pnp/sp/webs"; import "@pnp/sp/site-users/web"; -const sp = spfi("{tenant url}").using(SPFx(this.context)); +const sp = spfi(...); // get user object by id const user = await sp.web.siteUsers.getById(6); @@ -118,11 +119,11 @@ const user = await sp.web.siteUsers.getByLoginName("userLoginName"); ### Update user ```TypeScript -import { spfi, SPFx } from "@pnp/sp"; +import { spfi } from "@pnp/sp"; import "@pnp/sp/webs"; import "@pnp/sp/site-users/web"; -const sp = spfi("{tenant url}").using(SPFx(this.context)); +const sp = spfi(...); let userProps = await sp.web.currentUser(); userProps.Title = "New title"; @@ -132,11 +133,11 @@ await sp.web.currentUser.update(userProps); ### Remove user ```TypeScript -import { spfi, SPFx } from "@pnp/sp"; +import { spfi } from "@pnp/sp"; import "@pnp/sp/webs"; import "@pnp/sp/site-users/web"; -const sp = spfi("{tenant url}").using(SPFx(this.context)); +const sp = spfi(...); // remove user by id await sp.web.siteUsers.removeById(6); diff --git a/docs/sp/sites.md b/docs/sp/sites.md index 99b5a2448..706c26fd9 100644 --- a/docs/sp/sites.md +++ b/docs/sp/sites.md @@ -7,11 +7,11 @@ Site collection are one of the fundamental entry points while working with Share Using the library, you can get the context information of the current site collection ```Typescript -import { spfi, SPFx } from "@pnp/sp"; +import { spfi } from "@pnp/sp"; import "@pnp/sp/sites"; import { IContextInfo } from "@pnp/sp/sites"; -const sp = spfi("{tenant url}").using(SPFx(this.context)); +const sp = spfi(...); const oContext: IContextInfo = await sp.site.getContextInfo(); console.log(oContext.FormDigestValue); @@ -24,11 +24,11 @@ Using the library, you can get a list of the document libraries present in the a **Note:** Works only in SharePoint online ```Typescript -import { spfi, SPFx } from "@pnp/sp"; +import { spfi } from "@pnp/sp"; import "@pnp/sp/sites"; import { IDocumentLibraryInformation } from "@pnp/sp/sites"; -const sp = spfi("{tenant url}").using(SPFx(this.context)); +const sp = spfi(...); const docLibs: IDocumentLibraryInformation[] = await sp.site.getDocumentLibraries("https://tenant.sharepoint.com/sites/test/subsite"); @@ -43,10 +43,10 @@ docLibs.forEach((docLib: IDocumentLibraryInformation) => { Because this method is a POST request you can chain off it directly. You will get back the full web properties in the data property of the return object. You can also chain directly off the returned Web instance on the web property. ```TypeScript -import { spfi, SPFx } from "@pnp/sp"; +import { spfi } from "@pnp/sp"; import "@pnp/sp/sites"; -const sp = spfi("{tenant url}").using(SPFx(this.context)); +const sp = spfi(...); const w = await sp.site.openWebById("111ca453-90f5-482e-a381-cee1ff383c9e"); @@ -62,10 +62,10 @@ const w2 = await w.web.select("Title")(); Using the library, you can get the absolute web url by providing a page url ```TypeScript -import { spfi, SPFx } from "@pnp/sp"; +import { spfi } from "@pnp/sp"; import "@pnp/sp/sites"; -const sp = spfi("{tenant url}").using(SPFx(this.context)); +const sp = spfi(...); const d: string = await sp.site.getWebUrlFromPageUrl("https://tenant.sharepoint.com/sites/test/Pages/test.aspx"); @@ -77,10 +77,10 @@ console.log(d); //https://tenant.sharepoint.com/sites/test There are two methods to access the root web. The first, using the rootWeb property, is best for directly accessing information about that web. If you want to chain multiple operations off of the web, better to use the getRootWeb method that will ensure the web instance is created using its own Url vs. "_api/sites/rootweb" which does not work for all operations. ```TypeScript -import { spfi, SPFx } from "@pnp/sp"; +import { spfi } from "@pnp/sp"; import "@pnp/sp/sites"; -const sp = spfi("{tenant url}").using(SPFx(this.context)); +const sp = spfi(...); // use for rootweb information access const rootwebData = await sp.site.rootWeb(); @@ -115,10 +115,10 @@ Creates a modern communication site. ```TypeScript -import { spfi, SPFx } from "@pnp/sp"; +import { spfi } from "@pnp/sp"; import "@pnp/sp/sites"; -const sp = spfi("{tenant url}").using(SPFx(this.context)); +const sp = spfi(...); const result = await sp.site.createCommunicationSite( "Title", @@ -138,11 +138,11 @@ const result = await sp.site.createCommunicationSite( You may need to supply additional parameters such as WebTemplate, to do so please use the `createCommunicationSiteFromProps` method. ```TypeScript -import { spfi, SPFx } from "@pnp/sp"; +import { spfi } from "@pnp/sp"; import "@pnp/sp/webs"; import "@pnp/sp/sites"; -const sp = spfi("{tenant url}").using(SPFx(this.context)); +const sp = spfi(...); // in this case you supply a single struct deinfing the creation props const result = await sp.site.createCommunicationSiteFromProps({ @@ -177,10 +177,10 @@ Creates a modern team site backed by O365 group. ```TypeScript -import { spfi, SPFx } from "@pnp/sp"; +import { spfi } from "@pnp/sp"; import "@pnp/sp/sites"; -const sp = spfi("{tenant url}").using(SPFx(this.context)); +const sp = spfi(...); const result = await sp.site.createModernTeamSite( "displayName", @@ -202,11 +202,11 @@ console.log(d); You may need to supply additional parameters, to do so please use the `createModernTeamSiteFromProps` method. ```TypeScript -import { spfi, SPFx } from "@pnp/sp"; +import { spfi } from "@pnp/sp"; import "@pnp/sp/webs"; import "@pnp/sp/sites"; -const sp = spfi("{tenant url}").using(SPFx(this.context)); +const sp = spfi(...); // in this case you supply a single struct deinfing the creation props const result = await sp.site.createModernTeamSiteFromProps({ @@ -221,11 +221,11 @@ const result = await sp.site.createModernTeamSiteFromProps({ Using the library, you can delete a specific site collection ```TypeScript -import { spfi, SPFx } from "@pnp/sp"; +import { spfi } from "@pnp/sp"; import "@pnp/sp/sites"; import { Site } from "@pnp/sp/sites"; -const sp = spfi("{tenant url}").using(SPFx(this.context)); +const sp = spfi(...); // Delete the current site await sp.site.delete(); @@ -241,9 +241,9 @@ await site2.delete(); Using the library, you can check if a specific site collection exist or not on your tenant ```TypeScript -import { spfi, SPFx } from "@pnp/sp"; +import { spfi } from "@pnp/sp"; -const sp = spfi("{tenant url}").using(SPFx(this.context)); +const sp = spfi(...); // Specify which site to verify const siteUrl = "https://tenant.sharepoint.com/sites/subsite"; diff --git a/docs/sp/social.md b/docs/sp/social.md index 80840efbd..377c5abc3 100644 --- a/docs/sp/social.md +++ b/docs/sp/social.md @@ -10,10 +10,10 @@ with app-only permissions. Gets a URI to a site that lists the current user's followed sites. ```TypeScript -import { spfi, SPFx } from "@pnp/sp"; +import { spfi } from "@pnp/sp"; import "@pnp/sp/social"; -const sp = spfi("{tenant url}").using(SPFx(this.context)); +const sp = spfi(...); const uri = await sp.social.getFollowedSitesUri(); ``` @@ -23,10 +23,10 @@ const uri = await sp.social.getFollowedSitesUri(); Gets a URI to a site that lists the current user's followed documents. ```TypeScript -import { spfi, SPFx } from "@pnp/sp"; +import { spfi } from "@pnp/sp"; import "@pnp/sp/social"; -const sp = spfi("{tenant url}").using(SPFx(this.context)); +const sp = spfi(...); const uri = await sp.social.getFollowedDocumentsUri(); ``` @@ -36,10 +36,10 @@ const uri = await sp.social.getFollowedDocumentsUri(); Makes the current user start following a user, document, site, or tag ```TypeScript -import { spfi, SPFx } from "@pnp/sp"; +import { spfi } from "@pnp/sp"; import { SocialActorType } from "@pnp/sp/social"; -const sp = spfi("{tenant url}").using(SPFx(this.context)); +const sp = spfi(...); // follow a site const r1 = await sp.social.follow({ @@ -75,10 +75,10 @@ const r4 = await sp.social.follow({ Indicates whether the current user is following a specified user, document, site, or tag ```TypeScript -import { spfi, SPFx } from "@pnp/sp"; +import { spfi } from "@pnp/sp"; import { SocialActorType } from "@pnp/sp/social"; -const sp = spfi("{tenant url}").using(SPFx(this.context)); +const sp = spfi(...); // pass the same social actor struct as shown in follow example for each type const r = await sp.social.isFollowed({ @@ -92,10 +92,10 @@ const r = await sp.social.isFollowed({ Makes the current user stop following a user, document, site, or tag ```TypeScript -import { spfi, SPFx } from "@pnp/sp"; +import { spfi } from "@pnp/sp"; import { SocialActorType } from "@pnp/sp/social"; -const sp = spfi("{tenant url}").using(SPFx(this.context)); +const sp = spfi(...); // pass the same social actor struct as shown in follow example for each type const r = await sp.social.stopFollowing({ @@ -111,10 +111,10 @@ const r = await sp.social.stopFollowing({ Gets this user's social information ```TypeScript -import { spfi, SPFx } from "@pnp/sp"; +import { spfi } from "@pnp/sp"; import "@pnp/sp/social"; -const sp = spfi("{tenant url}").using(SPFx(this.context)); +const sp = spfi(...); const r = await sp.social.my(); ``` @@ -124,10 +124,10 @@ const r = await sp.social.my(); Gets users, documents, sites, and tags that the current user is following based on the supplied flags. ```TypeScript -import { spfi, SPFx } from "@pnp/sp"; +import { spfi } from "@pnp/sp"; import { SocialActorType } from "@pnp/sp/social"; -const sp = spfi("{tenant url}").using(SPFx(this.context)); +const sp = spfi(...); // get all the followed documents const r1 = await sp.social.my.followed(SocialActorTypes.Document); @@ -144,10 +144,10 @@ const r3 = await sp.social.my.followed(SocialActorTypes.Site | SocialActorTypes. Works as followed but returns on the count of actors specified by the query ```TypeScript -import { spfi, SPFx } from "@pnp/sp"; +import { spfi } from "@pnp/sp"; import { SocialActorType } from "@pnp/sp/social"; -const sp = spfi("{tenant url}").using(SPFx(this.context)); +const sp = spfi(...); // get the followed documents count const r = await sp.social.my.followedCount(SocialActorTypes.Document); @@ -158,10 +158,10 @@ const r = await sp.social.my.followedCount(SocialActorTypes.Document); Gets the users who are following the current user. ```TypeScript -import { spfi, SPFx } from "@pnp/sp"; +import { spfi } from "@pnp/sp"; import "@pnp/sp/social"; -const sp = spfi("{tenant url}").using(SPFx(this.context)); +const sp = spfi(...); // get the followed documents count const r = await sp.social.my.followers(); @@ -172,10 +172,10 @@ const r = await sp.social.my.followers(); Gets users who the current user might want to follow. ```TypeScript -import { spfi, SPFx } from "@pnp/sp"; +import { spfi } from "@pnp/sp"; import "@pnp/sp/social"; -const sp = spfi("{tenant url}").using(SPFx(this.context)); +const sp = spfi(...); // get the followed documents count const r = await sp.social.my.suggestions(); diff --git a/docs/sp/sp-utilities-utility.md b/docs/sp/sp-utilities-utility.md index b14a59c62..30f6d0563 100644 --- a/docs/sp/sp-utilities-utility.md +++ b/docs/sp/sp-utilities-utility.md @@ -30,11 +30,11 @@ export interface EmailProperties { You must define the To, Subject, and Body values - the remaining are optional. ```TypeScript -import { spfi, SPFx } from "@pnp/sp"; +import { spfi } from "@pnp/sp"; import "@pnp/sp/sputilities"; import { IEmailProperties } from "@pnp/sp/sputilities"; -const sp = spfi("{tenant url}").using(SPFx(this.context)); +const sp = spfi(...); const emailProps: IEmailProperties = { To: ["user@site.com"], @@ -56,10 +56,10 @@ console.log("Email Sent!"); This method returns the current user's email addresses known to SharePoint. ```TypeScript -import { spfi, SPFx } from "@pnp/sp"; +import { spfi } from "@pnp/sp"; import "@pnp/sp/sputilities"; -const sp = spfi("{tenant url}").using(SPFx(this.context)); +const sp = spfi(...); let addressString: string = await sp.utility.getCurrentUserEmailAddresses(); @@ -82,7 +82,7 @@ Gets information about a principal that matches the specified Search criteria import { spfi, SPFx, IPrincipalInfo, PrincipalType, PrincipalSource } from "@pnp/sp"; import "@pnp/sp/sputilities"; -const sp = spfi("{tenant url}").using(SPFx(this.context)); +const sp = spfi(...); let principal : IPrincipalInfo = await sp.utility.resolvePrincipal("user@site.com", PrincipalType.User, PrincipalSource.All, true, false, true); @@ -97,7 +97,7 @@ Gets information about the principals that match the specified Search criteria. import { spfi, SPFx, IPrincipalInfo, PrincipalType, PrincipalSource } from "@pnp/sp"; import "@pnp/sp/sputilities"; -const sp = spfi("{tenant url}").using(SPFx(this.context)); +const sp = spfi(...); let principals : IPrincipalInfo[] = await sp.utility.searchPrincipals("john", PrincipalType.User, PrincipalSource.All,"", 10); @@ -109,10 +109,10 @@ console.log(principals); Gets the external (outside the firewall) URL to a document or resource in a site. ```TypeScript -import { spfi, SPFx } from "@pnp/sp"; +import { spfi } from "@pnp/sp"; import "@pnp/sp/sputilities"; -const sp = spfi("{tenant url}").using(SPFx(this.context)); +const sp = spfi(...); let url : string = await sp.utility.createEmailBodyForInvitation("https://contoso.sharepoint.com/sites/dev/SitePages/DevHome.aspx"); console.log(url); @@ -126,7 +126,7 @@ Resolves the principals contained within the supplied groups import { spfi, SPFx, IPrincipalInfo } from "@pnp/sp"; import "@pnp/sp/sputilities"; -const sp = spfi("{tenant url}").using(SPFx(this.context)); +const sp = spfi(...); let principals : IPrincipalInfo[] = await sp.utility.expandGroupsToPrincipals(["Dev Owners", "Dev Members"]); console.log(principals); @@ -139,11 +139,11 @@ console.log(principals); ## createWikiPage ```TypeScript -import { spfi, SPFx } from "@pnp/sp"; +import { spfi } from "@pnp/sp"; import "@pnp/sp/sputilities"; import { ICreateWikiPageResult } from "@pnp/sp/sputilities"; -const sp = spfi("{tenant url}").using(SPFx(this.context)); +const sp = spfi(...); let newPage : ICreateWikiPageResult = await sp.utility.createWikiPage({ ServerRelativeUrl: "/sites/dev/SitePages/mynewpage.aspx", diff --git a/docs/sp/subscriptions.md b/docs/sp/subscriptions.md index f7b13a2c5..9855c18c3 100644 --- a/docs/sp/subscriptions.md +++ b/docs/sp/subscriptions.md @@ -11,14 +11,14 @@ Webhooks on a SharePoint list are used to notify any change in the list, to othe Using this library, you can add a webhook to a specified list within the SharePoint site. ```TypeScript -import { spfi, SPFx } from "@pnp/sp"; +import { spfi } from "@pnp/sp"; import "@pnp/sp/webs"; import "@pnp/sp/lists"; import { Subscriptions, ISubscriptions} from "@pnp/sp/subscriptions"; import "@pnp/sp/subscriptions/list"; -const sp = spfi("{tenant url}").using(SPFx(this.context)); +const sp = spfi(...); // This is the URL which will be called by SharePoint when there is a change in the list const notificationUrl = ""; @@ -35,12 +35,12 @@ var res = await sp.web.lists.getByTitle("Documents").subscriptions.add(notificat Read all the webhooks' details which are associated to the list ```TypeScript -import { spfi, SPFx } from "@pnp/sp"; +import { spfi } from "@pnp/sp"; import "@pnp/sp/webs"; import "@pnp/sp/lists"; import "@pnp/sp/subscriptions"; -const sp = spfi("{tenant url}").using(SPFx(this.context)); +const sp = spfi(...); const res = await sp.web.lists.getByTitle("Documents").subscriptions(); ``` @@ -59,15 +59,16 @@ This interface provides the methods for managing a particular webhook. ======= >>>>>>> 52a91d788431066d44d536df1352b6ce855675e3 + ### Managing a webhook ```TypeScript -import { spfi, SPFx } from "@pnp/sp"; +import { spfi } from "@pnp/sp"; import "@pnp/sp/webs"; import "@pnp/sp/lists"; import "@pnp/sp/subscriptions"; -const sp = spfi("{tenant url}").using(SPFx(this.context)); +const sp = spfi(...); // Get details of a webhook based on its ID const webhookId = "1f029e5c-16e4-4941-b46f-67895118763f"; diff --git a/docs/sp/taxonomy.md b/docs/sp/taxonomy.md index c40d06730..1022d6a25 100644 --- a/docs/sp/taxonomy.md +++ b/docs/sp/taxonomy.md @@ -13,11 +13,11 @@ Provides access to the v2.1 api term store Access term store data from the root sp object as shown below. ```TypeScript -import { spfi, SPFx } from "@pnp/sp"; +import { spfi } from "@pnp/sp"; import "@pnp/sp/taxonomy"; import { ITermStoreInfo } from "@pnp/sp/taxonomy"; -const sp = spfi("{tenant url}").using(SPFx(this.context)); +const sp = spfi(...); // get term store data const info: ITermStoreInfo = await sp.termStore(); @@ -30,11 +30,11 @@ Access term group information ### List ```TypeScript -import { spfi, SPFx } from "@pnp/sp"; +import { spfi } from "@pnp/sp"; import "@pnp/sp/taxonomy"; import { ITermGroupInfo } from "@pnp/sp/taxonomy"; -const sp = spfi("{tenant url}").using(SPFx(this.context)); +const sp = spfi(...); // get term groups const info: ITermGroupInfo[] = await sp.termStore.groups(); @@ -43,11 +43,11 @@ const info: ITermGroupInfo[] = await sp.termStore.groups(); ### Get By Id ```TypeScript -import { spfi, SPFx } from "@pnp/sp"; +import { spfi } from "@pnp/sp"; import "@pnp/sp/taxonomy"; import { ITermGroupInfo } from "@pnp/sp/taxonomy"; -const sp = spfi("{tenant url}").using(SPFx(this.context)); +const sp = spfi(...); // get term groups data const info: ITermGroupInfo = await sp.termStore.groups.getById("338666a8-1111-2222-3333-f72471314e72")(); @@ -60,11 +60,11 @@ Access term set information ### List ```TypeScript -import { spfi, SPFx } from "@pnp/sp"; +import { spfi } from "@pnp/sp"; import "@pnp/sp/taxonomy"; import { ITermSetInfo } from "@pnp/sp/taxonomy"; -const sp = spfi("{tenant url}").using(SPFx(this.context)); +const sp = spfi(...); // get set info const info: ITermSetInfo[] = await sp.termStore.groups.getById("338666a8-1111-2222-3333-f72471314e72").sets(); @@ -73,11 +73,11 @@ const info: ITermSetInfo[] = await sp.termStore.groups.getById("338666a8-1111-22 ### Get By Id ```TypeScript -import { spfi, SPFx } from "@pnp/sp"; +import { spfi } from "@pnp/sp"; import "@pnp/sp/taxonomy"; import { ITermSetInfo } from "@pnp/sp/taxonomy"; -const sp = spfi("{tenant url}").using(SPFx(this.context)); +const sp = spfi(...); // get term set data by group id then by term set id const info: ITermSetInfo = await sp.termStore.groups.getById("338666a8-1111-2222-3333-f72471314e72").sets.getById("338666a8-1111-2222-3333-f72471314e72")(); @@ -93,12 +93,12 @@ This method will get all of a set's child terms in an ordered array. It is a cos > Starting with version 2.6.0 you can now include an optional param to retrieve all of the term's properties and localProperties in the tree. Default is false. ```TypeScript -import { spfi, SPFx } from "@pnp/sp"; +import { spfi } from "@pnp/sp"; import "@pnp/sp/taxonomy"; import { ITermInfo } from "@pnp/sp/taxonomy"; import { dateAdd, PnPClientStorage } from "@pnp/core"; -const sp = spfi("{tenant url}").using(SPFx(this.context)); +const sp = spfi(...); // here we get all the children of a given set const childTree = await sp.termStore.groups.getById("338666a8-1111-2222-3333-f72471314e72").sets.getById("338666a8-1111-2222-3333-f72471314e72").getAllChildrenAsOrderedTree(); @@ -124,11 +124,11 @@ Access term set information ### List ```TypeScript -import { spfi, SPFx } from "@pnp/sp"; +import { spfi } from "@pnp/sp"; import "@pnp/sp/taxonomy"; import { ITermInfo } from "@pnp/sp/taxonomy"; -const sp = spfi("{tenant url}").using(SPFx(this.context)); +const sp = spfi(...); // list all the terms that are direct children of this set const infos: ITermInfo[] = await sp.termStore.groups.getById("338666a8-1111-2222-3333-f72471314e72").sets.getById("338666a8-1111-2222-3333-f72471314e72").children(); @@ -139,11 +139,11 @@ const infos: ITermInfo[] = await sp.termStore.groups.getById("338666a8-1111-2222 You can use the terms property to get a flat list of all terms in the set. These terms do not contain parent/child relationship information. ```TypeScript -import { spfi, SPFx } from "@pnp/sp"; +import { spfi } from "@pnp/sp"; import "@pnp/sp/taxonomy"; import { ITermInfo } from "@pnp/sp/taxonomy"; -const sp = spfi("{tenant url}").using(SPFx(this.context)); +const sp = spfi(...); // list all the terms available in this term set by group id then by term set id const infos: ITermInfo[] = await sp.termStore.groups.getById("338666a8-1111-2222-3333-f72471314e72").sets.getById("338666a8-1111-2222-3333-f72471314e72").terms(); @@ -155,11 +155,11 @@ const infosByTermSetId: ITermInfo[] = await sp.termStore.sets.getById("338666a8- ### Get By Id ```TypeScript -import { spfi, SPFx } from "@pnp/sp"; +import { spfi } from "@pnp/sp"; import "@pnp/sp/taxonomy"; import { ITermInfo } from "@pnp/sp/taxonomy"; -const sp = spfi("{tenant url}").using(SPFx(this.context)); +const sp = spfi(...); // get term set data const info: ITermInfo = await sp.termStore.groups.getById("338666a8-1111-2222-3333-f72471314e72").sets.getById("338666a8-1111-2222-3333-f72471314e72").getTermById("338666a8-1111-2222-3333-f72471314e72")(); @@ -172,10 +172,10 @@ _Behavior Change in 2.1.0_ The server API changed again, resulting in the removal of the "parent" property from ITerm as it is not longer supported as a path property. You now must use "expand" to load a term's parent information. The side affect of this is that the parent is no longer chainable, meaning you need to load a new term instance to work with the parent term. An approach for this is shown below. ```TypeScript -import { spfi, SPFx } from "@pnp/sp"; +import { spfi } from "@pnp/sp"; import "@pnp/sp/taxonomy"; -const sp = spfi("{tenant url}").using(SPFx(this.context)); +const sp = spfi(...); // get a ref to the set const set = sp.termStore.groups.getById("338666a8-1111-2222-3333-f72471314e72").sets.getById("338666a8-1111-2222-3333-f72471314e72"); diff --git a/docs/sp/tenant-properties.md b/docs/sp/tenant-properties.md index b53ebb716..ee2f2cc4b 100644 --- a/docs/sp/tenant-properties.md +++ b/docs/sp/tenant-properties.md @@ -7,11 +7,11 @@ You can set, read, and remove tenant properties using the methods shown below: This method MUST be called in the context of the app catalog web or you will get an access denied message. ```TypeScript -import { spfi, SPFx } from "@pnp/sp"; +import { spfi } from "@pnp/sp"; import "@pnp/sp/appcatalog"; import "@pnp/sp/webs"; -const sp = spfi("{tenant url}").using(SPFx(this.context)); +const sp = spfi(...); const w = await sp.getTenantAppCatalogWeb(); @@ -31,7 +31,7 @@ import { spfi, SPFx, IStorageEntity } from "@pnp/sp"; import "@pnp/sp/appcatalog"; import "@pnp/sp/webs"; -const sp = spfi("{tenant url}").using(SPFx(this.context)); +const sp = spfi(...); const prop: IStorageEntity = await sp.web.getStorageEntity("Test1"); @@ -43,11 +43,11 @@ console.log(prop.Value); This method MUST be called in the context of the app catalog web or you will get an access denied message. ```TypeScript -import { spfi, SPFx } from "@pnp/sp"; +import { spfi } from "@pnp/sp"; import "@pnp/sp/appcatalog"; import "@pnp/sp/webs"; -const sp = spfi("{tenant url}").using(SPFx(this.context)); +const sp = spfi(...); const w = await sp.getTenantAppCatalogWeb(); diff --git a/docs/sp/user-custom-actions.md b/docs/sp/user-custom-actions.md index 5363e11dc..ca7e0fbcd 100644 --- a/docs/sp/user-custom-actions.md +++ b/docs/sp/user-custom-actions.md @@ -9,11 +9,11 @@ Represents a custom action associated with a SharePoint list, web or site collec ### Get a collection of User Custom Actions from a web ```TypeScript -import { spfi, SPFx } from "@pnp/sp"; +import { spfi } from "@pnp/sp"; import "@pnp/sp/webs"; import "@pnp/sp/user-custom-actions"; -const sp = spfi("{tenant url}").using(SPFx(this.context)); +const sp = spfi(...); const userCustomActions = sp.web.userCustomActions(); ``` @@ -21,12 +21,12 @@ const userCustomActions = sp.web.userCustomActions(); ### Add a new User Custom Action ```TypeScript -import { spfi, SPFx } from "@pnp/sp"; +import { spfi } from "@pnp/sp"; import "@pnp/sp/webs"; import "@pnp/sp/user-custom-actions"; import { IUserCustomActionAddResult } from '@pnp/sp/user-custom-actions'; -const sp = spfi("{tenant url}").using(SPFx(this.context)); +const sp = spfi(...); const newValues: TypedHash = { "Title": "New Title", @@ -41,11 +41,11 @@ const response : IUserCustomActionAddResult = await sp.web.userCustomActions.add ### Get a User Custom Action by ID ```TypeScript -import { spfi, SPFx } from "@pnp/sp"; +import { spfi } from "@pnp/sp"; import "@pnp/sp/webs"; import "@pnp/sp/user-custom-actions"; -const sp = spfi("{tenant url}").using(SPFx(this.context)); +const sp = spfi(...); const uca: IUserCustomAction = sp.web.userCustomActions.getById("00000000-0000-0000-0000-000000000000"); @@ -55,11 +55,11 @@ const ucaData = await uca(); ### Clear the User Custom Action collection ```TypeScript -import { spfi, SPFx } from "@pnp/sp"; +import { spfi } from "@pnp/sp"; import "@pnp/sp/webs"; import "@pnp/sp/user-custom-actions"; -const sp = spfi("{tenant url}").using(SPFx(this.context)); +const sp = spfi(...); // Site collection level await sp.site.userCustomActions.clear(); @@ -76,12 +76,12 @@ await sp.web.lists.getByTitle("Documents").userCustomActions.clear(); ### Update an existing User Custom Action ```TypeScript -import { spfi, SPFx } from "@pnp/sp"; +import { spfi } from "@pnp/sp"; import "@pnp/sp/webs"; import "@pnp/sp/user-custom-actions"; import { IUserCustomActionUpdateResult } from '@pnp/sp/user-custom-actions'; -const sp = spfi("{tenant url}").using(SPFx(this.context)); +const sp = spfi(...); const uca = sp.web.userCustomActions.getById("00000000-0000-0000-0000-000000000000"); diff --git a/docs/sp/views.md b/docs/sp/views.md index 1f27f830a..944bafd10 100644 --- a/docs/sp/views.md +++ b/docs/sp/views.md @@ -9,12 +9,12 @@ Views define the columns, ordering, and other details we see when we look at a l ### Get views in a list ```TypeScript -import { spfi, SPFx } from "@pnp/sp"; +import { spfi } from "@pnp/sp"; import "@pnp/sp/webs"; import "@pnp/sp/lists"; import "@pnp/sp/views"; -const sp = spfi("{tenant url}").using(SPFx(this.context)); +const sp = spfi(...); const list = sp.web.lists.getByTitle("My List"); @@ -31,12 +31,12 @@ const views3 = await list.views.top(3)(); ### Add a View ```TypeScript -import { spfi, SPFx } from "@pnp/sp"; +import { spfi } from "@pnp/sp"; import "@pnp/sp/webs"; import "@pnp/sp/lists"; import "@pnp/sp/views"; -const sp = spfi("{tenant url}").using(SPFx(this.context)); +const sp = spfi(...); const list = sp.web.lists.getByTitle("My List"); @@ -63,12 +63,12 @@ await Promise.all([ ### Get a View's Information ```TypeScript -import { spfi, SPFx } from "@pnp/sp"; +import { spfi } from "@pnp/sp"; import "@pnp/sp/webs"; import "@pnp/sp/lists"; import "@pnp/sp/views"; -const sp = spfi("{tenant url}").using(SPFx(this.context)); +const sp = spfi(...); const list = sp.web.lists.getByTitle("My List"); @@ -86,12 +86,12 @@ const result5 = await list.getView("{GUID view id}")(); ### fields ```TypeScript -import { spfi, SPFx } from "@pnp/sp"; +import { spfi } from "@pnp/sp"; import "@pnp/sp/webs"; import "@pnp/sp/lists"; import "@pnp/sp/views"; -const sp = spfi("{tenant url}").using(SPFx(this.context)); +const sp = spfi(...); const list = sp.web.lists.getByTitle("My List"); @@ -101,12 +101,12 @@ const result = await list.views.getById("{GUID view id}").fields(); ### update ```TypeScript -import { spfi, SPFx } from "@pnp/sp"; +import { spfi } from "@pnp/sp"; import "@pnp/sp/webs"; import "@pnp/sp/lists"; import "@pnp/sp/views"; -const sp = spfi("{tenant url}").using(SPFx(this.context)); +const sp = spfi(...); const list = sp.web.lists.getByTitle("My List"); @@ -118,12 +118,12 @@ const result = await list.views.getById("{GUID view id}").update({ ### renderAsHtml ```TypeScript -import { spfi, SPFx } from "@pnp/sp"; +import { spfi } from "@pnp/sp"; import "@pnp/sp/webs"; import "@pnp/sp/lists"; import "@pnp/sp/views"; -const sp = spfi("{tenant url}").using(SPFx(this.context)); +const sp = spfi(...); const result = await sp.web.lists.getByTitle("My List").views.getById("{GUID view id}").renderAsHtml(); ``` @@ -131,12 +131,12 @@ const result = await sp.web.lists.getByTitle("My List").views.getById("{GUID vie ### setViewXml ```TypeScript -import { spfi, SPFx } from "@pnp/sp"; +import { spfi } from "@pnp/sp"; import "@pnp/sp/webs"; import "@pnp/sp/lists"; import "@pnp/sp/views"; -const sp = spfi("{tenant url}").using(SPFx(this.context)); +const sp = spfi(...); const viewXml = "..."; @@ -146,12 +146,12 @@ await sp.web.lists.getByTitle("My List").views.getById("{GUID view id}").setView ### delete ```TypeScript -import { spfi, SPFx } from "@pnp/sp"; +import { spfi } from "@pnp/sp"; import "@pnp/sp/webs"; import "@pnp/sp/lists"; import "@pnp/sp/views"; -const sp = spfi("{tenant url}").using(SPFx(this.context)); +const sp = spfi(...); const viewXml = "..."; @@ -163,12 +163,12 @@ await sp.web.lists.getByTitle("My List").views.getById("{GUID view id}").delete( ### getSchemaXml ```TypeScript -import { spfi, SPFx } from "@pnp/sp"; +import { spfi } from "@pnp/sp"; import "@pnp/sp/webs"; import "@pnp/sp/lists"; import "@pnp/sp/views"; -const sp = spfi("{tenant url}").using(SPFx(this.context)); +const sp = spfi(...); const xml = await sp.web.lists.getByTitle("My List").defaultView.fields.getSchemaXml(); ``` @@ -176,12 +176,12 @@ const xml = await sp.web.lists.getByTitle("My List").defaultView.fields.getSchem ### add ```TypeScript -import { spfi, SPFx } from "@pnp/sp"; +import { spfi } from "@pnp/sp"; import "@pnp/sp/webs"; import "@pnp/sp/lists"; import "@pnp/sp/views"; -const sp = spfi("{tenant url}").using(SPFx(this.context)); +const sp = spfi(...); await sp.web.lists.getByTitle("My List").defaultView.fields.add("Created"); ``` @@ -189,12 +189,12 @@ await sp.web.lists.getByTitle("My List").defaultView.fields.add("Created"); ### move ```TypeScript -import { spfi, SPFx } from "@pnp/sp"; +import { spfi } from "@pnp/sp"; import "@pnp/sp/webs"; import "@pnp/sp/lists"; import "@pnp/sp/views"; -const sp = spfi("{tenant url}").using(SPFx(this.context)); +const sp = spfi(...); await sp.web.lists.getByTitle("My List").defaultView.fields.move("Created", 0); ``` @@ -202,12 +202,12 @@ await sp.web.lists.getByTitle("My List").defaultView.fields.move("Created", 0); ### remove ```TypeScript -import { spfi, SPFx } from "@pnp/sp"; +import { spfi } from "@pnp/sp"; import "@pnp/sp/webs"; import "@pnp/sp/lists"; import "@pnp/sp/views"; -const sp = spfi("{tenant url}").using(SPFx(this.context)); +const sp = spfi(...); await sp.web.lists.getByTitle("My List").defaultView.fields.remove("Created"); ``` @@ -215,12 +215,12 @@ await sp.web.lists.getByTitle("My List").defaultView.fields.remove("Created"); ### removeAll ```TypeScript -import { spfi, SPFx } from "@pnp/sp"; +import { spfi } from "@pnp/sp"; import "@pnp/sp/webs"; import "@pnp/sp/lists"; import "@pnp/sp/views"; -const sp = spfi("{tenant url}").using(SPFx(this.context)); +const sp = spfi(...); await sp.web.lists.getByTitle("My List").defaultView.fields.removeAll(); ``` diff --git a/docs/sp/webs.md b/docs/sp/webs.md index f94f24c62..039043667 100644 --- a/docs/sp/webs.md +++ b/docs/sp/webs.md @@ -11,10 +11,10 @@ Webs are one of the fundamental entry points when working with SharePoint. Webs Using the library you can add a web to another web's collection of subwebs. The simplest usage requires only a title and url. This will result in a team site with all of the default settings. You can also provide other settings such as description, template, language, and inherit permissions. ```TypeScript -import { spfi, SPFx } from "@pnp/sp"; +import { spfi } from "@pnp/sp"; import { IWebAddResult } from "@pnp/sp/webs"; -const sp = spfi("{tenant url}").using(SPFx(this.context)); +const sp = spfi(...); const result = await sp.web.webs.add("title", "subweb1"); @@ -30,10 +30,10 @@ result.web.select("Title")().then((w: IWebInfo) => { ``` ```TypeScript -import { spfi, SPFx } from "@pnp/sp"; +import { spfi } from "@pnp/sp"; import { IWebAddResult } from "@pnp/sp/webs"; -const sp = spfi("{tenant url}").using(SPFx(this.context)); +const sp = spfi(...); // create a German language wiki site with title, url, description, which does not inherit permissions sp.web.webs.add("wiki", "subweb2", "a wiki web", "WIKI#0", 1031, false).then((w: IWebAddResult) => { @@ -53,10 +53,10 @@ There are several ways to access a web instance, each of these methods is equiva **Access the web from the imported "spfi" object using selective import:** ```TypeScript -import { spfi, SPFx } from "@pnp/sp"; +import { spfi } from "@pnp/sp"; import "@pnp/sp/webs"; -const sp = spfi("{tenant url}").using(SPFx(this.context)); +const sp = spfi(...); const r = await sp.web(); ``` @@ -64,10 +64,10 @@ const r = await sp.web(); **Access the web from the imported "spfi" object using the 'all' preset** ```TypeScript -import { spfi, SPFx } from "@pnp/sp"; +import { spfi } from "@pnp/sp"; import "@pnp/sp/webs"; -const sp = spfi("{tenant url}").using(SPFx(this.context)); +const sp = spfi(...); const r = await sp.web(); ``` @@ -77,12 +77,12 @@ const r = await sp.web(); In this scenario you might be deep in your code without access to the original start of the fluid chain (i.e. the instance produced from spfi). You can pass any queryable to the Web or Site factory and get back a valid IWeb instance. In this case all of the observers registered to the supplied instance will be referenced by the IWeb, and the url will be rebased to ensure a valid path. ```TypeScript -import { spfi, SPFx } from "@pnp/sp"; +import { spfi } from "@pnp/sp"; import "@pnp/sp/webs"; import "@pnp/sp/lists"; import "@pnp/sp/items"; -const sp = spfi("{tenant url}").using(SPFx(this.context)); +const sp = spfi(...); // we have a ref to the IItems instance const items = await sp.web.lists.getByTitle("Generic").items; @@ -104,7 +104,7 @@ There are several ways to use the `Web` factory directly and have some special c > When in doubt, supply the absolute url to the web as the first parameter as shown in example 1 below ```TypeScript -import { spfi, SPFx } from "@pnp/sp"; +import { spfi } from "@pnp/sp"; import "@pnp/sp/webs"; // creates a web: @@ -140,10 +140,10 @@ const web4 = Web("https://tenant.sharepoint.com/sites/myweb", "_api/web/lists"); Access the child [webs collection](#Webs%20Collection) of this web ```TypeScript -import { spfi, SPFx } from "@pnp/sp"; +import { spfi } from "@pnp/sp"; import "@pnp/sp/webs"; -const sp = spfi("{tenant url}").using(SPFx(this.context)); +const sp = spfi(...); const web = sp.web; const webs = await web.webs(); @@ -152,10 +152,10 @@ const webs = await web.webs(); ### Get A Web's properties ```TypeScript -import { spfi, SPFx } from "@pnp/sp"; +import { spfi } from "@pnp/sp"; import "@pnp/sp/webs"; -const sp = spfi("{tenant url}").using(SPFx(this.context)); +const sp = spfi(...); // basic get of the webs properties const props = await sp.web(); @@ -172,10 +172,10 @@ const props3 = await sp.web.select("Title")<{ Title: string }>(); Get the data and IWeb instance for the parent web for the given web instance ```TypeScript -import { spfi, SPFx } from "@pnp/sp"; +import { spfi } from "@pnp/sp"; import "@pnp/sp/webs"; -const sp = spfi("{tenant url}").using(SPFx(this.context)); +const sp = spfi(...); const web = web.getParentWeb(); ``` @@ -184,10 +184,10 @@ const web = web.getParentWeb(); Returns a collection of objects that contain metadata about subsites of the current site in which the current user is a member. ```TypeScript -import { spfi, SPFx } from "@pnp/sp"; +import { spfi } from "@pnp/sp"; import "@pnp/sp/webs"; -const sp = spfi("{tenant url}").using(SPFx(this.context)); +const sp = spfi(...); const web = sp.web; const subWebs = web.getSubwebsFilteredForCurrentUser()(); @@ -203,10 +203,10 @@ const subWebs2 = await sp.web.getSubwebsFilteredForCurrentUser().select("Title", Allows access to the web's all properties collection. This is readonly in REST. ```TypeScript -import { spfi, SPFx } from "@pnp/sp"; +import { spfi } from "@pnp/sp"; import "@pnp/sp/webs"; -const sp = spfi("{tenant url}").using(SPFx(this.context)); +const sp = spfi(...); const web = sp.web; const props = await web.allProperties(); @@ -220,10 +220,10 @@ const props2 = await web.allProperties.select("prop1", "prop2")(); Gets a collection of WebInfos for this web's subwebs ```TypeScript -import { spfi, SPFx } from "@pnp/sp"; +import { spfi } from "@pnp/sp"; import "@pnp/sp/webs"; -const sp = spfi("{tenant url}").using(SPFx(this.context)); +const sp = spfi(...); const web = sp.web; const infos = await web.webinfos(); @@ -248,10 +248,10 @@ const infos5 = await web.webinfos.top(4).orderBy("Title")(); Updates this web instance with the supplied properties ```TypeScript -import { spfi, SPFx } from "@pnp/sp"; +import { spfi } from "@pnp/sp"; import "@pnp/sp/webs"; -const sp = spfi("{tenant url}").using(SPFx(this.context)); +const sp = spfi(...); const web = sp.web; // update the web's title and description const result = await web.update({ @@ -274,10 +274,10 @@ function updateWeb(props: IWebUpdateProps): Promise { ### Delete a Web ```TypeScript -import { spfi, SPFx } from "@pnp/sp"; +import { spfi } from "@pnp/sp"; import "@pnp/sp/webs"; -const sp = spfi("{tenant url}").using(SPFx(this.context)); +const sp = spfi(...); const web = sp.web; await web.delete(); @@ -288,7 +288,7 @@ await web.delete(); Applies the theme specified by the contents of each of the files specified in the arguments to the site ```TypeScript -import { spfi, SPFx } from "@pnp/sp"; +import { spfi } from "@pnp/sp"; import "@pnp/sp/webs"; import { combine } from "@pnp/core"; @@ -310,10 +310,10 @@ await web.applyTheme(colorUrl, fontUrl, "", false); Applies the specified site definition or site template to the Web site that has no template applied to it. This is seldom used outside provisioning scenarios. ```TypeScript -import { spfi, SPFx } from "@pnp/sp"; +import { spfi } from "@pnp/sp"; import "@pnp/sp/webs"; -const sp = spfi("{tenant url}").using(SPFx(this.context)); +const sp = spfi(...); const web = sp.web; const templates = (await web.availableWebTemplates().select("Name")<{ Name: string }[]>()).filter(t => /ENTERWIKI#0/i.test(t.Name)); @@ -328,10 +328,10 @@ await web.applyWebTemplate(template); Returns the collection of changes from the change log that have occurred within the web, based on the specified query. ```TypeScript -import { spfi, SPFx } from "@pnp/sp"; +import { spfi } from "@pnp/sp"; import "@pnp/sp/webs"; -const sp = spfi("{tenant url}").using(SPFx(this.context)); +const sp = spfi(...); const web = sp.web; // get the web changes including add, update, and delete const changes = await web.getChanges({ @@ -349,7 +349,7 @@ const changes = await web.getChanges({ Returns the name of the image file for the icon that is used to represent the specified file ```TypeScript -import { spfi, SPFx } from "@pnp/sp"; +import { spfi } from "@pnp/sp"; import "@pnp/sp/webs"; import { combine } from "@pnp/core"; @@ -359,7 +359,7 @@ const iconFileName = await web.mapToIcon("test.docx"); const iconFullPath = `https://{tenant}.sharepoint.com/sites/dev/_layouts/images/${iconFileName}`; // OR dynamically -const sp = spfi("{tenant url}").using(SPFx(this.context)); +const sp = spfi(...); const webData = await sp.web.select("Url")(); const iconFullPath2 = combine(webData.Url, "_layouts", "images", iconFileName); @@ -374,7 +374,7 @@ const icon32FileName = await web.mapToIcon("test.docx", 1); ### storage entities ```TypeScript -import { spfi, SPFx } from "@pnp/sp"; +import { spfi } from "@pnp/sp"; import "@pnp/sp/webs"; import "@pnp/sp/appcatalog"; import { IStorageEntity } from "@pnp/sp/webs"; @@ -382,7 +382,7 @@ import { IStorageEntity } from "@pnp/sp/webs"; // needs to be unique, GUIDs are great const key = "my-storage-key"; -const sp = spfi("{tenant url}").using(SPFx(this.context)); +const sp = spfi(...); // read an existing entity const entity: IStorageEntity = await sp.web.getStorageEntity(key); @@ -414,11 +414,11 @@ await tenantAppCatalogWeb.removeStorageEntity(key); Returns this web as an IAppCatalog instance or creates a new IAppCatalog instance from the provided url. ```TypeScript -import { spfi, SPFx } from "@pnp/sp"; +import { spfi } from "@pnp/sp"; import "@pnp/sp/webs"; import { IApp } from "@pnp/sp/appcatalog"; -const sp = spfi("{tenant url}").using(SPFx(this.context)); +const sp = spfi(...); const appWeb = sp.web.appcatalog; const app: IApp = appWeb.getAppById("{your app id}"); @@ -430,11 +430,11 @@ const app: IApp = appWeb.getAppById("{your app id}"); You can create and load clientside page instances directly from a web. More details on [working with clientside pages](clientside-pages.md) are available in the dedicated article. ```TypeScript -import { spfi, SPFx } from "@pnp/sp"; +import { spfi } from "@pnp/sp"; import "@pnp/sp/webs"; import "@pnp/sp/clientside-pages/web"; -const sp = spfi("{tenant url}").using(SPFx(this.context)); +const sp = spfi(...); // simplest add a page example const page = await sp.web.addClientsidePage("mypage1"); @@ -448,11 +448,11 @@ const page = await sp.web.loadClientsidePage("/sites/dev/sitepages/mypage3.aspx" Allows access to the collection of content types in this web. ```TypeScript -import { spfi, SPFx } from "@pnp/sp"; +import { spfi } from "@pnp/sp"; import "@pnp/sp/webs"; import "@pnp/sp/content-types/web"; -const sp = spfi("{tenant url}").using(SPFx(this.context)); +const sp = spfi(...); const cts = await sp.web.contentTypes(); @@ -465,11 +465,11 @@ const cts2 = await sp.web.contentTypes.select("Name")(); Allows access to the collection of content types in this web. ```TypeScript -import { spfi, SPFx } from "@pnp/sp"; +import { spfi } from "@pnp/sp"; import "@pnp/sp/webs"; import "@pnp/sp/features/web"; -const sp = spfi("{tenant url}").using(SPFx(this.context)); +const sp = spfi(...); const features = await sp.web.features(); ``` @@ -479,11 +479,11 @@ const features = await sp.web.features(); Allows access to the collection of fields in this web. ```TypeScript -import { spfi, SPFx } from "@pnp/sp"; +import { spfi } from "@pnp/sp"; import "@pnp/sp/webs"; import "@pnp/sp/fields/web"; -const sp = spfi("{tenant url}").using(SPFx(this.context)); +const sp = spfi(...); const fields = await sp.web.fields(); ``` @@ -492,12 +492,12 @@ const fields = await sp.web.fields(); Gets a file by server relative url if your file name contains # and % characters ```TypeScript -import { spfi, SPFx } from "@pnp/sp"; +import { spfi } from "@pnp/sp"; import "@pnp/sp/webs"; import "@pnp/sp/files/web"; import { IFile } from "@pnp/sp/files/types"; -const sp = spfi("{tenant url}").using(SPFx(this.context)); +const sp = spfi(...); const file: IFile = web.getFileByServerRelativePath("/sites/dev/library/my # file%.docx"); ``` @@ -506,11 +506,11 @@ const file: IFile = web.getFileByServerRelativePath("/sites/dev/library/my # fil Gets the collection of folders in this web ```TypeScript -import { spfi, SPFx } from "@pnp/sp"; +import { spfi } from "@pnp/sp"; import "@pnp/sp/webs"; import "@pnp/sp/folders/web"; -const sp = spfi("{tenant url}").using(SPFx(this.context)); +const sp = spfi(...); const folders = await sp.web.folders(); @@ -526,11 +526,11 @@ const folders2 = await sp.web.folders.orderBy("TimeLastModified").top(1)(); Gets the root folder of the web ```TypeScript -import { spfi, SPFx } from "@pnp/sp"; +import { spfi } from "@pnp/sp"; import "@pnp/sp/webs"; import "@pnp/sp/folders/web"; -const sp = spfi("{tenant url}").using(SPFx(this.context)); +const sp = spfi(...); const folder = await sp.web.rootFolder(); ``` @@ -540,12 +540,12 @@ const folder = await sp.web.rootFolder(); Gets a folder by server relative url if your folder name contains # and % characters ```TypeScript -import { spfi, SPFx } from "@pnp/sp"; +import { spfi } from "@pnp/sp"; import "@pnp/sp/webs"; import "@pnp/sp/folders/web"; import { IFolder } from "@pnp/sp/folders"; -const sp = spfi("{tenant url}").using(SPFx(this.context)); +const sp = spfi(...); const folder: IFolder = web.getFolderByServerRelativePath("/sites/dev/library/my # folder%/"); ``` @@ -555,11 +555,11 @@ const folder: IFolder = web.getFolderByServerRelativePath("/sites/dev/library/my Gets hub site data for the current web ```TypeScript -import { spfi, SPFx } from "@pnp/sp"; +import { spfi } from "@pnp/sp"; import "@pnp/sp/webs"; import "@pnp/sp/hubsites/web"; -const sp = spfi("{tenant url}").using(SPFx(this.context)); +const sp = spfi(...); // get the data and force a refresh const data = await sp.web.hubSiteData(true); ``` @@ -569,11 +569,11 @@ const data = await sp.web.hubSiteData(true); Applies theme updates from the parent hub site collection ```TypeScript -import { spfi, SPFx } from "@pnp/sp"; +import { spfi } from "@pnp/sp"; import "@pnp/sp/webs"; import "@pnp/sp/hubsites/web"; -const sp = spfi("{tenant url}").using(SPFx(this.context)); +const sp = spfi(...); await sp.web.syncHubSiteTheme(); ``` @@ -582,12 +582,12 @@ await sp.web.syncHubSiteTheme(); Gets the collection of all lists that are contained in the Web site ```TypeScript -import { spfi, SPFx } from "@pnp/sp"; +import { spfi } from "@pnp/sp"; import "@pnp/sp/webs"; import "@pnp/sp/lists/web"; import { ILists } from "@pnp/sp/lists"; -const sp = spfi("{tenant url}").using(SPFx(this.context)); +const sp = spfi(...); const lists: ILists = sp.web.lists; // you can always order the lists and select properties @@ -602,12 +602,12 @@ const data2 = await sp.web.lists.top(3).orderBy("LastItemModifiedDate")(); Gets the UserInfo list of the site collection that contains the Web site ```TypeScript -import { spfi, SPFx } from "@pnp/sp"; +import { spfi } from "@pnp/sp"; import "@pnp/sp/webs"; import "@pnp/sp/lists/web"; import { IList } from "@pnp/sp/lists"; -const sp = spfi("{tenant url}").using(SPFx(this.context)); +const sp = spfi(...); const list: IList = sp.web.siteUserInfoList; const data = await list(); @@ -621,11 +621,11 @@ const items = await list.items.top(2)(); Get a reference the default documents library of a web ```TypeScript -import { spfi, SPFx } from "@pnp/sp"; +import { spfi } from "@pnp/sp"; import "@pnp/sp/webs"; import { IList } from "@pnp/sp/lists/web"; -const sp = spfi("{tenant url}").using(SPFx(this.context)); +const sp = spfi(...); const list: IList = sp.web.defaultDocumentLibrary; ``` @@ -634,12 +634,12 @@ const list: IList = sp.web.defaultDocumentLibrary; Gets the collection of all list definitions and list templates that are available ```TypeScript -import { spfi, SPFx } from "@pnp/sp"; +import { spfi } from "@pnp/sp"; import "@pnp/sp/webs"; import "@pnp/sp/lists/web"; import { IList } from "@pnp/sp/lists"; -const sp = spfi("{tenant url}").using(SPFx(this.context)); +const sp = spfi(...); const templates = await sp.web.customListTemplates(); // odata operators chain off the collection as expected @@ -651,11 +651,11 @@ const templates2 = await sp.web.customListTemplates.select("Title")(); Gets a list by server relative url (list's root folder) ```TypeScript -import { spfi, SPFx } from "@pnp/sp"; +import { spfi } from "@pnp/sp"; import "@pnp/sp/webs"; import { IList } from "@pnp/sp/lists/web"; -const sp = spfi("{tenant url}").using(SPFx(this.context)); +const sp = spfi(...); const list: IList = sp.web.getList("/sites/dev/lists/test"); const listData = await list(); @@ -677,11 +677,11 @@ DesignCatalog | 124 AppDataCatalog | 125 ```TypeScript -import { spfi, SPFx } from "@pnp/sp"; +import { spfi } from "@pnp/sp"; import "@pnp/sp/webs"; import { IList } from "@pnp/sp/lists"; -const sp = spfi("{tenant url}").using(SPFx(this.context)); +const sp = spfi(...); const templateCatalog: IList = await sp.web.getCatalog(111); const themeCatalog: IList = await sp.web.getCatalog(123); @@ -692,34 +692,34 @@ const themeCatalog: IList = await sp.web.getCatalog(123); Gets a navigation object that represents navigation on the Web site, including the Quick Launch area and the top navigation bar ```TypeScript -import { spfi, SPFx } from "@pnp/sp"; +import { spfi } from "@pnp/sp"; import "@pnp/sp/webs"; import "@pnp/sp/navigation/web"; import { INavigation } from "@pnp/sp/navigation"; -const sp = spfi("{tenant url}").using(SPFx(this.context)); +const sp = spfi(...); const nav: INavigation = sp.web.navigation; ``` ```TypeScript -import { spfi, SPFx } from "@pnp/sp"; +import { spfi } from "@pnp/sp"; import "@pnp/sp/webs"; import "@pnp/sp/navigation/web"; import { IRegionalSettings } from "@pnp/sp/navigation"; -const sp = spfi("{tenant url}").using(SPFx(this.context)); +const sp = spfi(...); const settings: IRegionalSettings = sp.web.regionalSettings; const settingsData = await settings(); ``` ```TypeScript -import { spfi, SPFx } from "@pnp/sp"; +import { spfi } from "@pnp/sp"; import "@pnp/sp/webs"; import "@pnp/sp/related-items/web"; import { IRelatedItemManager, IRelatedItem } from "@pnp/sp/related-items"; -const sp = spfi("{tenant url}").using(SPFx(this.context)); +const sp = spfi(...); const manager: IRelatedItemManager = sp.web.relatedItems; const data: IRelatedItem[] = await manager.getRelatedItems("{list name}", 4); @@ -738,11 +738,11 @@ Please see information around the available sharing methods in the [sharing arti The site groups ```TypeScript -import { spfi, SPFx } from "@pnp/sp"; +import { spfi } from "@pnp/sp"; import "@pnp/sp/webs"; import "@pnp/sp/site-groups/web"; -const sp = spfi("{tenant url}").using(SPFx(this.context)); +const sp = spfi(...); const groups = await sp.web.siteGroups(); const groups2 = await sp.web.siteGroups.top(2)(); @@ -753,11 +753,11 @@ const groups2 = await sp.web.siteGroups.top(2)(); The web's owner group ```TypeScript -import { spfi, SPFx } from "@pnp/sp"; +import { spfi } from "@pnp/sp"; import "@pnp/sp/webs"; import "@pnp/sp/site-groups/web"; -const sp = spfi("{tenant url}").using(SPFx(this.context)); +const sp = spfi(...); const group = await sp.web.associatedOwnerGroup(); @@ -769,11 +769,11 @@ const users = await sp.web.associatedOwnerGroup.users(); The web's member group ```TypeScript -import { spfi, SPFx } from "@pnp/sp"; +import { spfi } from "@pnp/sp"; import "@pnp/sp/webs"; import "@pnp/sp/site-groups/web"; -const sp = spfi("{tenant url}").using(SPFx(this.context)); +const sp = spfi(...); const group = await sp.web.associatedMemberGroup(); @@ -785,11 +785,11 @@ const users = await sp.web.associatedMemberGroup.users(); The web's visitor group ```TypeScript -import { spfi, SPFx } from "@pnp/sp"; +import { spfi } from "@pnp/sp"; import "@pnp/sp/webs"; import "@pnp/sp/site-groups/web"; -const sp = spfi("{tenant url}").using(SPFx(this.context)); +const sp = spfi(...); const group = await sp.web.associatedVisitorGroup(); @@ -801,11 +801,11 @@ const users = await sp.web.associatedVisitorGroup.users(); Creates the default associated groups (Members, Owners, Visitors) and gives them the default permissions on the site. The target site must have unique permissions and no associated members / owners / visitors groups ```TypeScript -import { spfi, SPFx } from "@pnp/sp"; +import { spfi } from "@pnp/sp"; import "@pnp/sp/webs"; import "@pnp/sp/site-groups/web"; -const sp = spfi("{tenant url}").using(SPFx(this.context)); +const sp = spfi(...); await sp.web.createDefaultAssociatedGroups("Contoso", "{first owner login}"); @@ -824,11 +824,11 @@ await sp.web.createDefaultAssociatedGroups("Contoso", "{first owner login}", fal The site users ```TypeScript -import { spfi, SPFx } from "@pnp/sp"; +import { spfi } from "@pnp/sp"; import "@pnp/sp/webs"; import "@pnp/sp/site-users/web"; -const sp = spfi("{tenant url}").using(SPFx(this.context)); +const sp = spfi(...); const users = await sp.web.siteUsers(); @@ -842,11 +842,11 @@ const users3 = await sp.web.siteUsers.filter(`startswith(LoginName, '${encodeURI Information on the current user ```TypeScript -import { spfi, SPFx } from "@pnp/sp"; +import { spfi } from "@pnp/sp"; import "@pnp/sp/webs"; import "@pnp/sp/site-users/web"; -const sp = spfi("{tenant url}").using(SPFx(this.context)); +const sp = spfi(...); const user = await sp.web.currentUser(); @@ -859,12 +859,12 @@ const user2 = await sp.web.currentUser.select("LoginName")(); Checks whether the specified login name belongs to a valid user in the web. If the user doesn't exist, adds the user to the web ```TypeScript -import { spfi, SPFx } from "@pnp/sp"; +import { spfi } from "@pnp/sp"; import "@pnp/sp/webs"; import "@pnp/sp/site-users/web"; import { IWebEnsureUserResult } from "@pnp/sp/site-users/"; -const sp = spfi("{tenant url}").using(SPFx(this.context)); +const sp = spfi(...); const result: IWebEnsureUserResult = await sp.web.ensureUser("i:0#.f|membership|user@domain.onmicrosoft.com"); ``` @@ -874,12 +874,12 @@ const result: IWebEnsureUserResult = await sp.web.ensureUser("i:0#.f|membership| Returns the user corresponding to the specified member identifier for the current web ```TypeScript -import { spfi, SPFx } from "@pnp/sp"; +import { spfi } from "@pnp/sp"; import "@pnp/sp/webs"; import "@pnp/sp/site-users/web"; import { ISiteUser } from "@pnp/sp/site-users/"; -const sp = spfi("{tenant url}").using(SPFx(this.context)); +const sp = spfi(...); const user: ISiteUser = sp.web.getUserById(23); @@ -893,12 +893,12 @@ const userData2 = await user.select("LoginName")(); Gets a newly refreshed collection of the SPWeb's SPUserCustomActionCollection ```TypeScript -import { spfi, SPFx } from "@pnp/sp"; +import { spfi } from "@pnp/sp"; import "@pnp/sp/webs"; import "@pnp/sp/user-custom-actions/web"; import { IUserCustomActions } from "@pnp/sp/user-custom-actions"; -const sp = spfi("{tenant url}").using(SPFx(this.context)); +const sp = spfi(...); const actions: IUserCustomActions = sp.web.userCustomActions; diff --git a/docs/transition-guide.md b/docs/transition-guide.md index 84ca8962c..773de8002 100644 --- a/docs/transition-guide.md +++ b/docs/transition-guide.md @@ -69,10 +69,12 @@ const spWebC = spfi("{Other Web URL}").using(AssignFrom(sp.web)); // Create a new instance of Queryable using other credentials? const spWebD = spfi("{Other Web URL}").using(SPFx(this.context)); -// as well you can use the tuple pattern and the Web contructor, which will copy all the observers from the object but set the url to the one provided -const spWebE = Web([spWebA, "{Other Web URL}"]).using(SPFx(this.context)); +// as well you can use the tuple pattern and the Web constructor, which will copy all the observers from the object but set the url to the one provided +const spWebE = Web([spWebA.web, "{Absolute URL of Other Web}"]); ``` +Please see the documentation for more information on the updated [Web constructor](./sp/webs.md). + ## Dropping -Commonjs Packages -Starting with v3 we are dropping the commonjs versions of all packages. Previously we released these as we worked to transition to esm and the current node didn't yet support esm. With esm now a supported module type, and having done the work to ensure they work in node we feel it is a good time to drop the -commonjs variants. +Starting with v3 we are dropping the commonjs versions of all packages. Previously we released these as we worked to transition to esm and the current node didn't yet support esm. With esm now a supported module type, and having done the work to ensure they work in node we feel it is a good time to drop the -commonjs variants. Please see documentation on [Getting started with NodeJS Project using TypeScript producing CommonJS modules](getting-started.md#node-project-using-typescript-producing-commonjs-modules) diff --git a/packages/graph/presets/all.ts b/packages/graph/presets/all.ts index 726890c8d..fb88027f1 100644 --- a/packages/graph/presets/all.ts +++ b/packages/graph/presets/all.ts @@ -1,5 +1,6 @@ import "../attachments/index.js"; import "../calendars/index.js"; +import "../cloud-communications/index.js"; import "../contacts/index.js"; import "../conversations/index.js"; import "../directory-objects/index.js"; @@ -19,6 +20,7 @@ import "../users/index.js"; export * from "../attachments/index.js"; export * from "../calendars/index.js"; +export * from "../cloud-communications/index.js"; export * from "../contacts/index.js"; export * from "../conversations/index.js"; export * from "../directory-objects/index.js";