@lindle/sharepoint_requests 0.1.10 → 0.1.11
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/root/index.d.ts +156 -0
- package/dist/sharepoint_requests.cjs.development.js +225 -30
- package/dist/sharepoint_requests.cjs.development.js.map +1 -1
- package/dist/sharepoint_requests.cjs.production.min.js +1 -1
- package/dist/sharepoint_requests.cjs.production.min.js.map +1 -1
- package/dist/sharepoint_requests.esm.js +225 -30
- package/dist/sharepoint_requests.esm.js.map +1 -1
- package/package.json +1 -1
- package/src/root/index.ts +156 -0
- package/src/root/instance.ts +1 -1
package/src/root/index.ts
CHANGED
|
@@ -25,6 +25,11 @@ class HTTPSharePointRequests<
|
|
|
25
25
|
private listName: string;
|
|
26
26
|
private instance: AxiosInstance;
|
|
27
27
|
|
|
28
|
+
/**
|
|
29
|
+
* Creates an HTTP SharePoint requester bound to the provided base URL.
|
|
30
|
+
*
|
|
31
|
+
* @param baseURL The root SharePoint site URL (with or without trailing slash).
|
|
32
|
+
*/
|
|
28
33
|
constructor(baseURL: string) {
|
|
29
34
|
this.baseURL = baseURL.endsWith('/') ? baseURL : `${baseURL}/`;
|
|
30
35
|
this.endpoint = '/api';
|
|
@@ -33,6 +38,12 @@ class HTTPSharePointRequests<
|
|
|
33
38
|
this.instance = instance(this.baseURL);
|
|
34
39
|
}
|
|
35
40
|
|
|
41
|
+
/**
|
|
42
|
+
* Converts array values in a payload to the `Collection(Edm.String)` structure
|
|
43
|
+
* expected by SharePoint REST endpoints.
|
|
44
|
+
*
|
|
45
|
+
* @param data The list item payload to harmonise in-place.
|
|
46
|
+
*/
|
|
36
47
|
private transformArraysToEdmStrings(data: ListData) {
|
|
37
48
|
for (const key in data) {
|
|
38
49
|
if (Array.isArray(data[key])) {
|
|
@@ -53,12 +64,24 @@ class HTTPSharePointRequests<
|
|
|
53
64
|
return this;
|
|
54
65
|
}
|
|
55
66
|
public readonly lists = {
|
|
67
|
+
/**
|
|
68
|
+
* Fetches all SharePoint lists available to the current site.
|
|
69
|
+
*
|
|
70
|
+
* @returns Promise resolving to the list collection response payload.
|
|
71
|
+
*/
|
|
56
72
|
get: () => {
|
|
57
73
|
this.endpoint = '_api/web/lists';
|
|
58
74
|
return this.get_v2();
|
|
59
75
|
},
|
|
60
76
|
};
|
|
61
77
|
|
|
78
|
+
/**
|
|
79
|
+
* Selects a SharePoint list and exposes list-scoped CRUD helpers.
|
|
80
|
+
*
|
|
81
|
+
* @param listName Logical list key configured in the generic type map.
|
|
82
|
+
* @param sharepoint_ver SharePoint version used to choose the correct REST endpoint.
|
|
83
|
+
* @returns Chainable helpers bound to the selected list.
|
|
84
|
+
*/
|
|
62
85
|
from<K extends Extract<keyof T['LISTS'], string>>(
|
|
63
86
|
listName: K,
|
|
64
87
|
sharepoint_ver: SHAREPOINT_VER = '2013'
|
|
@@ -89,12 +112,23 @@ class HTTPSharePointRequests<
|
|
|
89
112
|
}
|
|
90
113
|
|
|
91
114
|
public folders = {
|
|
115
|
+
/**
|
|
116
|
+
* Retrieves SharePoint folders from the default folders endpoint.
|
|
117
|
+
*
|
|
118
|
+
* @returns A promise resolving with folder metadata.
|
|
119
|
+
*/
|
|
92
120
|
get: () => {
|
|
93
121
|
this.endpoint = '_api/web/folders';
|
|
94
122
|
this.get_v2();
|
|
95
123
|
},
|
|
96
124
|
};
|
|
97
125
|
|
|
126
|
+
/**
|
|
127
|
+
* Targets a SharePoint folder path and exposes file retrieval helpers.
|
|
128
|
+
*
|
|
129
|
+
* @param folderName Optional folder path relative to `Shared Documents`.
|
|
130
|
+
* @returns Helper exposing `get` to fetch files or sub-folders.
|
|
131
|
+
*/
|
|
98
132
|
public folder(folderName?: string | string[]) {
|
|
99
133
|
let filePath = ['Shared Documents'];
|
|
100
134
|
|
|
@@ -107,6 +141,12 @@ class HTTPSharePointRequests<
|
|
|
107
141
|
'/'
|
|
108
142
|
)}')`;
|
|
109
143
|
return {
|
|
144
|
+
/**
|
|
145
|
+
* Fetches files or folders from the targeted path.
|
|
146
|
+
*
|
|
147
|
+
* @param options Optional REST query options to refine the result set.
|
|
148
|
+
* @returns Promise resolving to folder contents and metadata.
|
|
149
|
+
*/
|
|
110
150
|
get: (options?: Folder_Options<any>) => {
|
|
111
151
|
if (!options?.type) {
|
|
112
152
|
this.endpoint += '/Files';
|
|
@@ -119,9 +159,20 @@ class HTTPSharePointRequests<
|
|
|
119
159
|
};
|
|
120
160
|
}
|
|
121
161
|
|
|
162
|
+
/**
|
|
163
|
+
* Retrieves user list items and exposes a get helper with optional query parameters.
|
|
164
|
+
*
|
|
165
|
+
* @param options Optional REST query options.
|
|
166
|
+
* @returns Helper exposing `get` returning SharePoint user rows.
|
|
167
|
+
*/
|
|
122
168
|
public users(options?: Options<any>) {
|
|
123
169
|
this.endpoint = '_api/web/SiteUserInfoList/items';
|
|
124
170
|
return {
|
|
171
|
+
/**
|
|
172
|
+
* Executes the user list request using the specified options.
|
|
173
|
+
*
|
|
174
|
+
* @returns Promise resolving to the SharePoint user list response.
|
|
175
|
+
*/
|
|
125
176
|
get: () => this.get_v2(options),
|
|
126
177
|
};
|
|
127
178
|
}
|
|
@@ -148,6 +199,12 @@ class HTTPSharePointRequests<
|
|
|
148
199
|
'';
|
|
149
200
|
}
|
|
150
201
|
|
|
202
|
+
/**
|
|
203
|
+
* Executes a GET request without additional metadata wrapping.
|
|
204
|
+
*
|
|
205
|
+
* @param options Optional REST query options.
|
|
206
|
+
* @returns SharePoint response payload or undefined when empty.
|
|
207
|
+
*/
|
|
151
208
|
private async get_only(options?: any) {
|
|
152
209
|
const { expand, orderBy, limit, filter, cols, skip } = options || {};
|
|
153
210
|
|
|
@@ -165,6 +222,12 @@ class HTTPSharePointRequests<
|
|
|
165
222
|
}
|
|
166
223
|
}
|
|
167
224
|
|
|
225
|
+
/**
|
|
226
|
+
* Retrieves folder contents with optional filtering and returns the payload with metadata.
|
|
227
|
+
*
|
|
228
|
+
* @param options REST options describing expand/filter/order conditions.
|
|
229
|
+
* @returns Folder data and the fully resolved request URL.
|
|
230
|
+
*/
|
|
168
231
|
private async get_files(options?: Folder_Options<any>) {
|
|
169
232
|
const { expand, orderBy, limit, filter, cols, skip } = options || {};
|
|
170
233
|
const params = {
|
|
@@ -198,6 +261,12 @@ class HTTPSharePointRequests<
|
|
|
198
261
|
return { data, meta };
|
|
199
262
|
}
|
|
200
263
|
|
|
264
|
+
/**
|
|
265
|
+
* Performs a typed list read against the current endpoint.
|
|
266
|
+
*
|
|
267
|
+
* @param options Optional REST query options governing expand, filter, ordering and pagination.
|
|
268
|
+
* @returns SharePoint list items alongside the fully-resolved request URL.
|
|
269
|
+
*/
|
|
201
270
|
private async get_v2<K = any>(
|
|
202
271
|
options?: Options<K>
|
|
203
272
|
): Promise<{ data: (K & Partial<SPItem>)[]; meta: { url: URL } }> {
|
|
@@ -235,6 +304,14 @@ class HTTPSharePointRequests<
|
|
|
235
304
|
return { data, meta };
|
|
236
305
|
}
|
|
237
306
|
|
|
307
|
+
/**
|
|
308
|
+
* Updates an item in the currently selected list.
|
|
309
|
+
*
|
|
310
|
+
* @param id Target list item identifier.
|
|
311
|
+
* @param data Payload with fields to update.
|
|
312
|
+
* @param digest Optional pre-fetched form digest to reuse.
|
|
313
|
+
* @returns Axios response of the update request.
|
|
314
|
+
*/
|
|
238
315
|
private async update_2(id: ItemID, data: ListData, digest?: string) {
|
|
239
316
|
const formDigestValue = digest || (await this.getDigest());
|
|
240
317
|
|
|
@@ -255,6 +332,12 @@ class HTTPSharePointRequests<
|
|
|
255
332
|
return response;
|
|
256
333
|
}
|
|
257
334
|
|
|
335
|
+
/**
|
|
336
|
+
* Creates a new item within the active list.
|
|
337
|
+
*
|
|
338
|
+
* @param listData SharePoint list item payload.
|
|
339
|
+
* @returns Axios response resolved from the create request.
|
|
340
|
+
*/
|
|
258
341
|
private async create_v2(listData: ListData) {
|
|
259
342
|
this.transformArraysToEdmStrings(listData);
|
|
260
343
|
listData.__metadata = {
|
|
@@ -272,6 +355,12 @@ class HTTPSharePointRequests<
|
|
|
272
355
|
return response;
|
|
273
356
|
}
|
|
274
357
|
|
|
358
|
+
/**
|
|
359
|
+
* Uploads an attachment file to an existing list item.
|
|
360
|
+
*
|
|
361
|
+
* @param props File payload and target item identifier.
|
|
362
|
+
* @returns Axios response describing the upload result.
|
|
363
|
+
*/
|
|
275
364
|
private async createFile({ file, itemId }: CreateFileProps) {
|
|
276
365
|
const requestUrl = `_api/lists/getbytitle('${this.listName}')/items(${itemId})/AttachmentFiles/add(FileName='${file.name}')`;
|
|
277
366
|
const res = await this.instance.post(requestUrl, file, {
|
|
@@ -284,6 +373,12 @@ class HTTPSharePointRequests<
|
|
|
284
373
|
return res;
|
|
285
374
|
}
|
|
286
375
|
|
|
376
|
+
/**
|
|
377
|
+
* Deletes an item using the current endpoint.
|
|
378
|
+
*
|
|
379
|
+
* @param ID Identifier of the entity to remove.
|
|
380
|
+
* @returns Axios response from the delete call.
|
|
381
|
+
*/
|
|
287
382
|
private async delete(ID: string | number) {
|
|
288
383
|
const response = await this.instance.delete(`${this.endpoint!}(${ID})`);
|
|
289
384
|
return response;
|
|
@@ -356,6 +451,13 @@ class HTTPSharePointRequests<
|
|
|
356
451
|
return response;
|
|
357
452
|
}
|
|
358
453
|
|
|
454
|
+
/**
|
|
455
|
+
* Queries SharePoint's people picker endpoint for matching users.
|
|
456
|
+
*
|
|
457
|
+
* @param input Free-text search term.
|
|
458
|
+
* @param filter Optional additional filter condition.
|
|
459
|
+
* @returns Promise with type-ahead results payload.
|
|
460
|
+
*/
|
|
359
461
|
private async typeAhead(input: string, filter?: string) {
|
|
360
462
|
const filterValue = filter ? ` and ${filter}` : '';
|
|
361
463
|
const response = await this.instance.get(
|
|
@@ -364,6 +466,11 @@ class HTTPSharePointRequests<
|
|
|
364
466
|
return response.data.d;
|
|
365
467
|
}
|
|
366
468
|
|
|
469
|
+
/**
|
|
470
|
+
* Retrieves the current user profile and flattens selected properties.
|
|
471
|
+
*
|
|
472
|
+
* @returns Promise containing the current user's profile information.
|
|
473
|
+
*/
|
|
367
474
|
private async currentUserProperties() {
|
|
368
475
|
const requestUrl = '_api/sp.userprofiles.peoplemanager/getmyproperties';
|
|
369
476
|
let profile: any = await this.instance.get(requestUrl);
|
|
@@ -389,20 +496,48 @@ class HTTPSharePointRequests<
|
|
|
389
496
|
return profile as Promise<UserProfile>;
|
|
390
497
|
}
|
|
391
498
|
public user = {
|
|
499
|
+
/**
|
|
500
|
+
* Provides accessors for the current user's profile information.
|
|
501
|
+
*
|
|
502
|
+
* @returns Helper exposing a `get` function to retrieve profile details.
|
|
503
|
+
*/
|
|
392
504
|
properties: () => {
|
|
393
505
|
return {
|
|
394
506
|
get: () => this.currentUserProperties(),
|
|
395
507
|
};
|
|
396
508
|
},
|
|
509
|
+
/**
|
|
510
|
+
* Searches across site users and their groups.
|
|
511
|
+
*
|
|
512
|
+
* @param searchValue Query string to match site users.
|
|
513
|
+
* @returns Promise resolving to matching site users.
|
|
514
|
+
*/
|
|
397
515
|
searchSiteUser: (searchValue: string) => this.getSiteUser(searchValue),
|
|
516
|
+
/**
|
|
517
|
+
* Performs a people-picker search scoped to the current site collection.
|
|
518
|
+
*
|
|
519
|
+
* @param input Search prefix.
|
|
520
|
+
* @param filter Optional additional filter condition.
|
|
521
|
+
* @returns Promise with type-ahead person results.
|
|
522
|
+
*/
|
|
398
523
|
searchUser: (input: string, filter?: string): Promise<PersonField> =>
|
|
399
524
|
this.typeAhead(input, filter),
|
|
525
|
+
/**
|
|
526
|
+
* Fetches the currently authenticated SharePoint user.
|
|
527
|
+
*
|
|
528
|
+
* @returns Helper exposing `get` that resolves to the current user payload.
|
|
529
|
+
*/
|
|
400
530
|
current: () => {
|
|
401
531
|
this.endpoint = '_api/web/currentUser';
|
|
402
532
|
return {
|
|
403
533
|
get: (): Promise<CurrentUser> => this.get_only(),
|
|
404
534
|
};
|
|
405
535
|
},
|
|
536
|
+
/**
|
|
537
|
+
* Retrieves calculated permission level for the current user.
|
|
538
|
+
*
|
|
539
|
+
* @returns Helper exposing `get` resolving to the user's permission definition.
|
|
540
|
+
*/
|
|
406
541
|
currentPermission: () => {
|
|
407
542
|
return {
|
|
408
543
|
get: () => this.currentUserPermissions(),
|
|
@@ -410,24 +545,45 @@ class HTTPSharePointRequests<
|
|
|
410
545
|
},
|
|
411
546
|
};
|
|
412
547
|
|
|
548
|
+
/**
|
|
549
|
+
* Searches site users based on a substring match across common fields.
|
|
550
|
+
*
|
|
551
|
+
* @param searchValue Term to match against the SharePoint user directory.
|
|
552
|
+
* @returns Promise with matching site users and their groups.
|
|
553
|
+
*/
|
|
413
554
|
private async getSiteUser(searchValue: string) {
|
|
414
555
|
const requestUrl = `_api/web/siteusers?&$filter=substringof('${searchValue}', Title) or substringof('${searchValue}', LoginName) or substringof('${searchValue}', Email)&$top=50&$expand=Groups`;
|
|
415
556
|
const response = await this.instance.get(requestUrl);
|
|
416
557
|
return response.data.d;
|
|
417
558
|
}
|
|
418
559
|
|
|
560
|
+
/**
|
|
561
|
+
* Retrieves all available role definitions for the current site.
|
|
562
|
+
*
|
|
563
|
+
* @returns Promise resolving to an array of role definitions.
|
|
564
|
+
*/
|
|
419
565
|
private async roleDefinitions() {
|
|
420
566
|
const requestUrl = `_api/Web/RoleDefinitions`;
|
|
421
567
|
const response = await this.instance.get(requestUrl);
|
|
422
568
|
return response.data.d.results;
|
|
423
569
|
}
|
|
424
570
|
|
|
571
|
+
/**
|
|
572
|
+
* Fetches the bit-encoded permissions of the current user.
|
|
573
|
+
*
|
|
574
|
+
* @returns Promise resolving to the `EffectiveBasePermissions` object.
|
|
575
|
+
*/
|
|
425
576
|
private async getEffectiveBasePermissions() {
|
|
426
577
|
const requestUrl = `_api/Web/effectiveBasePermissions`;
|
|
427
578
|
const response = await this.instance.get(requestUrl);
|
|
428
579
|
return response.data.d.EffectiveBasePermissions;
|
|
429
580
|
}
|
|
430
581
|
|
|
582
|
+
/**
|
|
583
|
+
* Matches the current user's effective permissions against known role definitions.
|
|
584
|
+
*
|
|
585
|
+
* @returns The matching SharePoint role definition as a structured permission object.
|
|
586
|
+
*/
|
|
431
587
|
private async currentUserPermissions() {
|
|
432
588
|
const { High } = await this.getEffectiveBasePermissions();
|
|
433
589
|
const roleDefinitions = await this.roleDefinitions();
|