diff --git a/CHANGELOG.md b/CHANGELOG.md index 128faff86..ebf4c0d66 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -39,6 +39,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0. - ./operations.ts methods moved to ./spqueryable.ts - startUpload, continueUpload, finishUpload File protected methods removed - removed legacy support for @target query param + - removed "favorites", please use graph favorites - nodejs - removed stream extensions, moved into sp diff --git a/docs/sp/favorites.md b/docs/sp/favorites.md deleted file mode 100644 index c1c4ba55d..000000000 --- a/docs/sp/favorites.md +++ /dev/null @@ -1,91 +0,0 @@ -# @pnp/sp/ - favorites - -[![Selective Imports Banner](https://img.shields.io/badge/Selective%20Imports-informational.svg)](../concepts/selective-imports.md) - -The favorites API allows you to fetch and manipulate followed sites and list items (also called _saved for later_). Note, all of these methods only work with the context of a logged in user, and not with app-only permissions. - -## Get current user's followed sites - -```TypeScript -import { spfi } from "@pnp/sp"; -import "@pnp/sp/favorites"; - -const sp = spfi(...); - -const favSites = await sp.favorites.getFollowedSites(); -``` - -## Add a site to current user's followed sites - -```TypeScript -import { spfi } from "@pnp/sp"; -import "@pnp/sp/favorites"; - -const sp = spfi(...); - -const tenantUrl = "contoso.sharepoint.com"; -const siteId = "e3913de9-bfee-4089-b1bc-fb147d302f11"; -const webId = "11a53c2b-0a67-46c8-8599-db50b8bc4dd1" -const webUrl = "https://contoso.sharepoint.com/sites/favsite" - -const favSiteInfo = await sp.favorites.getFollowedSites.add(tenantUrl, siteId, webId, webUrl); -``` - -## Remove a site from current user's followed sites - -```TypeScript -import { spfi } from "@pnp/sp"; -import "@pnp/sp/favorites"; - -const sp = spfi(...); - -const tenantUrl = "contoso.sharepoint.com"; -const siteId = "e3913de9-bfee-4089-b1bc-fb147d302f11"; -const webId = "11a53c2b-0a67-46c8-8599-db50b8bc4dd1" -const webUrl = "https://contoso.sharepoint.com/sites/favsite" - -await sp.favorites.getFollowedSites.remove(tenantUrl, siteId, webId, webUrl); -``` - -## Get current user's followed list items - -```TypeScript -import { spfi } from "@pnp/sp"; -import "@pnp/sp/favorites"; - -const sp = spfi(...); - -const favListItems = await sp.favorites.getFollowedListItems(); -``` - -## Add an item to current user's followed list items - -```TypeScript -import { spfi } from "@pnp/sp"; -import "@pnp/sp/favorites"; - -const sp = spfi(...); - -const siteId = "e3913de9-bfee-4089-b1bc-fb147d302f11"; -const webId = "11a53c2b-0a67-46c8-8599-db50b8bc4dd1"; -const listId = "f09fe67e-0160-4fcc-9144-905bd4889f31"; -const listItemUniqueId = "1425C841-626A-44C9-8731-DA8BDC0882D1"; - -const favListItemInfo = await sp.favorites.getFollowedListItems.add(siteId, webId, listId, listItemUniqueId); -``` - -## Remove an item from current user's followed list items - -```TypeScript -import { spfi } from "@pnp/sp"; -import "@pnp/sp/favorites"; - -const sp = spfi(...); - -const siteId = "e3913de9-bfee-4089-b1bc-fb147d302f11"; -const webId = "11a53c2b-0a67-46c8-8599-db50b8bc4dd1"; -const listId = "f09fe67e-0160-4fcc-9144-905bd4889f31"; -const listItemUniqueId = "1425C841-626A-44C9-8731-DA8BDC0882D1"; - -const favListItemInfo = await sp.favorites.getFollowedListItems.remove(siteId, webId, listId, listItemUniqueId); -``` \ No newline at end of file diff --git a/mkdocs.yml b/mkdocs.yml index 67db74852..c9af784e8 100644 --- a/mkdocs.yml +++ b/mkdocs.yml @@ -98,7 +98,6 @@ nav: - 'comments and likes': 'sp/comments-likes.md' - 'content types': 'sp/content-types.md' - 'context info': 'sp/context-info.md' - - Favorites: 'sp/favorites.md' - Features: 'sp/features.md' - Fields: 'sp/fields.md' - Files: 'sp/files.md' diff --git a/packages/sp/favorites/index.ts b/packages/sp/favorites/index.ts deleted file mode 100644 index 9340e0c61..000000000 --- a/packages/sp/favorites/index.ts +++ /dev/null @@ -1,32 +0,0 @@ -import { SPFI } from "../fi.js"; -import { Favorites, IFavorites} from "./types.js"; - -export { - IFavorites, - Favorites, - IFollowedSites, - IFollowedSiteInfo, - IFollowedExchangeId, - IFollowedListItems, - IFollowedListItemInfo, - IFavoritesResourceVisualization, - IFavoritesUser, -} from "./types.js"; - - -declare module "../fi" { - interface SPFI { - /** - * Access to the favorites instance which allows you to track followed sites and items. - */ - readonly favorites: IFavorites; - } -} - -Reflect.defineProperty(SPFI.prototype, "favorites", { - configurable: true, - enumerable: true, - get: function (this: SPFI) { - return this.create(Favorites); - }, -}); diff --git a/packages/sp/favorites/types.ts b/packages/sp/favorites/types.ts deleted file mode 100644 index b8e21106e..000000000 --- a/packages/sp/favorites/types.ts +++ /dev/null @@ -1,186 +0,0 @@ -import { defaultPath } from "../decorators.js"; -import { _SPInstance, spInvokableFactory, _SPCollection, SPInit, spPost } from "../spqueryable.js"; -import { hOP } from "@pnp/core"; -import { body } from "@pnp/queryable"; -import { SharepointIds, ResourceVisualization } from "@microsoft/microsoft-graph-types"; - -@defaultPath("_api/v2.1/favorites") -export class _Favorites extends _SPInstance implements IFavorites { - public get followedSites(): IFollowedSites { - return FollowedSites(this); - } - - public get followedListItems(): IFollowedListItems { - return FollowedListItems(this); - } -} - -export const Favorites = (baseUrl: SPInit): IFavorites => new _Favorites(baseUrl); - -@defaultPath("followedSites") -export class _FollowedSites extends _SPCollection { - /** - * Adds a site to user's followed sites - * - * @param tenantUrl Name of a tenant (e.g. yourtenant.sharepoint.com). - * @param siteId Id of a site collection. - * @param webId Id of a site. - * @param webUrl Absolute URL of a site. - */ - public async add(tenantUrl: string, siteId: string, webId: string, webUrl: string): Promise { - const data = await spPost(FollowedListItems(this, "oneDrive.add"), body( - { - value: [ - { - id: [tenantUrl,webId,siteId].join(","), - webUrl: webUrl, - }, - ], - } - )); - return hOP(data, "value") ? data.value : data; - } - - /** - * Removes a site from user's followed sites - * - * @param tenantUrl Name of a tenant (e.g. yourtenant.sharepoint.com). - * @param siteId Id of a site collection. - * @param webId Id of a site. - * @param webUrl Absolute URL of a site. - */ - public async remove(tenantUrl: string, siteId: string, webId: string, webUrl: string): Promise { - - await spPost(FollowedListItems(this, "oneDrive.remove"), body( - { - value: [ - { - id: [tenantUrl,webId,siteId].join(","), - webUrl: webUrl, - }, - ], - } - )); - } -} - -export interface IFollowedSites extends _FollowedSites { } -export const FollowedSites = spInvokableFactory(_FollowedSites); - -@defaultPath("followedListItems") -export class _FollowedListItems extends _SPCollection { - /** - * Adds an item to user's _saved for later_ list - * - * @param siteId Id of a site collection of an item to add - * @param webId Id of a site of an item to add - * @param listId Id of a list of an item to add - * @param listItemUniqueId Unique id of an item to add - */ - public async add(siteId: string, webId: string, listId: string, listItemUniqueId: string): Promise { - const data = await spPost(FollowedListItems(this, "oneDrive.add"), body( - { - value: [ - { - siteId: siteId, - webId: webId, - listId: listId, - listItemUniqueId: listItemUniqueId, - }, - ], - } - )); - return hOP(data, "value") ? data.value : data; - } - - /** - * Removes an item from user's _saved for later_ list - * - * @param siteId Id of a site collection of an item to remove - * @param webId Id of a site of an item to remove - * @param listId Id of a list of an item to remove - * @param listItemUniqueId Unique id of an item to remove - */ - public async remove(siteId: string, webId: string, listId: string, listItemUniqueId: string): Promise { - await spPost(FollowedListItems(this, "oneDrive.remove"), body( - { - value: [ - { - siteId: siteId, - webId: webId, - listId: listId, - listItemUniqueId: listItemUniqueId, - }, - ], - } - )); - } -} - -export interface IFollowedListItems extends _FollowedListItems { } -export const FollowedListItems = spInvokableFactory(_FollowedListItems); - -export interface IFavorites { - readonly followedSites: IFollowedSites; - readonly followedListItems: IFollowedListItems; -} - -export interface IFollowedSiteInfo { - id: string; - webUrl: string; - title: string; - sharepointIds: SharepointIds; - siteCollection: { - hostName: string; - }; - template: any; - exchangeIds: IFollowedExchangeId; - resourceVisualization: { - color: string; - }; -} - -export interface IFollowedListItemInfo { - description: string; - id: string; - lastModifiedDateTime: string; - name: string; - size: number; - webUrl: string; - serverRedirectedUrl: string; - contentClass: string; - lastModifiedBy: { - user: IFavoritesUser; - }; - sharepointIds: SharepointIds; - contentType: { - id: string; - }; - resourceVisualization: IFavoritesResourceVisualization; - exchangeIds: IFollowedExchangeId; - followed: { - followedDateTime: string; - }; - file: { - fileExtension: string; - }; - news: { - publishedDateTime: string; - newsType: string; - author: IFavoritesUser; - }; -} - -export interface IFavoritesResourceVisualization extends ResourceVisualization { - color: string; -} - -export interface IFollowedExchangeId { - id: string; - documentId: string; -} - -export interface IFavoritesUser { - displayName: string; - userPrincipalName: string; -} diff --git a/packages/sp/presets/all.ts b/packages/sp/presets/all.ts index c1fb87c74..011602395 100644 --- a/packages/sp/presets/all.ts +++ b/packages/sp/presets/all.ts @@ -4,7 +4,6 @@ import "../clientside-pages/index.js"; import "../column-defaults/index.js"; import "../comments/index.js"; import "../content-types/index.js"; -import "../favorites/index.js"; import "../features/index.js"; import "../fields/index.js"; import "../files/index.js"; @@ -40,7 +39,6 @@ export * from "../clientside-pages/index.js"; export * from "../column-defaults/index.js"; export * from "../comments/index.js"; export * from "../content-types/index.js"; -export * from "../favorites/index.js"; export * from "../features/index.js"; export * from "../fields/index.js"; export * from "../files/index.js"; diff --git a/test/sp/favorites.ts b/test/sp/favorites.ts deleted file mode 100644 index ac5ef5031..000000000 --- a/test/sp/favorites.ts +++ /dev/null @@ -1,2 +0,0 @@ -// we cannot test favorites as they rely on a current user and an app doesn't work -describe("Favorites", () => void(0));