@lindle/sharepoint_requests 0.1.9-beta.0
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/LICENSE +21 -0
- package/README.md +170 -0
- package/dist/index.d.ts +15 -0
- package/dist/index.js +8 -0
- package/dist/root/index.d.ts +125 -0
- package/dist/root/request/digest.d.ts +7 -0
- package/dist/root/request/get.d.ts +13 -0
- package/dist/sharepoint_requests.cjs.development.js +914 -0
- package/dist/sharepoint_requests.cjs.development.js.map +1 -0
- package/dist/sharepoint_requests.cjs.production.min.js +2 -0
- package/dist/sharepoint_requests.cjs.production.min.js.map +1 -0
- package/dist/sharepoint_requests.esm.js +908 -0
- package/dist/sharepoint_requests.esm.js.map +1 -0
- package/dist/types/index.d.ts +201 -0
- package/package.json +47 -0
- package/src/index.ts +28 -0
- package/src/root/index.ts +429 -0
- package/src/root/request/digest.ts +25 -0
- package/src/root/request/get.ts +44 -0
- package/src/types/index.ts +342 -0
|
@@ -0,0 +1,429 @@
|
|
|
1
|
+
import axios, { AxiosInstance, AxiosResponse } from 'axios';
|
|
2
|
+
import {
|
|
3
|
+
CreateFileProps,
|
|
4
|
+
CurrentUser,
|
|
5
|
+
EmailProps,
|
|
6
|
+
Field_Options,
|
|
7
|
+
Folder_Options,
|
|
8
|
+
IListName,
|
|
9
|
+
ItemID,
|
|
10
|
+
ListData,
|
|
11
|
+
Options,
|
|
12
|
+
PersonField,
|
|
13
|
+
SHAREPOINT_VER,
|
|
14
|
+
SPItem,
|
|
15
|
+
UserPermision,
|
|
16
|
+
UserProfile,
|
|
17
|
+
} from '../types';
|
|
18
|
+
import get from './request/get';
|
|
19
|
+
import getDigest from './request/digest';
|
|
20
|
+
|
|
21
|
+
class HTTPSharePointRequests<
|
|
22
|
+
T extends { LISTS: Record<string, any>; FOLDERS?: Record<string, any> }
|
|
23
|
+
> {
|
|
24
|
+
private baseURL: string;
|
|
25
|
+
private endpoint: string;
|
|
26
|
+
private listName: string;
|
|
27
|
+
private instance: AxiosInstance;
|
|
28
|
+
|
|
29
|
+
constructor(baseURL: string) {
|
|
30
|
+
this.baseURL = baseURL.endsWith('/') ? baseURL : `${baseURL}/`;
|
|
31
|
+
this.endpoint = '/api';
|
|
32
|
+
this.listName = '';
|
|
33
|
+
const headers = {
|
|
34
|
+
Accept: 'application/json; odata=verbose',
|
|
35
|
+
'Content-Type': 'application/json; odata=verbose',
|
|
36
|
+
};
|
|
37
|
+
|
|
38
|
+
this.instance = axios.create({
|
|
39
|
+
baseURL: `${this.baseURL}`,
|
|
40
|
+
withCredentials: true,
|
|
41
|
+
headers: {
|
|
42
|
+
common: headers,
|
|
43
|
+
post: headers,
|
|
44
|
+
},
|
|
45
|
+
});
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
private transformArraysToEdmStrings(data: ListData) {
|
|
49
|
+
for (const key in data) {
|
|
50
|
+
if (Array.isArray(data[key])) {
|
|
51
|
+
data[key] = {
|
|
52
|
+
__metadata: { type: 'Collection(Edm.String)' },
|
|
53
|
+
results: data[key],
|
|
54
|
+
};
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
/**
|
|
60
|
+
* @deprecated Use `from` instead.
|
|
61
|
+
*/
|
|
62
|
+
list(listName: IListName<T>) {
|
|
63
|
+
this.listName = listName;
|
|
64
|
+
this.endpoint = `_vti_bin/ListData.svc/${listName}`;
|
|
65
|
+
return this;
|
|
66
|
+
}
|
|
67
|
+
public readonly lists = {
|
|
68
|
+
get: () => {
|
|
69
|
+
this.endpoint = '_api/web/lists';
|
|
70
|
+
return this.get_v2();
|
|
71
|
+
},
|
|
72
|
+
};
|
|
73
|
+
|
|
74
|
+
from<K extends Extract<keyof T['LISTS'], string>>(
|
|
75
|
+
listName: K,
|
|
76
|
+
sharepoint_ver: SHAREPOINT_VER = '2013'
|
|
77
|
+
) {
|
|
78
|
+
this.listName = listName;
|
|
79
|
+
this.endpoint =
|
|
80
|
+
sharepoint_ver === '2013'
|
|
81
|
+
? `_api/web/lists/GetByTitle('${this.listName}')/items`
|
|
82
|
+
: `_vti_bin/ListData.svc/${listName}`;
|
|
83
|
+
return {
|
|
84
|
+
create: (data: ListData) => this.create_v2(data),
|
|
85
|
+
get: (options?: Options<T['LISTS'][K]>) =>
|
|
86
|
+
this.get_v2<T['LISTS'][K]>(options),
|
|
87
|
+
update: (id: ItemID, data: ListData, digest?: string) =>
|
|
88
|
+
this.update_2(id, data, digest),
|
|
89
|
+
delete: (id: ItemID) => this.delete(id),
|
|
90
|
+
createFile: (props: CreateFileProps) => this.createFile(props),
|
|
91
|
+
fields: (options?: Field_Options<T['LISTS'][K]>) => {
|
|
92
|
+
// return this.field_v2(options)
|
|
93
|
+
this.endpoint = !options?.fieldName
|
|
94
|
+
? `_api/web/lists/GetByTitle('${this.listName}')/fields`
|
|
95
|
+
: `_api/web/lists/GetByTitle('${this.listName}')/fields/getbytitle('${options.fieldName}')`;
|
|
96
|
+
return {
|
|
97
|
+
get: () => this.get_only(options),
|
|
98
|
+
};
|
|
99
|
+
},
|
|
100
|
+
};
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
public folders = {
|
|
104
|
+
get: () => {
|
|
105
|
+
this.endpoint = '_api/web/folders';
|
|
106
|
+
this.get_v2();
|
|
107
|
+
},
|
|
108
|
+
};
|
|
109
|
+
|
|
110
|
+
public folder(folderName?: string | string[]) {
|
|
111
|
+
let filePath = ['Shared Documents'];
|
|
112
|
+
|
|
113
|
+
if (folderName) {
|
|
114
|
+
filePath = Array.isArray(folderName)
|
|
115
|
+
? [...filePath, ...folderName]
|
|
116
|
+
: [...filePath, folderName];
|
|
117
|
+
}
|
|
118
|
+
this.endpoint = `_api/web/GetFolderByServerRelativeUrl('${filePath.join(
|
|
119
|
+
'/'
|
|
120
|
+
)}')`;
|
|
121
|
+
return {
|
|
122
|
+
get: (options?: Folder_Options<any>) => {
|
|
123
|
+
if (!options?.type) {
|
|
124
|
+
this.endpoint += '/Files';
|
|
125
|
+
} else {
|
|
126
|
+
this.endpoint += `/${options.type}`;
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
return this.get_files(options);
|
|
130
|
+
},
|
|
131
|
+
};
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
// public users(options?: Options<any>) {
|
|
135
|
+
// this.endpoint = '_api/web/SiteUserInfoList/items';
|
|
136
|
+
// return {
|
|
137
|
+
// get: () => this.get_v2(options),
|
|
138
|
+
// };
|
|
139
|
+
// }
|
|
140
|
+
public users = {
|
|
141
|
+
get: async (options?: Options<any>) => {
|
|
142
|
+
this.endpoint = '_api/web/SiteUserInfoList/items';
|
|
143
|
+
return await this.get_v2(options);
|
|
144
|
+
},
|
|
145
|
+
};
|
|
146
|
+
|
|
147
|
+
/**
|
|
148
|
+
* Asynchronously retrieves the Form Digest Value from the context information API.
|
|
149
|
+
*
|
|
150
|
+
* @returns {Promise<string>} A promise that resolves to the Form Digest Value.
|
|
151
|
+
* @throws {Error} If the HTTP request fails or the response does not contain the expected data.
|
|
152
|
+
*/
|
|
153
|
+
private async getDigest(): Promise<string> {
|
|
154
|
+
const value = await getDigest({
|
|
155
|
+
instance: this.instance,
|
|
156
|
+
baseURL: this.baseURL,
|
|
157
|
+
});
|
|
158
|
+
|
|
159
|
+
return value;
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
private async get_only(options?: any) {
|
|
163
|
+
const { expand, orderBy, limit, filter, cols, skip } = options || {};
|
|
164
|
+
|
|
165
|
+
const params = {
|
|
166
|
+
$expand: Array.isArray(expand) ? expand.join(',') : expand,
|
|
167
|
+
$top: limit,
|
|
168
|
+
$skip: skip,
|
|
169
|
+
$select: Array.isArray(cols) ? cols.join(',') : cols,
|
|
170
|
+
$filter: filter,
|
|
171
|
+
$orderby: Array.isArray(orderBy) ? orderBy.join(',') : orderBy,
|
|
172
|
+
};
|
|
173
|
+
const { data } = await this.instance.get(this.endpoint, { params });
|
|
174
|
+
if (data) {
|
|
175
|
+
return data.d.results ? data.d.results : data.d;
|
|
176
|
+
}
|
|
177
|
+
}
|
|
178
|
+
|
|
179
|
+
private async get_files(options?: Folder_Options<any>) {
|
|
180
|
+
const { expand, orderBy, limit, filter, cols, skip } = options || {};
|
|
181
|
+
const params = {
|
|
182
|
+
$expand: Array.isArray(expand) ? expand.join(',') : expand,
|
|
183
|
+
$top: limit,
|
|
184
|
+
$skip: skip,
|
|
185
|
+
$select: Array.isArray(cols) ? cols.join(',') : cols,
|
|
186
|
+
$filter: filter,
|
|
187
|
+
$orderby: Array.isArray(orderBy) ? orderBy.join(',') : orderBy,
|
|
188
|
+
};
|
|
189
|
+
const url = new URL(this.endpoint, this.instance.defaults.baseURL);
|
|
190
|
+
Object.entries(params).forEach(([key, value]) => {
|
|
191
|
+
if (value !== undefined && value !== null) {
|
|
192
|
+
url.searchParams.append(key, String(value));
|
|
193
|
+
}
|
|
194
|
+
});
|
|
195
|
+
|
|
196
|
+
const response = await this.instance.request({
|
|
197
|
+
url: this.endpoint,
|
|
198
|
+
method: 'GET',
|
|
199
|
+
params,
|
|
200
|
+
});
|
|
201
|
+
|
|
202
|
+
const data =
|
|
203
|
+
limit || !response.data.d.results
|
|
204
|
+
? response.data.d
|
|
205
|
+
: response.data.d.results;
|
|
206
|
+
|
|
207
|
+
const meta = { url };
|
|
208
|
+
|
|
209
|
+
return { data, meta };
|
|
210
|
+
}
|
|
211
|
+
|
|
212
|
+
private async get_v2<K = any>(
|
|
213
|
+
options?: Options<K>
|
|
214
|
+
): Promise<{ data: (K & Partial<SPItem>)[]; meta: { url: URL } }> {
|
|
215
|
+
const { data, meta } = await get(
|
|
216
|
+
{ instance: this.instance, endpoint: this.endpoint },
|
|
217
|
+
options
|
|
218
|
+
);
|
|
219
|
+
|
|
220
|
+
return { data, meta };
|
|
221
|
+
}
|
|
222
|
+
|
|
223
|
+
private async update_2(id: ItemID, data: ListData, digest?: string) {
|
|
224
|
+
const formDigestValue = digest || (await this.getDigest());
|
|
225
|
+
|
|
226
|
+
data.__metadata = {
|
|
227
|
+
type: `SP.Data.${this.listName}ListItem`,
|
|
228
|
+
};
|
|
229
|
+
const url = `_api/lists/getbytitle('${this.listName}')/getItemById('${id}')`;
|
|
230
|
+
const response = await this.instance({
|
|
231
|
+
url,
|
|
232
|
+
method: 'POST',
|
|
233
|
+
data: JSON.stringify(data),
|
|
234
|
+
headers: {
|
|
235
|
+
'X-RequestDigest': formDigestValue,
|
|
236
|
+
'IF-MATCH': '*',
|
|
237
|
+
'X-Http-Method': 'PATCH',
|
|
238
|
+
},
|
|
239
|
+
});
|
|
240
|
+
return response;
|
|
241
|
+
}
|
|
242
|
+
|
|
243
|
+
private async create_v2(listData: ListData) {
|
|
244
|
+
this.transformArraysToEdmStrings(listData);
|
|
245
|
+
listData.__metadata = {
|
|
246
|
+
type: `SP.Data.${this.listName}ListItem`,
|
|
247
|
+
};
|
|
248
|
+
const response = await this.instance({
|
|
249
|
+
url: this.endpoint,
|
|
250
|
+
method: 'POST',
|
|
251
|
+
data: JSON.stringify(listData),
|
|
252
|
+
headers: {
|
|
253
|
+
'X-RequestDigest': await this.getDigest(),
|
|
254
|
+
'IF-MATCH': '*',
|
|
255
|
+
},
|
|
256
|
+
});
|
|
257
|
+
return response;
|
|
258
|
+
}
|
|
259
|
+
|
|
260
|
+
private async createFile({ file, itemId }: CreateFileProps) {
|
|
261
|
+
const requestUrl = `_api/lists/getbytitle('${this.listName}')/items(${itemId})/AttachmentFiles/add(FileName='${file.name}')`;
|
|
262
|
+
const res = await this.instance.post(requestUrl, file, {
|
|
263
|
+
headers: {
|
|
264
|
+
'X-RequestDigest': await this.getDigest(),
|
|
265
|
+
},
|
|
266
|
+
withCredentials: true,
|
|
267
|
+
});
|
|
268
|
+
|
|
269
|
+
return res;
|
|
270
|
+
}
|
|
271
|
+
|
|
272
|
+
private async delete(ID: string | number) {
|
|
273
|
+
const response = await this.instance.delete(`${this.endpoint!}(${ID})`);
|
|
274
|
+
return response;
|
|
275
|
+
}
|
|
276
|
+
|
|
277
|
+
public email = {
|
|
278
|
+
/**
|
|
279
|
+
* Sends an email using SharePoint's Utility.SendEmail API.
|
|
280
|
+
*
|
|
281
|
+
* @param {EmailProps} param0 - The email properties.
|
|
282
|
+
* @param {string} param0.From - The sender's email address.
|
|
283
|
+
* @example
|
|
284
|
+
* Example of a sender's email address
|
|
285
|
+
* "sender@example.com"
|
|
286
|
+
* @param {string | string[]} param0.To - The recipient's email address or an array of email addresses.
|
|
287
|
+
* @example
|
|
288
|
+
* Example of a single recipient's email address
|
|
289
|
+
* "recipient@example.com"
|
|
290
|
+
* Example of multiple recipients' email addresses
|
|
291
|
+
* ["recipient1@example.com", "recipient2@example.com"]
|
|
292
|
+
* @param {string} param0.Subject - The subject of the email.
|
|
293
|
+
* @example
|
|
294
|
+
* Example of an email subject
|
|
295
|
+
* "Meeting Reminder"
|
|
296
|
+
* @param {string} param0.Body - The body content of the email.
|
|
297
|
+
* @example
|
|
298
|
+
* Example of an email body
|
|
299
|
+
* "Dear team, please be reminded of the meeting scheduled for tomorrow at 10 AM."
|
|
300
|
+
* @returns {Promise<any>} - A promise that resolves to the response of the email send request.
|
|
301
|
+
*/
|
|
302
|
+
send: (props: EmailProps) => this.sendEmail(props),
|
|
303
|
+
};
|
|
304
|
+
|
|
305
|
+
private async sendEmail({
|
|
306
|
+
From,
|
|
307
|
+
To,
|
|
308
|
+
Subject,
|
|
309
|
+
Body,
|
|
310
|
+
}: EmailProps): Promise<
|
|
311
|
+
AxiosResponse<{
|
|
312
|
+
d: {
|
|
313
|
+
SendEmail: null;
|
|
314
|
+
};
|
|
315
|
+
}>
|
|
316
|
+
> {
|
|
317
|
+
const httpRequest = '_api/SP.Utilities.Utility.SendEmail';
|
|
318
|
+
const response = await this.instance({
|
|
319
|
+
url: httpRequest,
|
|
320
|
+
method: 'POST',
|
|
321
|
+
headers: {
|
|
322
|
+
'X-RequestDigest': await this.getDigest(),
|
|
323
|
+
'X-Http-Method': 'POST',
|
|
324
|
+
'Content-Type': 'application/json;odata=verbose',
|
|
325
|
+
},
|
|
326
|
+
data: JSON.stringify({
|
|
327
|
+
properties: {
|
|
328
|
+
__metadata: {
|
|
329
|
+
type: 'SP.Utilities.EmailProperties',
|
|
330
|
+
},
|
|
331
|
+
From,
|
|
332
|
+
To: {
|
|
333
|
+
results: Array.isArray(To) ? To : [To],
|
|
334
|
+
},
|
|
335
|
+
Body,
|
|
336
|
+
Subject,
|
|
337
|
+
},
|
|
338
|
+
}),
|
|
339
|
+
});
|
|
340
|
+
|
|
341
|
+
return response;
|
|
342
|
+
}
|
|
343
|
+
|
|
344
|
+
private async typeAhead(input: string, filter?: string) {
|
|
345
|
+
const filterValue = filter ? ` and ${filter}` : '';
|
|
346
|
+
const response = await this.instance.get(
|
|
347
|
+
`_vti_bin/listdata.svc/UserInformationList?$top=10&$filter=substringof('${input}',Name) or substringof('${input}',WorkEmail)${filterValue}`
|
|
348
|
+
);
|
|
349
|
+
return response.data.d;
|
|
350
|
+
}
|
|
351
|
+
|
|
352
|
+
private async currentUserProperties() {
|
|
353
|
+
const requestUrl = '_api/sp.userprofiles.peoplemanager/getmyproperties';
|
|
354
|
+
let profile: any = await this.instance.get(requestUrl);
|
|
355
|
+
|
|
356
|
+
profile = profile.data.d;
|
|
357
|
+
|
|
358
|
+
profile.UserProfileProperties.results.forEach(
|
|
359
|
+
(prop: { Key: string; Value: string }) => {
|
|
360
|
+
if (prop.Key === 'FirstName') {
|
|
361
|
+
profile.FirstName = prop.Value;
|
|
362
|
+
}
|
|
363
|
+
if (prop.Key === 'LastName') {
|
|
364
|
+
profile.LastName = prop.Value;
|
|
365
|
+
}
|
|
366
|
+
if (prop.Key === 'Country') {
|
|
367
|
+
profile.Country = prop.Value;
|
|
368
|
+
}
|
|
369
|
+
if (prop.Key === 'UserName') {
|
|
370
|
+
profile.UserName = prop.Value;
|
|
371
|
+
}
|
|
372
|
+
}
|
|
373
|
+
);
|
|
374
|
+
return profile as Promise<UserProfile>;
|
|
375
|
+
}
|
|
376
|
+
public user = {
|
|
377
|
+
properties: () => {
|
|
378
|
+
return {
|
|
379
|
+
get: () => this.currentUserProperties(),
|
|
380
|
+
};
|
|
381
|
+
},
|
|
382
|
+
searchSiteUser: (searchValue: string) => this.getSiteUser(searchValue),
|
|
383
|
+
searchUser: (input: string, filter?: string): Promise<PersonField> =>
|
|
384
|
+
this.typeAhead(input, filter),
|
|
385
|
+
current: () => {
|
|
386
|
+
this.endpoint = '_api/web/currentUser';
|
|
387
|
+
return {
|
|
388
|
+
get: (): Promise<CurrentUser> => this.get_only(),
|
|
389
|
+
};
|
|
390
|
+
},
|
|
391
|
+
currentPermission: () => {
|
|
392
|
+
return {
|
|
393
|
+
get: () => this.currentUserPermissions(),
|
|
394
|
+
};
|
|
395
|
+
},
|
|
396
|
+
};
|
|
397
|
+
|
|
398
|
+
private async getSiteUser(searchValue: string) {
|
|
399
|
+
const requestUrl = `_api/web/siteusers?&$filter=substringof('${searchValue}', Title) or substringof('${searchValue}', LoginName) or substringof('${searchValue}', Email)&$top=50&$expand=Groups`;
|
|
400
|
+
const response = await this.instance.get(requestUrl);
|
|
401
|
+
return response.data.d;
|
|
402
|
+
}
|
|
403
|
+
|
|
404
|
+
private async roleDefinitions() {
|
|
405
|
+
const requestUrl = `_api/Web/RoleDefinitions`;
|
|
406
|
+
const response = await this.instance.get(requestUrl);
|
|
407
|
+
return response.data.d.results;
|
|
408
|
+
}
|
|
409
|
+
|
|
410
|
+
private async getEffectiveBasePermissions() {
|
|
411
|
+
const requestUrl = `_api/Web/effectiveBasePermissions`;
|
|
412
|
+
const response = await this.instance.get(requestUrl);
|
|
413
|
+
return response.data.d.EffectiveBasePermissions;
|
|
414
|
+
}
|
|
415
|
+
|
|
416
|
+
private async currentUserPermissions() {
|
|
417
|
+
const { High } = await this.getEffectiveBasePermissions();
|
|
418
|
+
const roleDefinitions = await this.roleDefinitions();
|
|
419
|
+
|
|
420
|
+
const result = roleDefinitions.find(
|
|
421
|
+
({ BasePermissions }: { BasePermissions: { High: string } }) =>
|
|
422
|
+
BasePermissions.High === High
|
|
423
|
+
);
|
|
424
|
+
|
|
425
|
+
return result as UserPermision;
|
|
426
|
+
}
|
|
427
|
+
}
|
|
428
|
+
|
|
429
|
+
export default HTTPSharePointRequests;
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { AxiosInstance } from 'axios';
|
|
2
|
+
|
|
3
|
+
type GetDigestProps = {
|
|
4
|
+
instance: AxiosInstance;
|
|
5
|
+
baseURL: string;
|
|
6
|
+
};
|
|
7
|
+
|
|
8
|
+
const getDigest = async ({
|
|
9
|
+
instance,
|
|
10
|
+
baseURL,
|
|
11
|
+
}: GetDigestProps): Promise<string> => {
|
|
12
|
+
try {
|
|
13
|
+
const response = await instance.post(`${baseURL}_api/contextinfo`);
|
|
14
|
+
if (!response.data?.d?.GetContextWebInformation?.FormDigestValue) {
|
|
15
|
+
throw new Error('Invalid response structure: Missing FormDigestValue');
|
|
16
|
+
}
|
|
17
|
+
return response.data.d.GetContextWebInformation.FormDigestValue;
|
|
18
|
+
} catch (error) {
|
|
19
|
+
console.error('Failed to retrieve the Form Digest Value:', error);
|
|
20
|
+
throw new Error(`Error retrieving Form Digest Value`);
|
|
21
|
+
}
|
|
22
|
+
'';
|
|
23
|
+
};
|
|
24
|
+
|
|
25
|
+
export default getDigest;
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
import { AxiosInstance } from 'axios';
|
|
2
|
+
import { Options, SPItem } from '../../types';
|
|
3
|
+
|
|
4
|
+
type GetProps = { instance: AxiosInstance; endpoint: string };
|
|
5
|
+
|
|
6
|
+
const get = async <K = any>(
|
|
7
|
+
{ instance, endpoint }: GetProps,
|
|
8
|
+
options?: Options<K>
|
|
9
|
+
): Promise<{ data: (K & Partial<SPItem>)[]; meta: { url: URL } }> => {
|
|
10
|
+
const { expand, orderBy, limit, filter, cols, skip } = options || {};
|
|
11
|
+
|
|
12
|
+
const params = {
|
|
13
|
+
$expand: Array.isArray(expand) ? expand.join(',') : expand,
|
|
14
|
+
$top: limit,
|
|
15
|
+
$skip: skip,
|
|
16
|
+
$select: Array.isArray(cols) ? cols.join(',') : cols,
|
|
17
|
+
$filter: filter,
|
|
18
|
+
$orderby: Array.isArray(orderBy) ? orderBy.join(' ') : orderBy,
|
|
19
|
+
};
|
|
20
|
+
|
|
21
|
+
const url = new URL(endpoint, instance.defaults.baseURL);
|
|
22
|
+
Object.entries(params).forEach(([key, value]) => {
|
|
23
|
+
if (value !== undefined && value !== null) {
|
|
24
|
+
url.searchParams.append(key, String(value));
|
|
25
|
+
}
|
|
26
|
+
});
|
|
27
|
+
|
|
28
|
+
const response = await instance.request({
|
|
29
|
+
url: endpoint,
|
|
30
|
+
method: 'GET',
|
|
31
|
+
params,
|
|
32
|
+
});
|
|
33
|
+
|
|
34
|
+
const data =
|
|
35
|
+
limit || !response.data.d.results
|
|
36
|
+
? response.data.d
|
|
37
|
+
: response.data.d.results;
|
|
38
|
+
|
|
39
|
+
const meta = { url };
|
|
40
|
+
|
|
41
|
+
return { data, meta };
|
|
42
|
+
};
|
|
43
|
+
|
|
44
|
+
export default get;
|