UNPKG

@pnp/sp

Version:

pnp - provides a fluent api for working with SharePoint REST

359 lines • 13 kB
import { __decorate } from "tslib"; import { _SPInstance, SPCollection, spInvokableFactory, _SPQueryable, } from "../spqueryable.js"; import { body } from "@pnp/queryable"; import { defaultPath } from "../decorators.js"; import { spPost } from "../operations.js"; import { AssignFrom } from "@pnp/core"; export class _Profiles extends _SPInstance { /** * Creates a new instance of the UserProfileQuery class * * @param baseUrl The url or SharePointQueryable which forms the parent of this user profile query */ constructor(baseUrl, path = "_api/sp.userprofiles.peoplemanager") { super(baseUrl, path); this.clientPeoplePickerQuery = (new ClientPeoplePickerQuery(baseUrl)).using(AssignFrom(this)); this.profileLoader = (new ProfileLoader(baseUrl)).using(AssignFrom(this)); } /** * The url of the edit profile page for the current user */ getEditProfileLink() { return Profiles(this, "EditProfileLink")(); } /** * A boolean value that indicates whether the current user's "People I'm Following" list is public */ getIsMyPeopleListPublic() { return Profiles(this, "IsMyPeopleListPublic")(); } /** * A boolean value that indicates whether the current user is being followed by the specified user * * @param loginName The account name of the user */ amIFollowedBy(loginName) { const q = Profiles(this, "amifollowedby(@v)"); q.query.set("@v", `'${encodeURIComponent(loginName)}'`); return q(); } /** * A boolean value that indicates whether the current user is following the specified user * * @param loginName The account name of the user */ amIFollowing(loginName) { const q = Profiles(this, "amifollowing(@v)"); q.query.set("@v", `'${encodeURIComponent(loginName)}'`); return q(); } /** * Gets tags that the current user is following * * @param maxCount The maximum number of tags to retrieve (default is 20) */ getFollowedTags(maxCount = 20) { return Profiles(this, `getfollowedtags(${maxCount})`)(); } /** * Gets the people who are following the specified user * * @param loginName The account name of the user */ getFollowersFor(loginName) { const q = Profiles(this, "getfollowersfor(@v)"); q.query.set("@v", `'${encodeURIComponent(loginName)}'`); return q(); } /** * Gets the people who are following the current user * */ get myFollowers() { return SPCollection(this, "getmyfollowers"); } /** * Gets user properties for the current user * */ get myProperties() { return Profiles(this, "getmyproperties"); } /** * Gets the people who the specified user is following * * @param loginName The account name of the user. */ getPeopleFollowedBy(loginName) { const q = Profiles(this, "getpeoplefollowedby(@v)"); q.query.set("@v", `'${encodeURIComponent(loginName)}'`); return q(); } /** * Gets user properties for the specified user. * * @param loginName The account name of the user. */ getPropertiesFor(loginName) { const q = Profiles(this, "getpropertiesfor(@v)"); q.query.set("@v", `'${encodeURIComponent(loginName)}'`); return q(); } /** * Gets the 20 most popular hash tags over the past week, sorted so that the most popular tag appears first * */ get trendingTags() { const q = Profiles(this, null); q.concat(".gettrendingtags"); return q(); } /** * Gets the specified user profile property for the specified user * * @param loginName The account name of the user * @param propertyName The case-sensitive name of the property to get */ getUserProfilePropertyFor(loginName, propertyName) { const q = Profiles(this, `getuserprofilepropertyfor(accountname=@v, propertyname='${propertyName}')`); q.query.set("@v", `'${encodeURIComponent(loginName)}'`); return q(); } /** * Removes the specified user from the user's list of suggested people to follow * * @param loginName The account name of the user */ hideSuggestion(loginName) { const q = Profiles(this, "hidesuggestion(@v)"); q.query.set("@v", `'${encodeURIComponent(loginName)}'`); return spPost(q); } /** * A boolean values that indicates whether the first user is following the second user * * @param follower The account name of the user who might be following the followee * @param followee The account name of the user who might be followed by the follower */ isFollowing(follower, followee) { const q = Profiles(this, null); q.concat(".isfollowing(possiblefolloweraccountname=@v, possiblefolloweeaccountname=@y)"); q.query.set("@v", `'${encodeURIComponent(follower)}'`); q.query.set("@y", `'${encodeURIComponent(followee)}'`); return q(); } /** * Uploads and sets the user profile picture (Users can upload a picture to their own profile only). Not supported for batching. * * @param profilePicSource Blob data representing the user's picture in BMP, JPEG, or PNG format of up to 4.76MB */ setMyProfilePic(profilePicSource) { return new Promise((resolve, reject) => { const reader = new FileReader(); reader.onload = async (e) => { const buffer = e.target.result; try { await spPost(Profiles(this, "setmyprofilepicture"), { body: buffer }); resolve(); } catch (e) { reject(e); } }; reader.readAsArrayBuffer(profilePicSource); }); } /** * Sets single value User Profile property * * @param accountName The account name of the user * @param propertyName Property name * @param propertyValue Property value */ setSingleValueProfileProperty(accountName, propertyName, propertyValue) { return spPost(Profiles(this, "SetSingleValueProfileProperty"), body({ accountName, propertyName, propertyValue, })); } /** * Sets multi valued User Profile property * * @param accountName The account name of the user * @param propertyName Property name * @param propertyValues Property values */ setMultiValuedProfileProperty(accountName, propertyName, propertyValues) { return spPost(Profiles(this, "SetMultiValuedProfileProperty"), body({ accountName, propertyName, propertyValues, })); } /** * Provisions one or more users' personal sites. (My Site administrator on SharePoint Online only) * * @param emails The email addresses of the users to provision sites for */ createPersonalSiteEnqueueBulk(...emails) { return this.profileLoader.createPersonalSiteEnqueueBulk(emails); } /** * Gets the user profile of the site owner * */ get ownerUserProfile() { return this.profileLoader.ownerUserProfile; } /** * Gets the user profile for the current user */ get userProfile() { return this.profileLoader.userProfile; } /** * Enqueues creating a personal site for this user, which can be used to share documents, web pages, and other files * * @param interactiveRequest true if interactively (web) initiated request, or false (default) if non-interactively (client) initiated request */ createPersonalSite(interactiveRequest = false) { return this.profileLoader.createPersonalSite(interactiveRequest); } /** * Sets the privacy settings for this profile * * @param share true to make all social data public; false to make all social data private */ shareAllSocialData(share) { return this.profileLoader.shareAllSocialData(share); } /** * Resolves user or group using specified query parameters * * @param queryParams The query parameters used to perform resolve */ clientPeoplePickerResolveUser(queryParams) { return this.clientPeoplePickerQuery.clientPeoplePickerResolveUser(queryParams); } /** * Searches for users or groups using specified query parameters * * @param queryParams The query parameters used to perform search */ clientPeoplePickerSearchUser(queryParams) { return this.clientPeoplePickerQuery.clientPeoplePickerSearchUser(queryParams); } } export const Profiles = spInvokableFactory(_Profiles); let ProfileLoader = class ProfileLoader extends _SPQueryable { /** * Provisions one or more users' personal sites. (My Site administrator on SharePoint Online only) Doesn't support batching * * @param emails The email addresses of the users to provision sites for */ createPersonalSiteEnqueueBulk(emails) { return spPost(ProfileLoaderFactory(this, "createpersonalsiteenqueuebulk"), body({ "emailIDs": emails })); } /** * Gets the user profile of the site owner. * */ get ownerUserProfile() { return spPost(this.getParent(ProfileLoaderFactory, "_api/sp.userprofiles.profileloader.getowneruserprofile")); } /** * Gets the user profile of the current user. * */ get userProfile() { return spPost(ProfileLoaderFactory(this, "getuserprofile")); } /** * Enqueues creating a personal site for this user, which can be used to share documents, web pages, and other files. * * @param interactiveRequest true if interactively (web) initiated request, or false (default) if non-interactively (client) initiated request */ createPersonalSite(interactiveRequest = false) { return spPost(ProfileLoaderFactory(this, `getuserprofile/createpersonalsiteenque(${interactiveRequest})`)); } /** * Sets the privacy settings for this profile * * @param share true to make all social data public; false to make all social data private. */ shareAllSocialData(share) { return spPost(ProfileLoaderFactory(this, `getuserprofile/shareallsocialdata(${share})`)); } }; ProfileLoader = __decorate([ defaultPath("_api/sp.userprofiles.profileloader.getprofileloader") ], ProfileLoader); const ProfileLoaderFactory = (baseUrl, path) => { return new ProfileLoader(baseUrl, path); }; let ClientPeoplePickerQuery = class ClientPeoplePickerQuery extends _SPQueryable { /** * Resolves user or group using specified query parameters * * @param queryParams The query parameters used to perform resolve */ async clientPeoplePickerResolveUser(queryParams) { const q = ClientPeoplePickerFactory(this, null); q.concat(".clientpeoplepickerresolveuser"); const res = await spPost(q, this.getBodyFrom(queryParams)); return JSON.parse(typeof res === "object" ? res.ClientPeoplePickerResolveUser : res); } /** * Searches for users or groups using specified query parameters * * @param queryParams The query parameters used to perform search */ async clientPeoplePickerSearchUser(queryParams) { const q = ClientPeoplePickerFactory(this, null); q.concat(".clientpeoplepickersearchuser"); const res = await spPost(q, this.getBodyFrom(queryParams)); return JSON.parse(typeof res === "object" ? res.ClientPeoplePickerSearchUser : res); } /** * Creates ClientPeoplePickerQueryParameters request body * * @param queryParams The query parameters to create request body */ getBodyFrom(queryParams) { return body({ queryParams }); } }; ClientPeoplePickerQuery = __decorate([ defaultPath("_api/sp.ui.applicationpages.clientpeoplepickerwebserviceinterface") ], ClientPeoplePickerQuery); const ClientPeoplePickerFactory = (baseUrl, path) => { return new ClientPeoplePickerQuery(baseUrl, path); }; /** * Specifies the originating zone of a request received. */ export var UrlZone; (function (UrlZone) { /** * Specifies the default zone used for requests unless another zone is specified. */ UrlZone[UrlZone["DefaultZone"] = 0] = "DefaultZone"; /** * Specifies an intranet zone. */ UrlZone[UrlZone["Intranet"] = 1] = "Intranet"; /** * Specifies an Internet zone. */ UrlZone[UrlZone["Internet"] = 2] = "Internet"; /** * Specifies a custom zone. */ UrlZone[UrlZone["Custom"] = 3] = "Custom"; /** * Specifies an extranet zone. */ UrlZone[UrlZone["Extranet"] = 4] = "Extranet"; })(UrlZone || (UrlZone = {})); //# sourceMappingURL=types.js.map