@lindle/sharepoint_requests 0.1.11 → 0.1.13

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 (41) hide show
  1. package/dist/index.d.ts +4 -2
  2. package/dist/root/index.d.ts +17 -217
  3. package/dist/root/instance.d.ts +2 -2
  4. package/dist/root/internal/context.d.ts +9 -0
  5. package/dist/root/internal/digest.d.ts +2 -0
  6. package/dist/root/internal/emailRequests.d.ts +10 -0
  7. package/dist/root/internal/listRequests/createAttachment.d.ts +3 -0
  8. package/dist/root/internal/listRequests/createListItem.d.ts +3 -0
  9. package/dist/root/internal/listRequests/deleteItem.d.ts +3 -0
  10. package/dist/root/internal/listRequests/getFiles.d.ts +8 -0
  11. package/dist/root/internal/listRequests/getListItems.d.ts +8 -0
  12. package/dist/root/internal/listRequests/getOnly.d.ts +3 -0
  13. package/dist/root/internal/listRequests/index.d.ts +7 -0
  14. package/dist/root/internal/listRequests/updateListItem.d.ts +3 -0
  15. package/dist/root/internal/odata.d.ts +5 -0
  16. package/dist/root/internal/userRequests.d.ts +15 -0
  17. package/dist/sharepoint_requests.cjs.development.js +621 -775
  18. package/dist/sharepoint_requests.cjs.development.js.map +1 -1
  19. package/dist/sharepoint_requests.cjs.production.min.js +1 -1
  20. package/dist/sharepoint_requests.cjs.production.min.js.map +1 -1
  21. package/dist/sharepoint_requests.esm.js +620 -775
  22. package/dist/sharepoint_requests.esm.js.map +1 -1
  23. package/dist/types.d.ts +38 -7
  24. package/package.json +1 -1
  25. package/src/index.ts +37 -28
  26. package/src/root/index.ts +201 -600
  27. package/src/root/instance.ts +22 -13
  28. package/src/root/internal/context.ts +10 -0
  29. package/src/root/internal/digest.ts +22 -0
  30. package/src/root/internal/emailRequests.ts +45 -0
  31. package/src/root/internal/listRequests/createAttachment.ts +18 -0
  32. package/src/root/internal/listRequests/createListItem.ts +36 -0
  33. package/src/root/internal/listRequests/deleteItem.ts +10 -0
  34. package/src/root/internal/listRequests/getFiles.ts +31 -0
  35. package/src/root/internal/listRequests/getListItems.ts +50 -0
  36. package/src/root/internal/listRequests/getOnly.ts +18 -0
  37. package/src/root/internal/listRequests/index.ts +7 -0
  38. package/src/root/internal/listRequests/updateListItem.ts +32 -0
  39. package/src/root/internal/odata.ts +36 -0
  40. package/src/root/internal/userRequests.ts +109 -0
  41. package/src/types.ts +76 -36
package/dist/index.d.ts CHANGED
@@ -1,4 +1,5 @@
1
1
  import SHAREPOINT_REQUESTS from './root';
2
+ import type { CreateAxiosDefaults as AxiosConfig } from 'axios';
2
3
  import type { LookupField, ChoiceField, PersonField } from './types';
3
4
  export default function createBase<T extends {
4
5
  LISTS: Record<string, any>;
@@ -7,9 +8,10 @@ export default function createBase<T extends {
7
8
  /**
8
9
  * @deprecated Use `create` instead.
9
10
  */
10
- baseURL(url: string): SHAREPOINT_REQUESTS<T>;
11
- create: ({ baseURL }: {
11
+ baseURL(url: string, config?: AxiosConfig): SHAREPOINT_REQUESTS<T>;
12
+ create: ({ baseURL, config, }: {
12
13
  baseURL: string;
14
+ config?: AxiosConfig;
13
15
  }) => SHAREPOINT_REQUESTS<T>;
14
16
  };
15
17
  export { LookupField, ChoiceField, PersonField };
@@ -1,86 +1,47 @@
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';
1
+ import { CreateAxiosDefaults as AxiosConfig } from 'axios';
2
+ import { CreateFileProps, CurrentUser, EmailProps, Field_Options, Folder_Options, IListName, ItemID, ListData, Options, PersonField, SHAREPOINT_VER, UserPermision, UserProfile } from '../types';
3
3
  declare class HTTPSharePointRequests<T extends {
4
- LISTS: Record<string, any>;
5
- FOLDERS?: Record<string, any>;
4
+ LISTS: Record<string, unknown>;
5
+ FOLDERS?: Record<string, unknown>;
6
6
  }> {
7
7
  private baseURL;
8
8
  private endpoint;
9
9
  private listName;
10
10
  private instance;
11
- /**
12
- * Creates an HTTP SharePoint requester bound to the provided base URL.
13
- *
14
- * @param baseURL The root SharePoint site URL (with or without trailing slash).
15
- */
16
- constructor(baseURL: string);
17
- /**
18
- * Converts array values in a payload to the `Collection(Edm.String)` structure
19
- * expected by SharePoint REST endpoints.
20
- *
21
- * @param data The list item payload to harmonise in-place.
22
- */
23
- private transformArraysToEdmStrings;
11
+ private sharepointVersion;
12
+ constructor(baseURL: string, config?: AxiosConfig);
13
+ private getContext;
24
14
  /**
25
15
  * @deprecated Use `from` instead.
26
16
  */
27
17
  list(listName: IListName<T>): this;
28
18
  readonly lists: {
29
- /**
30
- * Fetches all SharePoint lists available to the current site.
31
- *
32
- * @returns Promise resolving to the list collection response payload.
33
- */
34
19
  get: () => Promise<{
35
- data: any[];
20
+ data: Partial<import("../types").SPItem2013>[];
36
21
  meta: {
37
22
  url: URL;
38
23
  };
39
24
  }>;
40
25
  };
41
- /**
42
- * Selects a SharePoint list and exposes list-scoped CRUD helpers.
43
- *
44
- * @param listName Logical list key configured in the generic type map.
45
- * @param sharepoint_ver SharePoint version used to choose the correct REST endpoint.
46
- * @returns Chainable helpers bound to the selected list.
47
- */
48
- from<K extends Extract<keyof T['LISTS'], string>>(listName: K, sharepoint_ver?: SHAREPOINT_VER): {
49
- create: (data: ListData) => Promise<AxiosResponse<any, any, {}>>;
50
- get: (options?: Options<T['LISTS'][K]>) => Promise<{
51
- data: (T["LISTS"][K] & Partial<SPItem>)[];
26
+ from<K extends Extract<keyof T['LISTS'], string>, V extends SHAREPOINT_VER = '2013'>(listName: K, sharepoint_ver?: V): {
27
+ create: (data: ListData) => Promise<import("axios").AxiosResponse<any, any, {}>>;
28
+ get: (options?: Options<T['LISTS'][K], V>) => Promise<{
29
+ data: (T["LISTS"][K] & Partial<import("../types").SPItem<V>>)[];
52
30
  meta: {
53
31
  url: URL;
54
32
  };
55
33
  }>;
56
- update: (id: ItemID, data: ListData, digest?: string) => Promise<AxiosResponse<any, any, {}>>;
57
- delete: (id: ItemID) => Promise<AxiosResponse<any, any, {}>>;
58
- createFile: (props: CreateFileProps) => Promise<AxiosResponse<any, any, {}>>;
59
- fields: (options?: Field_Options<T['LISTS'][K]>) => {
34
+ update: (id: ItemID, data: ListData, digest?: string) => Promise<import("axios").AxiosResponse<any, any, {}>>;
35
+ delete: (id: ItemID) => Promise<import("axios").AxiosResponse<any, any, {}>>;
36
+ createFile: (props: CreateFileProps) => Promise<import("axios").AxiosResponse<any, any, {}>>;
37
+ fields: (options?: Field_Options<T['LISTS'][K], V>) => {
60
38
  get: () => Promise<any>;
61
39
  };
62
40
  };
63
41
  folders: {
64
- /**
65
- * Retrieves SharePoint folders from the default folders endpoint.
66
- *
67
- * @returns A promise resolving with folder metadata.
68
- */
69
42
  get: () => void;
70
43
  };
71
- /**
72
- * Targets a SharePoint folder path and exposes file retrieval helpers.
73
- *
74
- * @param folderName Optional folder path relative to `Shared Documents`.
75
- * @returns Helper exposing `get` to fetch files or sub-folders.
76
- */
77
44
  folder(folderName?: string | string[]): {
78
- /**
79
- * Fetches files or folders from the targeted path.
80
- *
81
- * @param options Optional REST query options to refine the result set.
82
- * @returns Promise resolving to folder contents and metadata.
83
- */
84
45
  get: (options?: Folder_Options<any>) => Promise<{
85
46
  data: any;
86
47
  meta: {
@@ -88,18 +49,7 @@ declare class HTTPSharePointRequests<T extends {
88
49
  };
89
50
  }>;
90
51
  };
91
- /**
92
- * Retrieves user list items and exposes a get helper with optional query parameters.
93
- *
94
- * @param options Optional REST query options.
95
- * @returns Helper exposing `get` returning SharePoint user rows.
96
- */
97
52
  users(options?: Options<any>): {
98
- /**
99
- * Executes the user list request using the specified options.
100
- *
101
- * @returns Promise resolving to the SharePoint user list response.
102
- */
103
53
  get: () => Promise<{
104
54
  data: any[];
105
55
  meta: {
@@ -107,175 +57,25 @@ declare class HTTPSharePointRequests<T extends {
107
57
  };
108
58
  }>;
109
59
  };
110
- /**
111
- * Asynchronously retrieves the Form Digest Value from the context information API.
112
- *
113
- * @returns {Promise<string>} A promise that resolves to the Form Digest Value.
114
- * @throws {Error} If the HTTP request fails or the response does not contain the expected data.
115
- */
116
- private getDigest;
117
- /**
118
- * Executes a GET request without additional metadata wrapping.
119
- *
120
- * @param options Optional REST query options.
121
- * @returns SharePoint response payload or undefined when empty.
122
- */
123
- private get_only;
124
- /**
125
- * Retrieves folder contents with optional filtering and returns the payload with metadata.
126
- *
127
- * @param options REST options describing expand/filter/order conditions.
128
- * @returns Folder data and the fully resolved request URL.
129
- */
130
- private get_files;
131
- /**
132
- * Performs a typed list read against the current endpoint.
133
- *
134
- * @param options Optional REST query options governing expand, filter, ordering and pagination.
135
- * @returns SharePoint list items alongside the fully-resolved request URL.
136
- */
137
- private get_v2;
138
- /**
139
- * Updates an item in the currently selected list.
140
- *
141
- * @param id Target list item identifier.
142
- * @param data Payload with fields to update.
143
- * @param digest Optional pre-fetched form digest to reuse.
144
- * @returns Axios response of the update request.
145
- */
146
- private update_2;
147
- /**
148
- * Creates a new item within the active list.
149
- *
150
- * @param listData SharePoint list item payload.
151
- * @returns Axios response resolved from the create request.
152
- */
153
- private create_v2;
154
- /**
155
- * Uploads an attachment file to an existing list item.
156
- *
157
- * @param props File payload and target item identifier.
158
- * @returns Axios response describing the upload result.
159
- */
160
- private createFile;
161
- /**
162
- * Deletes an item using the current endpoint.
163
- *
164
- * @param ID Identifier of the entity to remove.
165
- * @returns Axios response from the delete call.
166
- */
167
- private delete;
168
60
  email: {
169
- /**
170
- * Sends an email using SharePoint's Utility.SendEmail API.
171
- *
172
- * @param {EmailProps} param0 - The email properties.
173
- * @param {string} param0.From - The sender's email address.
174
- * @example
175
- * Example of a sender's email address
176
- * "sender@example.com"
177
- * @param {string | string[]} param0.To - The recipient's email address or an array of email addresses.
178
- * @example
179
- * Example of a single recipient's email address
180
- * "recipient@example.com"
181
- * Example of multiple recipients' email addresses
182
- * ["recipient1@example.com", "recipient2@example.com"]
183
- * @param {string} param0.Subject - The subject of the email.
184
- * @example
185
- * Example of an email subject
186
- * "Meeting Reminder"
187
- * @param {string} param0.Body - The body content of the email.
188
- * @example
189
- * Example of an email body
190
- * "Dear team, please be reminded of the meeting scheduled for tomorrow at 10 AM."
191
- * @returns {Promise<any>} - A promise that resolves to the response of the email send request.
192
- */
193
- send: (props: EmailProps) => Promise<AxiosResponse<{
61
+ send: (props: EmailProps) => Promise<import("axios").AxiosResponse<{
194
62
  d: {
195
63
  SendEmail: null;
196
64
  };
197
65
  }, any, {}>>;
198
66
  };
199
- private sendEmail;
200
- /**
201
- * Queries SharePoint's people picker endpoint for matching users.
202
- *
203
- * @param input Free-text search term.
204
- * @param filter Optional additional filter condition.
205
- * @returns Promise with type-ahead results payload.
206
- */
207
- private typeAhead;
208
- /**
209
- * Retrieves the current user profile and flattens selected properties.
210
- *
211
- * @returns Promise containing the current user's profile information.
212
- */
213
- private currentUserProperties;
214
67
  user: {
215
- /**
216
- * Provides accessors for the current user's profile information.
217
- *
218
- * @returns Helper exposing a `get` function to retrieve profile details.
219
- */
220
68
  properties: () => {
221
69
  get: () => Promise<UserProfile>;
222
70
  };
223
- /**
224
- * Searches across site users and their groups.
225
- *
226
- * @param searchValue Query string to match site users.
227
- * @returns Promise resolving to matching site users.
228
- */
229
71
  searchSiteUser: (searchValue: string) => Promise<any>;
230
- /**
231
- * Performs a people-picker search scoped to the current site collection.
232
- *
233
- * @param input Search prefix.
234
- * @param filter Optional additional filter condition.
235
- * @returns Promise with type-ahead person results.
236
- */
237
72
  searchUser: (input: string, filter?: string) => Promise<PersonField>;
238
- /**
239
- * Fetches the currently authenticated SharePoint user.
240
- *
241
- * @returns Helper exposing `get` that resolves to the current user payload.
242
- */
243
73
  current: () => {
244
74
  get: () => Promise<CurrentUser>;
245
75
  };
246
- /**
247
- * Retrieves calculated permission level for the current user.
248
- *
249
- * @returns Helper exposing `get` resolving to the user's permission definition.
250
- */
251
76
  currentPermission: () => {
252
77
  get: () => Promise<UserPermision>;
253
78
  };
254
79
  };
255
- /**
256
- * Searches site users based on a substring match across common fields.
257
- *
258
- * @param searchValue Term to match against the SharePoint user directory.
259
- * @returns Promise with matching site users and their groups.
260
- */
261
- private getSiteUser;
262
- /**
263
- * Retrieves all available role definitions for the current site.
264
- *
265
- * @returns Promise resolving to an array of role definitions.
266
- */
267
- private roleDefinitions;
268
- /**
269
- * Fetches the bit-encoded permissions of the current user.
270
- *
271
- * @returns Promise resolving to the `EffectiveBasePermissions` object.
272
- */
273
- private getEffectiveBasePermissions;
274
- /**
275
- * Matches the current user's effective permissions against known role definitions.
276
- *
277
- * @returns The matching SharePoint role definition as a structured permission object.
278
- */
279
- private currentUserPermissions;
280
80
  }
281
81
  export default HTTPSharePointRequests;
@@ -1,3 +1,3 @@
1
- import { CreateAxiosDefaults } from 'axios';
2
- export declare const instance: (baseURL: string, config?: CreateAxiosDefaults) => import("axios").AxiosInstance;
1
+ import { CreateAxiosDefaults as AxiosConfig } from 'axios';
2
+ export declare const instance: (baseURL: string, config?: AxiosConfig) => import("axios").AxiosInstance;
3
3
  export default instance;
@@ -0,0 +1,9 @@
1
+ import type { AxiosInstance } from 'axios';
2
+ import type { SHAREPOINT_VER } from '../../types';
3
+ export interface RequestContext<V extends SHAREPOINT_VER = '2013'> {
4
+ instance: AxiosInstance;
5
+ baseURL: string;
6
+ endpoint: string;
7
+ listName: string;
8
+ sharepointVersion: V;
9
+ }
@@ -0,0 +1,2 @@
1
+ import type { AxiosInstance } from 'axios';
2
+ export declare function fetchDigest(instance: AxiosInstance, baseURL: string): Promise<string>;
@@ -0,0 +1,10 @@
1
+ import type { AxiosResponse } from 'axios';
2
+ import type { EmailProps } from '../../types';
3
+ import type { RequestContext } from './context';
4
+ declare type SendEmailResponse = AxiosResponse<{
5
+ d: {
6
+ SendEmail: null;
7
+ };
8
+ }>;
9
+ export declare function sendEmail(context: RequestContext, { From, To, Subject, Body }: EmailProps): Promise<SendEmailResponse>;
10
+ export {};
@@ -0,0 +1,3 @@
1
+ import type { CreateFileProps, SHAREPOINT_VER } from '../../../types';
2
+ import type { RequestContext } from '../context';
3
+ export declare function createAttachment<V extends SHAREPOINT_VER = '2013'>(context: RequestContext<V>, { file, itemId }: CreateFileProps): Promise<import("axios").AxiosResponse<any, any, {}>>;
@@ -0,0 +1,3 @@
1
+ import type { ListData, SHAREPOINT_VER } from '../../../types';
2
+ import type { RequestContext } from '../context';
3
+ export declare function createListItem<V extends SHAREPOINT_VER = '2013'>(context: RequestContext<V>, listData: ListData): Promise<import("axios").AxiosResponse<any, any, {}>>;
@@ -0,0 +1,3 @@
1
+ import type { SHAREPOINT_VER } from '../../../types';
2
+ import type { RequestContext } from '../context';
3
+ export declare function deleteItem<V extends SHAREPOINT_VER = '2013'>(context: RequestContext<V>, id: number | string): Promise<import("axios").AxiosResponse<any, any, {}>>;
@@ -0,0 +1,8 @@
1
+ import type { Folder_Options, SHAREPOINT_VER } from '../../../types';
2
+ import type { RequestContext } from '../context';
3
+ export declare function getFiles<T, V extends SHAREPOINT_VER = '2013'>(context: RequestContext<V>, options?: Folder_Options<T>): Promise<{
4
+ data: any;
5
+ meta: {
6
+ url: URL;
7
+ };
8
+ }>;
@@ -0,0 +1,8 @@
1
+ import type { Options, SPItem, SHAREPOINT_VER } from '../../../types';
2
+ import type { RequestContext } from '../context';
3
+ export declare function getListItems<K, V extends SHAREPOINT_VER = '2013'>(context: RequestContext<V>, options?: Options<K, V>): Promise<{
4
+ data: (K & Partial<SPItem<V>>)[];
5
+ meta: {
6
+ url: URL;
7
+ };
8
+ }>;
@@ -0,0 +1,3 @@
1
+ import type { AxiosInstance } from 'axios';
2
+ import type { Options, SHAREPOINT_VER } from '../../../types';
3
+ export declare function getOnly<T, V extends SHAREPOINT_VER = '2013'>(instance: AxiosInstance, endpoint: string, options?: Options<T, V>): Promise<any>;
@@ -0,0 +1,7 @@
1
+ export { createListItem } from './createListItem';
2
+ export { createAttachment } from './createAttachment';
3
+ export { deleteItem } from './deleteItem';
4
+ export { getFiles } from './getFiles';
5
+ export { getListItems } from './getListItems';
6
+ export { getOnly } from './getOnly';
7
+ export { updateListItem } from './updateListItem';
@@ -0,0 +1,3 @@
1
+ import type { ListData, SHAREPOINT_VER } from '../../../types';
2
+ import type { RequestContext } from '../context';
3
+ export declare function updateListItem<V extends SHAREPOINT_VER = '2013'>(context: RequestContext<V>, id: number | string, data: ListData, digest?: string): Promise<import("axios").AxiosResponse<any, any, {}>>;
@@ -0,0 +1,5 @@
1
+ import type { Folder_Options, Options, SHAREPOINT_VER } from '../../types';
2
+ declare type QueryableOptions<T, V extends SHAREPOINT_VER = '2013'> = Options<T, V> | Folder_Options<T>;
3
+ export declare function buildODataParams<T, V extends SHAREPOINT_VER = '2013'>(options: QueryableOptions<T, V> | undefined, orderBySeparator?: ',' | ' '): Record<string, string | number>;
4
+ export declare function appendParamsToUrl(baseUrl: URL, params: Record<string, string | number | undefined | null>): void;
5
+ export {};
@@ -0,0 +1,15 @@
1
+ import type { AxiosInstance } from 'axios';
2
+ import type { PersonField, UserPermision, UserProfile } from '../../types';
3
+ import type { RequestContext } from './context';
4
+ declare type RoleDefinition = {
5
+ BasePermissions: {
6
+ High: string;
7
+ };
8
+ };
9
+ export declare function typeAhead(instance: AxiosInstance, input: string, filter?: string): Promise<PersonField>;
10
+ export declare function currentUserProperties(instance: AxiosInstance): Promise<UserProfile>;
11
+ export declare function getSiteUser(instance: AxiosInstance, searchValue: string): Promise<any>;
12
+ export declare function roleDefinitions(instance: AxiosInstance): Promise<RoleDefinition[]>;
13
+ export declare function getEffectiveBasePermissions(instance: AxiosInstance): Promise<any>;
14
+ export declare function currentUserPermissions(context: RequestContext): Promise<UserPermision>;
15
+ export {};