@lindle/sharepoint_requests 0.1.18 → 0.1.20

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.
Files changed (56) hide show
  1. package/README.md +121 -116
  2. package/dist/index.d.mts +469 -0
  3. package/dist/index.d.ts +460 -8
  4. package/dist/index.js +892 -5
  5. package/dist/index.js.map +1 -0
  6. package/dist/index.mjs +863 -0
  7. package/dist/index.mjs.map +1 -0
  8. package/package.json +5 -5
  9. package/src/index.ts +3 -5
  10. package/src/root/index.ts +281 -146
  11. package/src/root/instance.ts +7 -0
  12. package/src/root/internal/context.ts +2 -3
  13. package/src/root/internal/digest.ts +18 -11
  14. package/src/root/internal/emailRequests.ts +5 -11
  15. package/src/root/internal/listRequests/createAttachment.ts +16 -5
  16. package/src/root/internal/listRequests/createListItem.ts +18 -27
  17. package/src/root/internal/listRequests/deleteFile.ts +5 -5
  18. package/src/root/internal/listRequests/deleteItem.ts +17 -3
  19. package/src/root/internal/listRequests/getFiles.ts +4 -10
  20. package/src/root/internal/listRequests/getListItems.ts +43 -9
  21. package/src/root/internal/listRequests/getOnly.ts +10 -7
  22. package/src/root/internal/listRequests/normalizePayload.ts +1 -1
  23. package/src/root/internal/listRequests/resolveMetadataType.ts +14 -0
  24. package/src/root/internal/listRequests/updateListItem.ts +24 -30
  25. package/src/root/internal/listRequests/uploadFile.ts +13 -21
  26. package/src/root/internal/listRequests/utils.ts +1 -1
  27. package/src/root/internal/odata.ts +2 -4
  28. package/src/root/internal/sharepointUrl.ts +7 -0
  29. package/src/root/internal/userRequests.ts +93 -37
  30. package/src/types.ts +154 -149
  31. package/dist/root/index.d.ts +0 -88
  32. package/dist/root/instance.d.ts +0 -3
  33. package/dist/root/internal/context.d.ts +0 -11
  34. package/dist/root/internal/digest.d.ts +0 -2
  35. package/dist/root/internal/emailRequests.d.ts +0 -10
  36. package/dist/root/internal/listRequests/createAttachment.d.ts +0 -3
  37. package/dist/root/internal/listRequests/createListItem.d.ts +0 -3
  38. package/dist/root/internal/listRequests/deleteFile.d.ts +0 -3
  39. package/dist/root/internal/listRequests/deleteItem.d.ts +0 -3
  40. package/dist/root/internal/listRequests/getFiles.d.ts +0 -8
  41. package/dist/root/internal/listRequests/getListItems.d.ts +0 -8
  42. package/dist/root/internal/listRequests/getOnly.d.ts +0 -3
  43. package/dist/root/internal/listRequests/index.d.ts +0 -9
  44. package/dist/root/internal/listRequests/normalizePayload.d.ts +0 -4
  45. package/dist/root/internal/listRequests/updateListItem.d.ts +0 -3
  46. package/dist/root/internal/listRequests/uploadFile.d.ts +0 -6
  47. package/dist/root/internal/listRequests/utils.d.ts +0 -2
  48. package/dist/root/internal/odata.d.ts +0 -5
  49. package/dist/root/internal/userRequests.d.ts +0 -15
  50. package/dist/sharepoint_requests.cjs.development.js +0 -1325
  51. package/dist/sharepoint_requests.cjs.development.js.map +0 -1
  52. package/dist/sharepoint_requests.cjs.production.min.js +0 -2
  53. package/dist/sharepoint_requests.cjs.production.min.js.map +0 -1
  54. package/dist/sharepoint_requests.esm.js +0 -1318
  55. package/dist/sharepoint_requests.esm.js.map +0 -1
  56. package/dist/types.d.ts +0 -256
package/README.md CHANGED
@@ -1,179 +1,184 @@
1
1
  # HTTP SharePoint Requests
2
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.
3
+ TypeScript knihovna pro práci se SharePoint REST API nad `axios`.
4
+ Primární cíl je jednodušší skládání URL, bezpečnější CRUD a čitelnější API.
4
5
 
5
6
  ## Installation
6
7
 
7
- Install the package using npm:
8
-
9
8
  ```bash
10
9
  npm install @lindle/sharepoint_requests
11
10
  ```
12
11
 
13
- ## Usage
14
-
15
- ### Create a SharePoint Request Instance
12
+ ## Quick Start
16
13
 
17
- ```typescript
14
+ ```ts
18
15
  import createBase from '@lindle/sharepoint_requests';
19
16
 
20
- const sharepoint = createBase().create({
21
- baseURL: 'https://your-sharepoint-site.com',
22
- });
23
- ```
24
-
25
- ### Basic Methods
17
+ type Task = {
18
+ Title: string;
19
+ Description?: string;
20
+ CategoryRef?: number;
21
+ };
26
22
 
27
- #### Retrieve List Fields
23
+ type DB = {
24
+ LISTS: {
25
+ Tasks: Task;
26
+ };
27
+ };
28
28
 
29
- ```typescript
30
- const fields = await sharepoint.field('ListName', 'FieldName');
31
- console.log(fields);
29
+ const sp = createBase<DB>().create({
30
+ baseURL: 'https://tenant.sharepoint.com/sites/demo',
31
+ });
32
32
  ```
33
33
 
34
- #### Access Lists
35
-
36
- ```typescript
37
- const lists = await sharepoint.lists().get();
38
- console.log(lists);
39
- ```
34
+ ## API Overview
40
35
 
41
- #### Access Items in a List
36
+ ### 1. List scope (`from`) - doporučené
42
37
 
43
- ```typescript
44
- const { data, meta } = await sharepoint.from('ListName').get({ limit: 10 });
45
- console.log({ data, meta });
46
- ```
38
+ `from(listName)` vrací immutable scope. Každý scope drží vlastní endpoint/context, takže paralelní volání si navzájem nepřepisují stav.
47
39
 
48
- #### Create a New Item in a List
40
+ ```ts
41
+ const tasks = sp.from('Tasks');
49
42
 
50
- ```typescript
51
- const newItem = await sharepoint.from('ListName').create({
52
- Title: 'New Item',
53
- Description: 'This is a new item.',
43
+ const { data, meta } = await tasks.get({
44
+ cols: ['Title'],
45
+ limit: 10,
46
+ orderBy: ['Title', 'asc'],
54
47
  });
55
- console.log(newItem);
48
+
49
+ console.log(meta.url.toString());
56
50
  ```
57
51
 
58
- #### Update an Item in a List
52
+ ### 2. CRUD položek
59
53
 
60
- ```typescript
61
- const updatedItem = await sharepoint.from('ListName').update(1, {
62
- Title: 'Updated Title',
54
+ ```ts
55
+ const tasks = sp.from('Tasks');
56
+
57
+ await tasks.create({
58
+ Title: 'Prepare monthly report',
59
+ Description: 'Draft v1 by Friday',
63
60
  });
64
- console.log(updatedItem);
65
- ```
66
61
 
67
- #### Delete an Item in a List
62
+ await tasks.update(15, {
63
+ Title: 'Prepare monthly report (final)',
64
+ });
68
65
 
69
- ```typescript
70
- await sharepoint.from('ListName').delete(1);
71
- console.log('Item deleted successfully');
66
+ await tasks.delete(15);
67
+ // alias:
68
+ await tasks.remove(15);
72
69
  ```
73
70
 
74
- ### Advanced Features
75
-
76
- #### Upload Files
71
+ ### 3. Pole (fields) listu
77
72
 
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');
73
+ ```ts
74
+ const allFields = await sp.from('Tasks').fields().get();
75
+ const titleField = await sp.from('Tasks').fields({ fieldName: 'Title' }).get();
82
76
 
83
- const doc = new File(['doc content'], 'document.pdf');
84
- await sharepoint.from('Documents', '2013').uploadFile({ file: doc, folderPath: 'Shared/SubFolder' });
85
- console.log('Library file uploaded successfully');
86
-
87
- await sharepoint.from('Documents').deleteFile({ fileName: 'document.pdf', folderPath: 'Shared/SubFolder' });
88
- console.log('Library file deleted successfully');
77
+ // shortcut:
78
+ const titleField2 = await sp.field('Tasks', 'Title');
89
79
  ```
90
80
 
91
- #### Send Emails
81
+ ### 4. Přílohy a soubory
92
82
 
93
- ```typescript
94
- await sharepoint.email(
95
- 'sender@example.com',
96
- ['recipient@example.com'],
97
- 'Subject of Email',
98
- 'Body of the email content.'
99
- );
100
- console.log('Email sent successfully');
101
- ```
83
+ ```ts
84
+ const tasks = sp.from('Tasks');
102
85
 
103
- #### Retrieve Current User Information
86
+ const attachment = new File(['hello'], "O'Brien.txt");
87
+ await tasks.createFile({ file: attachment, itemId: 10 });
104
88
 
105
- ```typescript
106
- const currentUser = await sharepoint.getCurrentUser();
107
- console.log(currentUser);
108
- ```
89
+ const docs = sp.from('Tasks', '2013');
90
+ const doc = new File(['contract body'], 'contract.pdf');
109
91
 
110
- #### Retrieve User Properties
92
+ await docs.uploadFile({
93
+ file: doc,
94
+ folderPath: ['Shared', 'Contracts', '2026'],
95
+ overwrite: true,
96
+ });
111
97
 
112
- ```typescript
113
- const userProfile = await sharepoint.currentUserProperties();
114
- console.log(userProfile);
98
+ await docs.deleteFile({
99
+ fileName: 'contract.pdf',
100
+ folderPath: ['Shared', 'Contracts', '2026'],
101
+ });
115
102
  ```
116
103
 
117
- ### Authentication
104
+ `files` namespace alias:
118
105
 
119
- Ensure that the requests are authenticated by passing the appropriate cookies or tokens for your SharePoint environment.
106
+ ```ts
107
+ await sp.from('Tasks').files.attach({ file: attachment, itemId: 10 });
108
+ await sp.from('Tasks').files.upload({ file: doc });
109
+ await sp.from('Tasks').files.remove({ fileName: 'contract.pdf' });
110
+ ```
120
111
 
121
- ### Error Handling
112
+ ### 5. Folder endpoint
122
113
 
123
- Handle errors using try-catch blocks:
114
+ ```ts
115
+ const folderData = await sp.folder(['Shared Documents', 'Invoices']).get({
116
+ type: 'Files',
117
+ cols: ['Name'],
118
+ limit: 20,
119
+ });
124
120
 
125
- ```typescript
126
- try {
127
- const lists = await sharepoint.lists().get();
128
- console.log(lists);
129
- } catch (error) {
130
- console.error('An error occurred:', error);
131
- }
121
+ // default type je Files:
122
+ const folderData2 = await sp.folder('Shared Documents/Invoices').get();
132
123
  ```
133
124
 
134
- ### TypeScript Support
135
-
136
- The package is fully typed, enabling autocompletion and type safety for all methods.
125
+ ### 6. Users + Email
137
126
 
138
- ## API Reference
127
+ ```ts
128
+ const currentUser = await sp.getCurrentUser();
129
+ const profile = await sp.currentUserProperties();
130
+ const permission = await sp.currentUserPermission();
139
131
 
140
- ### Constructor
132
+ const siteUsers = await sp.users({ limit: 25 }).get();
133
+ const searchResult = await sp.user.searchUser('john.doe');
134
+ const matchedSiteUsers = await sp.user.searchSiteUser("o'connor");
141
135
 
142
- #### `createBase<T>()`
143
-
144
- - Creates a base instance for SharePoint requests.
145
- - **Params:**
146
- - `baseURL` (string): The base URL of your SharePoint site.
136
+ await sp.sendEmail({
137
+ From: 'sender@company.com',
138
+ To: ['recipient@company.com'],
139
+ Subject: 'Build status',
140
+ Body: 'Deployment completed.',
141
+ });
147
142
 
148
- ### Methods
143
+ // kompatibilní shortcut:
144
+ await sp.email(
145
+ 'sender@company.com',
146
+ ['recipient@company.com'],
147
+ 'Build status',
148
+ 'Deployment completed.'
149
+ );
150
+ ```
149
151
 
150
- #### Lists
152
+ ## SharePoint Version
151
153
 
152
- - `lists().get()` - Retrieve all lists in the SharePoint site.
153
- - `from(listName)` - Access specific list operations.
154
+ Default je `2013`.
154
155
 
155
- #### Items
156
+ ```ts
157
+ await sp.from('Tasks', '2013').get();
158
+ await sp.from('Tasks', '2010').get();
159
+ ```
156
160
 
157
- - `create(data)` - Create a new list item.
158
- - `get(options)` - Retrieve list items with filters, sorting, and limits.
159
- - `update(id, data)` - Update an existing list item.
160
- - `delete(id)` - Delete a list item.
161
+ `list(listName)` je stále dostupné jako deprecated alias na `from(listName, '2010')`.
161
162
 
162
- #### Users
163
+ ## Response Shape
163
164
 
164
- - `getCurrentUser()` - Retrieve the current user information.
165
- - `userGetId(userName)` - Get the ID of a user by username.
165
+ Kolekce vrací:
166
166
 
167
- #### Files
167
+ ```ts
168
+ {
169
+ data: ...,
170
+ meta: { url: URL }
171
+ }
172
+ ```
168
173
 
169
- - `createFile({ file, itemId })` - Upload a file to a list item.
170
- - `uploadFile({ file, folderPath, overwrite })` - Upload a file to a document library (SharePoint 2013).
171
- - `deleteFile({ fileName, folderPath })` - Delete a file from a document library (SharePoint 2013).
174
+ To zjednodušuje debug výsledné OData URL.
172
175
 
173
- ## Development
176
+ ## Notes
174
177
 
175
- Feel free to contribute or report issues. Pull requests are welcome.
178
+ - Knihovna předpokládá, že autentizaci řeší prostředí (cookies/tokeny).
179
+ - Write operace používají `X-RequestDigest`.
180
+ - Názvy listů, fieldů a souborů se interně escapují pro OData string literal.
176
181
 
177
182
  ## License
178
183
 
179
- MIT License. See [LICENSE](LICENSE) for details.
184
+ MIT (viz `LICENSE`).