@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 ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2024 lion.oncemore@gmail.com
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,170 @@
1
+ # HTTP SharePoint Requests
2
+
3
+ This package is a TypeScript library for interacting with SharePoint REST APIs. It provides a structured and flexible approach to perform CRUD operations, handle user information, manage files, and retrieve metadata from SharePoint lists.
4
+
5
+ ## Installation
6
+
7
+ Install the package using npm:
8
+
9
+ ```bash
10
+ npm install sharepoint-requests
11
+ ```
12
+
13
+ ## Usage
14
+
15
+ ### Create a SharePoint Request Instance
16
+
17
+ ```typescript
18
+ import createBase from 'sharepoint-requests';
19
+
20
+ const sharepoint = createBase().create({
21
+ baseURL: 'https://your-sharepoint-site.com',
22
+ });
23
+ ```
24
+
25
+ ### Basic Methods
26
+
27
+ #### Retrieve List Fields
28
+
29
+ ```typescript
30
+ const fields = await sharepoint.field('ListName', 'FieldName');
31
+ console.log(fields);
32
+ ```
33
+
34
+ #### Access Lists
35
+
36
+ ```typescript
37
+ const lists = await sharepoint.lists().get();
38
+ console.log(lists);
39
+ ```
40
+
41
+ #### Access Items in a List
42
+
43
+ ```typescript
44
+ const { data, meta } = await sharepoint.from('ListName').get({ limit: 10 });
45
+ console.log({ data, meta });
46
+ ```
47
+
48
+ #### Create a New Item in a List
49
+
50
+ ```typescript
51
+ const newItem = await sharepoint.from('ListName').create({
52
+ Title: 'New Item',
53
+ Description: 'This is a new item.',
54
+ });
55
+ console.log(newItem);
56
+ ```
57
+
58
+ #### Update an Item in a List
59
+
60
+ ```typescript
61
+ const updatedItem = await sharepoint.from('ListName').update(1, {
62
+ Title: 'Updated Title',
63
+ });
64
+ console.log(updatedItem);
65
+ ```
66
+
67
+ #### Delete an Item in a List
68
+
69
+ ```typescript
70
+ await sharepoint.from('ListName').delete(1);
71
+ console.log('Item deleted successfully');
72
+ ```
73
+
74
+ ### Advanced Features
75
+
76
+ #### Upload Files
77
+
78
+ ```typescript
79
+ const file = new File(['content'], 'example.txt');
80
+ await sharepoint.from('ListName').createFile({ file, itemId: 1 });
81
+ console.log('File uploaded successfully');
82
+ ```
83
+
84
+ #### Send Emails
85
+
86
+ ```typescript
87
+ await sharepoint.email(
88
+ 'sender@example.com',
89
+ ['recipient@example.com'],
90
+ 'Subject of Email',
91
+ 'Body of the email content.'
92
+ );
93
+ console.log('Email sent successfully');
94
+ ```
95
+
96
+ #### Retrieve Current User Information
97
+
98
+ ```typescript
99
+ const currentUser = await sharepoint.getCurrentUser();
100
+ console.log(currentUser);
101
+ ```
102
+
103
+ #### Retrieve User Properties
104
+
105
+ ```typescript
106
+ const userProfile = await sharepoint.currentUserProperties();
107
+ console.log(userProfile);
108
+ ```
109
+
110
+ ### Authentication
111
+
112
+ Ensure that the requests are authenticated by passing the appropriate cookies or tokens for your SharePoint environment.
113
+
114
+ ### Error Handling
115
+
116
+ Handle errors using try-catch blocks:
117
+
118
+ ```typescript
119
+ try {
120
+ const lists = await sharepoint.lists().get();
121
+ console.log(lists);
122
+ } catch (error) {
123
+ console.error('An error occurred:', error);
124
+ }
125
+ ```
126
+
127
+ ### TypeScript Support
128
+
129
+ The package is fully typed, enabling autocompletion and type safety for all methods.
130
+
131
+ ## API Reference
132
+
133
+ ### Constructor
134
+
135
+ #### `createBase<T>()`
136
+
137
+ - Creates a base instance for SharePoint requests.
138
+ - **Params:**
139
+ - `baseURL` (string): The base URL of your SharePoint site.
140
+
141
+ ### Methods
142
+
143
+ #### Lists
144
+
145
+ - `lists().get()` - Retrieve all lists in the SharePoint site.
146
+ - `from(listName)` - Access specific list operations.
147
+
148
+ #### Items
149
+
150
+ - `create(data)` - Create a new list item.
151
+ - `get(options)` - Retrieve list items with filters, sorting, and limits.
152
+ - `update(id, data)` - Update an existing list item.
153
+ - `delete(id)` - Delete a list item.
154
+
155
+ #### Users
156
+
157
+ - `getCurrentUser()` - Retrieve the current user information.
158
+ - `userGetId(userName)` - Get the ID of a user by username.
159
+
160
+ #### Files
161
+
162
+ - `createFile({ file, itemId })` - Upload a file to a list item.
163
+
164
+ ## Development
165
+
166
+ Feel free to contribute or report issues. Pull requests are welcome.
167
+
168
+ ## License
169
+
170
+ MIT License. See [LICENSE](LICENSE) for details.
@@ -0,0 +1,15 @@
1
+ import SHAREPOINT_REQUESTS from './root';
2
+ import type { LookupField, ChoiceField, PersonField } from './types';
3
+ export default function createBase<T extends {
4
+ LISTS: Record<string, any>;
5
+ FOLDERS?: Record<string, any>;
6
+ } = any>(): {
7
+ /**
8
+ * @deprecated Use `create` instead.
9
+ */
10
+ baseURL(url: string): SHAREPOINT_REQUESTS<T>;
11
+ create: ({ baseURL }: {
12
+ baseURL: string;
13
+ }) => SHAREPOINT_REQUESTS<T>;
14
+ };
15
+ export { LookupField, ChoiceField, PersonField };
package/dist/index.js ADDED
@@ -0,0 +1,8 @@
1
+
2
+ 'use strict'
3
+
4
+ if (process.env.NODE_ENV === 'production') {
5
+ module.exports = require('./sharepoint_requests.cjs.production.min.js')
6
+ } else {
7
+ module.exports = require('./sharepoint_requests.cjs.development.js')
8
+ }
@@ -0,0 +1,125 @@
1
+ import { AxiosResponse } from 'axios';
2
+ import { CreateFileProps, CurrentUser, EmailProps, Field_Options, Folder_Options, IListName, ItemID, ListData, Options, PersonField, SHAREPOINT_VER, SPItem, UserPermision, UserProfile } from '../types';
3
+ declare class HTTPSharePointRequests<T extends {
4
+ LISTS: Record<string, any>;
5
+ FOLDERS?: Record<string, any>;
6
+ }> {
7
+ private baseURL;
8
+ private endpoint;
9
+ private listName;
10
+ private instance;
11
+ constructor(baseURL: string);
12
+ private transformArraysToEdmStrings;
13
+ /**
14
+ * @deprecated Use `from` instead.
15
+ */
16
+ list(listName: IListName<T>): this;
17
+ readonly lists: {
18
+ get: () => Promise<{
19
+ data: any[];
20
+ meta: {
21
+ url: URL;
22
+ };
23
+ }>;
24
+ };
25
+ from<K extends Extract<keyof T['LISTS'], string>>(listName: K, sharepoint_ver?: SHAREPOINT_VER): {
26
+ create: (data: ListData) => Promise<AxiosResponse<any, any>>;
27
+ get: (options?: Options<T['LISTS'][K]>) => Promise<{
28
+ data: (T["LISTS"][K] & Partial<SPItem>)[];
29
+ meta: {
30
+ url: URL;
31
+ };
32
+ }>;
33
+ update: (id: ItemID, data: ListData, digest?: string) => Promise<AxiosResponse<any, any>>;
34
+ delete: (id: ItemID) => Promise<AxiosResponse<any, any>>;
35
+ createFile: (props: CreateFileProps) => Promise<AxiosResponse<any, any>>;
36
+ fields: (options?: Field_Options<T['LISTS'][K]>) => {
37
+ get: () => Promise<any>;
38
+ };
39
+ };
40
+ folders: {
41
+ get: () => void;
42
+ };
43
+ folder(folderName?: string | string[]): {
44
+ get: (options?: Folder_Options<any>) => Promise<{
45
+ data: any;
46
+ meta: {
47
+ url: URL;
48
+ };
49
+ }>;
50
+ };
51
+ users: {
52
+ get: (options?: Options<any>) => Promise<{
53
+ data: any[];
54
+ meta: {
55
+ url: URL;
56
+ };
57
+ }>;
58
+ };
59
+ /**
60
+ * Asynchronously retrieves the Form Digest Value from the context information API.
61
+ *
62
+ * @returns {Promise<string>} A promise that resolves to the Form Digest Value.
63
+ * @throws {Error} If the HTTP request fails or the response does not contain the expected data.
64
+ */
65
+ private getDigest;
66
+ private get_only;
67
+ private get_files;
68
+ private get_v2;
69
+ private update_2;
70
+ private create_v2;
71
+ private createFile;
72
+ private delete;
73
+ email: {
74
+ /**
75
+ * Sends an email using SharePoint's Utility.SendEmail API.
76
+ *
77
+ * @param {EmailProps} param0 - The email properties.
78
+ * @param {string} param0.From - The sender's email address.
79
+ * @example
80
+ * Example of a sender's email address
81
+ * "sender@example.com"
82
+ * @param {string | string[]} param0.To - The recipient's email address or an array of email addresses.
83
+ * @example
84
+ * Example of a single recipient's email address
85
+ * "recipient@example.com"
86
+ * Example of multiple recipients' email addresses
87
+ * ["recipient1@example.com", "recipient2@example.com"]
88
+ * @param {string} param0.Subject - The subject of the email.
89
+ * @example
90
+ * Example of an email subject
91
+ * "Meeting Reminder"
92
+ * @param {string} param0.Body - The body content of the email.
93
+ * @example
94
+ * Example of an email body
95
+ * "Dear team, please be reminded of the meeting scheduled for tomorrow at 10 AM."
96
+ * @returns {Promise<any>} - A promise that resolves to the response of the email send request.
97
+ */
98
+ send: (props: EmailProps) => Promise<AxiosResponse<{
99
+ d: {
100
+ SendEmail: null;
101
+ };
102
+ }, any>>;
103
+ };
104
+ private sendEmail;
105
+ private typeAhead;
106
+ private currentUserProperties;
107
+ user: {
108
+ properties: () => {
109
+ get: () => Promise<UserProfile>;
110
+ };
111
+ searchSiteUser: (searchValue: string) => Promise<any>;
112
+ searchUser: (input: string, filter?: string) => Promise<PersonField>;
113
+ current: () => {
114
+ get: () => Promise<CurrentUser>;
115
+ };
116
+ currentPermission: () => {
117
+ get: () => Promise<UserPermision>;
118
+ };
119
+ };
120
+ private getSiteUser;
121
+ private roleDefinitions;
122
+ private getEffectiveBasePermissions;
123
+ private currentUserPermissions;
124
+ }
125
+ export default HTTPSharePointRequests;
@@ -0,0 +1,7 @@
1
+ import { AxiosInstance } from 'axios';
2
+ declare type GetDigestProps = {
3
+ instance: AxiosInstance;
4
+ baseURL: string;
5
+ };
6
+ declare const getDigest: ({ instance, baseURL, }: GetDigestProps) => Promise<string>;
7
+ export default getDigest;
@@ -0,0 +1,13 @@
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;