@lindle/sharepoint_requests 0.1.9-beta.0 → 0.1.10

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.
@@ -1,13 +0,0 @@
1
- import { AxiosInstance } from 'axios';
2
- import { Options, SPItem } from '../../types';
3
- declare type GetProps = {
4
- instance: AxiosInstance;
5
- endpoint: string;
6
- };
7
- declare const get: <K = any>({ instance, endpoint }: GetProps, options?: Options<K>) => Promise<{
8
- data: (K & Partial<SPItem>)[];
9
- meta: {
10
- url: URL;
11
- };
12
- }>;
13
- export default get;
@@ -1,25 +0,0 @@
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;
@@ -1,44 +0,0 @@
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;
File without changes