UNPKG

13 kBJavaScriptView Raw
1import { __decorate } from "tslib";
2import { _SPInstance, SPCollection, spInvokableFactory, _SPQueryable, } from "../spqueryable.js";
3import { body } from "@pnp/queryable";
4import { defaultPath } from "../decorators.js";
5import { spPost } from "../operations.js";
6import { AssignFrom } from "@pnp/core";
7export class _Profiles extends _SPInstance {
8 /**
9 * Creates a new instance of the UserProfileQuery class
10 *
11 * @param baseUrl The url or SharePointQueryable which forms the parent of this user profile query
12 */
13 constructor(baseUrl, path = "_api/sp.userprofiles.peoplemanager") {
14 super(baseUrl, path);
15 this.clientPeoplePickerQuery = (new ClientPeoplePickerQuery(baseUrl)).using(AssignFrom(this));
16 this.profileLoader = (new ProfileLoader(baseUrl)).using(AssignFrom(this));
17 }
18 /**
19 * The url of the edit profile page for the current user
20 */
21 getEditProfileLink() {
22 return Profiles(this, "EditProfileLink")();
23 }
24 /**
25 * A boolean value that indicates whether the current user's "People I'm Following" list is public
26 */
27 getIsMyPeopleListPublic() {
28 return Profiles(this, "IsMyPeopleListPublic")();
29 }
30 /**
31 * A boolean value that indicates whether the current user is being followed by the specified user
32 *
33 * @param loginName The account name of the user
34 */
35 amIFollowedBy(loginName) {
36 const q = Profiles(this, "amifollowedby(@v)");
37 q.query.set("@v", `'${encodeURIComponent(loginName)}'`);
38 return q();
39 }
40 /**
41 * A boolean value that indicates whether the current user is following the specified user
42 *
43 * @param loginName The account name of the user
44 */
45 amIFollowing(loginName) {
46 const q = Profiles(this, "amifollowing(@v)");
47 q.query.set("@v", `'${encodeURIComponent(loginName)}'`);
48 return q();
49 }
50 /**
51 * Gets tags that the current user is following
52 *
53 * @param maxCount The maximum number of tags to retrieve (default is 20)
54 */
55 getFollowedTags(maxCount = 20) {
56 return Profiles(this, `getfollowedtags(${maxCount})`)();
57 }
58 /**
59 * Gets the people who are following the specified user
60 *
61 * @param loginName The account name of the user
62 */
63 getFollowersFor(loginName) {
64 const q = Profiles(this, "getfollowersfor(@v)");
65 q.query.set("@v", `'${encodeURIComponent(loginName)}'`);
66 return q();
67 }
68 /**
69 * Gets the people who are following the current user
70 *
71 */
72 get myFollowers() {
73 return SPCollection(this, "getmyfollowers");
74 }
75 /**
76 * Gets user properties for the current user
77 *
78 */
79 get myProperties() {
80 return Profiles(this, "getmyproperties");
81 }
82 /**
83 * Gets the people who the specified user is following
84 *
85 * @param loginName The account name of the user.
86 */
87 getPeopleFollowedBy(loginName) {
88 const q = Profiles(this, "getpeoplefollowedby(@v)");
89 q.query.set("@v", `'${encodeURIComponent(loginName)}'`);
90 return q();
91 }
92 /**
93 * Gets user properties for the specified user.
94 *
95 * @param loginName The account name of the user.
96 */
97 getPropertiesFor(loginName) {
98 const q = Profiles(this, "getpropertiesfor(@v)");
99 q.query.set("@v", `'${encodeURIComponent(loginName)}'`);
100 return q();
101 }
102 /**
103 * Gets the 20 most popular hash tags over the past week, sorted so that the most popular tag appears first
104 *
105 */
106 get trendingTags() {
107 const q = Profiles(this, null);
108 q.concat(".gettrendingtags");
109 return q();
110 }
111 /**
112 * Gets the specified user profile property for the specified user
113 *
114 * @param loginName The account name of the user
115 * @param propertyName The case-sensitive name of the property to get
116 */
117 getUserProfilePropertyFor(loginName, propertyName) {
118 const q = Profiles(this, `getuserprofilepropertyfor(accountname=@v, propertyname='${propertyName}')`);
119 q.query.set("@v", `'${encodeURIComponent(loginName)}'`);
120 return q();
121 }
122 /**
123 * Removes the specified user from the user's list of suggested people to follow
124 *
125 * @param loginName The account name of the user
126 */
127 hideSuggestion(loginName) {
128 const q = Profiles(this, "hidesuggestion(@v)");
129 q.query.set("@v", `'${encodeURIComponent(loginName)}'`);
130 return spPost(q);
131 }
132 /**
133 * A boolean values that indicates whether the first user is following the second user
134 *
135 * @param follower The account name of the user who might be following the followee
136 * @param followee The account name of the user who might be followed by the follower
137 */
138 isFollowing(follower, followee) {
139 const q = Profiles(this, null);
140 q.concat(".isfollowing(possiblefolloweraccountname=@v, possiblefolloweeaccountname=@y)");
141 q.query.set("@v", `'${encodeURIComponent(follower)}'`);
142 q.query.set("@y", `'${encodeURIComponent(followee)}'`);
143 return q();
144 }
145 /**
146 * Uploads and sets the user profile picture (Users can upload a picture to their own profile only). Not supported for batching.
147 *
148 * @param profilePicSource Blob data representing the user's picture in BMP, JPEG, or PNG format of up to 4.76MB
149 */
150 setMyProfilePic(profilePicSource) {
151 return new Promise((resolve, reject) => {
152 const reader = new FileReader();
153 reader.onload = async (e) => {
154 const buffer = e.target.result;
155 try {
156 await spPost(Profiles(this, "setmyprofilepicture"), { body: buffer });
157 resolve();
158 }
159 catch (e) {
160 reject(e);
161 }
162 };
163 reader.readAsArrayBuffer(profilePicSource);
164 });
165 }
166 /**
167 * Sets single value User Profile property
168 *
169 * @param accountName The account name of the user
170 * @param propertyName Property name
171 * @param propertyValue Property value
172 */
173 setSingleValueProfileProperty(accountName, propertyName, propertyValue) {
174 return spPost(Profiles(this, "SetSingleValueProfileProperty"), body({
175 accountName,
176 propertyName,
177 propertyValue,
178 }));
179 }
180 /**
181 * Sets multi valued User Profile property
182 *
183 * @param accountName The account name of the user
184 * @param propertyName Property name
185 * @param propertyValues Property values
186 */
187 setMultiValuedProfileProperty(accountName, propertyName, propertyValues) {
188 return spPost(Profiles(this, "SetMultiValuedProfileProperty"), body({
189 accountName,
190 propertyName,
191 propertyValues,
192 }));
193 }
194 /**
195 * Provisions one or more users' personal sites. (My Site administrator on SharePoint Online only)
196 *
197 * @param emails The email addresses of the users to provision sites for
198 */
199 createPersonalSiteEnqueueBulk(...emails) {
200 return this.profileLoader.createPersonalSiteEnqueueBulk(emails);
201 }
202 /**
203 * Gets the user profile of the site owner
204 *
205 */
206 get ownerUserProfile() {
207 return this.profileLoader.ownerUserProfile;
208 }
209 /**
210 * Gets the user profile for the current user
211 */
212 get userProfile() {
213 return this.profileLoader.userProfile;
214 }
215 /**
216 * Enqueues creating a personal site for this user, which can be used to share documents, web pages, and other files
217 *
218 * @param interactiveRequest true if interactively (web) initiated request, or false (default) if non-interactively (client) initiated request
219 */
220 createPersonalSite(interactiveRequest = false) {
221 return this.profileLoader.createPersonalSite(interactiveRequest);
222 }
223 /**
224 * Sets the privacy settings for this profile
225 *
226 * @param share true to make all social data public; false to make all social data private
227 */
228 shareAllSocialData(share) {
229 return this.profileLoader.shareAllSocialData(share);
230 }
231 /**
232 * Resolves user or group using specified query parameters
233 *
234 * @param queryParams The query parameters used to perform resolve
235 */
236 clientPeoplePickerResolveUser(queryParams) {
237 return this.clientPeoplePickerQuery.clientPeoplePickerResolveUser(queryParams);
238 }
239 /**
240 * Searches for users or groups using specified query parameters
241 *
242 * @param queryParams The query parameters used to perform search
243 */
244 clientPeoplePickerSearchUser(queryParams) {
245 return this.clientPeoplePickerQuery.clientPeoplePickerSearchUser(queryParams);
246 }
247}
248export const Profiles = spInvokableFactory(_Profiles);
249let ProfileLoader = class ProfileLoader extends _SPQueryable {
250 /**
251 * Provisions one or more users' personal sites. (My Site administrator on SharePoint Online only) Doesn't support batching
252 *
253 * @param emails The email addresses of the users to provision sites for
254 */
255 createPersonalSiteEnqueueBulk(emails) {
256 return spPost(ProfileLoaderFactory(this, "createpersonalsiteenqueuebulk"), body({ "emailIDs": emails }));
257 }
258 /**
259 * Gets the user profile of the site owner.
260 *
261 */
262 get ownerUserProfile() {
263 return spPost(this.getParent(ProfileLoaderFactory, "_api/sp.userprofiles.profileloader.getowneruserprofile"));
264 }
265 /**
266 * Gets the user profile of the current user.
267 *
268 */
269 get userProfile() {
270 return spPost(ProfileLoaderFactory(this, "getuserprofile"));
271 }
272 /**
273 * Enqueues creating a personal site for this user, which can be used to share documents, web pages, and other files.
274 *
275 * @param interactiveRequest true if interactively (web) initiated request, or false (default) if non-interactively (client) initiated request
276 */
277 createPersonalSite(interactiveRequest = false) {
278 return spPost(ProfileLoaderFactory(this, `getuserprofile/createpersonalsiteenque(${interactiveRequest})`));
279 }
280 /**
281 * Sets the privacy settings for this profile
282 *
283 * @param share true to make all social data public; false to make all social data private.
284 */
285 shareAllSocialData(share) {
286 return spPost(ProfileLoaderFactory(this, `getuserprofile/shareallsocialdata(${share})`));
287 }
288};
289ProfileLoader = __decorate([
290 defaultPath("_api/sp.userprofiles.profileloader.getprofileloader")
291], ProfileLoader);
292const ProfileLoaderFactory = (baseUrl, path) => {
293 return new ProfileLoader(baseUrl, path);
294};
295let ClientPeoplePickerQuery = class ClientPeoplePickerQuery extends _SPQueryable {
296 /**
297 * Resolves user or group using specified query parameters
298 *
299 * @param queryParams The query parameters used to perform resolve
300 */
301 async clientPeoplePickerResolveUser(queryParams) {
302 const q = ClientPeoplePickerFactory(this, null);
303 q.concat(".clientpeoplepickerresolveuser");
304 const res = await spPost(q, this.getBodyFrom(queryParams));
305 return JSON.parse(typeof res === "object" ? res.ClientPeoplePickerResolveUser : res);
306 }
307 /**
308 * Searches for users or groups using specified query parameters
309 *
310 * @param queryParams The query parameters used to perform search
311 */
312 async clientPeoplePickerSearchUser(queryParams) {
313 const q = ClientPeoplePickerFactory(this, null);
314 q.concat(".clientpeoplepickersearchuser");
315 const res = await spPost(q, this.getBodyFrom(queryParams));
316 return JSON.parse(typeof res === "object" ? res.ClientPeoplePickerSearchUser : res);
317 }
318 /**
319 * Creates ClientPeoplePickerQueryParameters request body
320 *
321 * @param queryParams The query parameters to create request body
322 */
323 getBodyFrom(queryParams) {
324 return body({ queryParams });
325 }
326};
327ClientPeoplePickerQuery = __decorate([
328 defaultPath("_api/sp.ui.applicationpages.clientpeoplepickerwebserviceinterface")
329], ClientPeoplePickerQuery);
330const ClientPeoplePickerFactory = (baseUrl, path) => {
331 return new ClientPeoplePickerQuery(baseUrl, path);
332};
333/**
334 * Specifies the originating zone of a request received.
335 */
336export var UrlZone;
337(function (UrlZone) {
338 /**
339 * Specifies the default zone used for requests unless another zone is specified.
340 */
341 UrlZone[UrlZone["DefaultZone"] = 0] = "DefaultZone";
342 /**
343 * Specifies an intranet zone.
344 */
345 UrlZone[UrlZone["Intranet"] = 1] = "Intranet";
346 /**
347 * Specifies an Internet zone.
348 */
349 UrlZone[UrlZone["Internet"] = 2] = "Internet";
350 /**
351 * Specifies a custom zone.
352 */
353 UrlZone[UrlZone["Custom"] = 3] = "Custom";
354 /**
355 * Specifies an extranet zone.
356 */
357 UrlZone[UrlZone["Extranet"] = 4] = "Extranet";
358})(UrlZone || (UrlZone = {}));
359//# sourceMappingURL=types.js.map
\No newline at end of file