@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.
- package/README.md +121 -116
- package/dist/index.d.mts +469 -0
- package/dist/index.d.ts +460 -8
- package/dist/index.js +892 -5
- package/dist/index.js.map +1 -0
- package/dist/index.mjs +863 -0
- package/dist/index.mjs.map +1 -0
- package/package.json +5 -5
- package/src/index.ts +3 -5
- package/src/root/index.ts +281 -146
- package/src/root/instance.ts +7 -0
- package/src/root/internal/context.ts +2 -3
- package/src/root/internal/digest.ts +18 -11
- package/src/root/internal/emailRequests.ts +5 -11
- package/src/root/internal/listRequests/createAttachment.ts +16 -5
- package/src/root/internal/listRequests/createListItem.ts +18 -27
- package/src/root/internal/listRequests/deleteFile.ts +5 -5
- package/src/root/internal/listRequests/deleteItem.ts +17 -3
- package/src/root/internal/listRequests/getFiles.ts +4 -10
- package/src/root/internal/listRequests/getListItems.ts +43 -9
- package/src/root/internal/listRequests/getOnly.ts +10 -7
- package/src/root/internal/listRequests/normalizePayload.ts +1 -1
- package/src/root/internal/listRequests/resolveMetadataType.ts +14 -0
- package/src/root/internal/listRequests/updateListItem.ts +24 -30
- package/src/root/internal/listRequests/uploadFile.ts +13 -21
- package/src/root/internal/listRequests/utils.ts +1 -1
- package/src/root/internal/odata.ts +2 -4
- package/src/root/internal/sharepointUrl.ts +7 -0
- package/src/root/internal/userRequests.ts +93 -37
- package/src/types.ts +154 -149
- package/dist/root/index.d.ts +0 -88
- package/dist/root/instance.d.ts +0 -3
- package/dist/root/internal/context.d.ts +0 -11
- package/dist/root/internal/digest.d.ts +0 -2
- package/dist/root/internal/emailRequests.d.ts +0 -10
- package/dist/root/internal/listRequests/createAttachment.d.ts +0 -3
- package/dist/root/internal/listRequests/createListItem.d.ts +0 -3
- package/dist/root/internal/listRequests/deleteFile.d.ts +0 -3
- package/dist/root/internal/listRequests/deleteItem.d.ts +0 -3
- package/dist/root/internal/listRequests/getFiles.d.ts +0 -8
- package/dist/root/internal/listRequests/getListItems.d.ts +0 -8
- package/dist/root/internal/listRequests/getOnly.d.ts +0 -3
- package/dist/root/internal/listRequests/index.d.ts +0 -9
- package/dist/root/internal/listRequests/normalizePayload.d.ts +0 -4
- package/dist/root/internal/listRequests/updateListItem.d.ts +0 -3
- package/dist/root/internal/listRequests/uploadFile.d.ts +0 -6
- package/dist/root/internal/listRequests/utils.d.ts +0 -2
- package/dist/root/internal/odata.d.ts +0 -5
- package/dist/root/internal/userRequests.d.ts +0 -15
- package/dist/sharepoint_requests.cjs.development.js +0 -1325
- package/dist/sharepoint_requests.cjs.development.js.map +0 -1
- package/dist/sharepoint_requests.cjs.production.min.js +0 -2
- package/dist/sharepoint_requests.cjs.production.min.js.map +0 -1
- package/dist/sharepoint_requests.esm.js +0 -1318
- package/dist/sharepoint_requests.esm.js.map +0 -1
- package/dist/types.d.ts +0 -256
package/README.md
CHANGED
|
@@ -1,179 +1,184 @@
|
|
|
1
1
|
# HTTP SharePoint Requests
|
|
2
2
|
|
|
3
|
-
|
|
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
|
-
##
|
|
14
|
-
|
|
15
|
-
### Create a SharePoint Request Instance
|
|
12
|
+
## Quick Start
|
|
16
13
|
|
|
17
|
-
```
|
|
14
|
+
```ts
|
|
18
15
|
import createBase from '@lindle/sharepoint_requests';
|
|
19
16
|
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
### Basic Methods
|
|
17
|
+
type Task = {
|
|
18
|
+
Title: string;
|
|
19
|
+
Description?: string;
|
|
20
|
+
CategoryRef?: number;
|
|
21
|
+
};
|
|
26
22
|
|
|
27
|
-
|
|
23
|
+
type DB = {
|
|
24
|
+
LISTS: {
|
|
25
|
+
Tasks: Task;
|
|
26
|
+
};
|
|
27
|
+
};
|
|
28
28
|
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
29
|
+
const sp = createBase<DB>().create({
|
|
30
|
+
baseURL: 'https://tenant.sharepoint.com/sites/demo',
|
|
31
|
+
});
|
|
32
32
|
```
|
|
33
33
|
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
```typescript
|
|
37
|
-
const lists = await sharepoint.lists().get();
|
|
38
|
-
console.log(lists);
|
|
39
|
-
```
|
|
34
|
+
## API Overview
|
|
40
35
|
|
|
41
|
-
|
|
36
|
+
### 1. List scope (`from`) - doporučené
|
|
42
37
|
|
|
43
|
-
|
|
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
|
-
|
|
40
|
+
```ts
|
|
41
|
+
const tasks = sp.from('Tasks');
|
|
49
42
|
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
43
|
+
const { data, meta } = await tasks.get({
|
|
44
|
+
cols: ['Title'],
|
|
45
|
+
limit: 10,
|
|
46
|
+
orderBy: ['Title', 'asc'],
|
|
54
47
|
});
|
|
55
|
-
|
|
48
|
+
|
|
49
|
+
console.log(meta.url.toString());
|
|
56
50
|
```
|
|
57
51
|
|
|
58
|
-
|
|
52
|
+
### 2. CRUD položek
|
|
59
53
|
|
|
60
|
-
```
|
|
61
|
-
const
|
|
62
|
-
|
|
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
|
-
|
|
62
|
+
await tasks.update(15, {
|
|
63
|
+
Title: 'Prepare monthly report (final)',
|
|
64
|
+
});
|
|
68
65
|
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
66
|
+
await tasks.delete(15);
|
|
67
|
+
// alias:
|
|
68
|
+
await tasks.remove(15);
|
|
72
69
|
```
|
|
73
70
|
|
|
74
|
-
###
|
|
75
|
-
|
|
76
|
-
#### Upload Files
|
|
71
|
+
### 3. Pole (fields) listu
|
|
77
72
|
|
|
78
|
-
```
|
|
79
|
-
const
|
|
80
|
-
await
|
|
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
|
-
|
|
84
|
-
await
|
|
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
|
-
|
|
81
|
+
### 4. Přílohy a soubory
|
|
92
82
|
|
|
93
|
-
```
|
|
94
|
-
|
|
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
|
-
|
|
86
|
+
const attachment = new File(['hello'], "O'Brien.txt");
|
|
87
|
+
await tasks.createFile({ file: attachment, itemId: 10 });
|
|
104
88
|
|
|
105
|
-
|
|
106
|
-
const
|
|
107
|
-
console.log(currentUser);
|
|
108
|
-
```
|
|
89
|
+
const docs = sp.from('Tasks', '2013');
|
|
90
|
+
const doc = new File(['contract body'], 'contract.pdf');
|
|
109
91
|
|
|
110
|
-
|
|
92
|
+
await docs.uploadFile({
|
|
93
|
+
file: doc,
|
|
94
|
+
folderPath: ['Shared', 'Contracts', '2026'],
|
|
95
|
+
overwrite: true,
|
|
96
|
+
});
|
|
111
97
|
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
98
|
+
await docs.deleteFile({
|
|
99
|
+
fileName: 'contract.pdf',
|
|
100
|
+
folderPath: ['Shared', 'Contracts', '2026'],
|
|
101
|
+
});
|
|
115
102
|
```
|
|
116
103
|
|
|
117
|
-
|
|
104
|
+
`files` namespace alias:
|
|
118
105
|
|
|
119
|
-
|
|
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
|
-
###
|
|
112
|
+
### 5. Folder endpoint
|
|
122
113
|
|
|
123
|
-
|
|
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
|
-
|
|
126
|
-
|
|
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
|
-
###
|
|
135
|
-
|
|
136
|
-
The package is fully typed, enabling autocompletion and type safety for all methods.
|
|
125
|
+
### 6. Users + Email
|
|
137
126
|
|
|
138
|
-
|
|
127
|
+
```ts
|
|
128
|
+
const currentUser = await sp.getCurrentUser();
|
|
129
|
+
const profile = await sp.currentUserProperties();
|
|
130
|
+
const permission = await sp.currentUserPermission();
|
|
139
131
|
|
|
140
|
-
|
|
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
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
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
|
-
|
|
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
|
-
|
|
152
|
+
## SharePoint Version
|
|
151
153
|
|
|
152
|
-
|
|
153
|
-
- `from(listName)` - Access specific list operations.
|
|
154
|
+
Default je `2013`.
|
|
154
155
|
|
|
155
|
-
|
|
156
|
+
```ts
|
|
157
|
+
await sp.from('Tasks', '2013').get();
|
|
158
|
+
await sp.from('Tasks', '2010').get();
|
|
159
|
+
```
|
|
156
160
|
|
|
157
|
-
|
|
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
|
-
|
|
163
|
+
## Response Shape
|
|
163
164
|
|
|
164
|
-
|
|
165
|
-
- `userGetId(userName)` - Get the ID of a user by username.
|
|
165
|
+
Kolekce vrací:
|
|
166
166
|
|
|
167
|
-
|
|
167
|
+
```ts
|
|
168
|
+
{
|
|
169
|
+
data: ...,
|
|
170
|
+
meta: { url: URL }
|
|
171
|
+
}
|
|
172
|
+
```
|
|
168
173
|
|
|
169
|
-
|
|
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
|
-
##
|
|
176
|
+
## Notes
|
|
174
177
|
|
|
175
|
-
|
|
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
|
|
184
|
+
MIT (viz `LICENSE`).
|