docpouch-client 0.8.14 → 0.8.16
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 +218 -74
- package/dist/index.d.ts +133 -0
- package/dist/index.js +133 -0
- package/package.json +38 -38
- package/src/index.ts +665 -532
package/dist/index.js
CHANGED
|
@@ -86,6 +86,12 @@ export default class docPouchClient {
|
|
|
86
86
|
}
|
|
87
87
|
}
|
|
88
88
|
// User Administration Endpoints
|
|
89
|
+
/**
|
|
90
|
+
* Authenticates a user and stores the returned token for subsequent requests.
|
|
91
|
+
*
|
|
92
|
+
* @param {I_UserLogin} credentials - Username and password credentials.
|
|
93
|
+
* @returns {Promise<I_LoginResponse | null>} Login payload when successful, otherwise null.
|
|
94
|
+
*/
|
|
89
95
|
async login(credentials) {
|
|
90
96
|
const response = await this.request('/users/login', 'POST', credentials, false);
|
|
91
97
|
if (response.token) {
|
|
@@ -98,60 +104,166 @@ export default class docPouchClient {
|
|
|
98
104
|
}
|
|
99
105
|
return null;
|
|
100
106
|
}
|
|
107
|
+
/**
|
|
108
|
+
* Retrieves all users visible to the authenticated user.
|
|
109
|
+
*
|
|
110
|
+
* @returns {Promise<I_UserEntry[]>} A list of user entries.
|
|
111
|
+
*/
|
|
101
112
|
async listUsers() {
|
|
102
113
|
return await this.request('/users/list', 'GET');
|
|
103
114
|
}
|
|
115
|
+
/**
|
|
116
|
+
* Updates a user by ID.
|
|
117
|
+
*
|
|
118
|
+
* @param {string} userID - The ID of the user to update.
|
|
119
|
+
* @param {I_UserUpdate} userData - Partial user fields to update.
|
|
120
|
+
* @returns {Promise<void>}
|
|
121
|
+
*/
|
|
104
122
|
async updateUser(userID, userData) {
|
|
105
123
|
await this.request(`/users/update/${userID}`, 'PATCH', userData);
|
|
106
124
|
}
|
|
125
|
+
/**
|
|
126
|
+
* Creates a new user.
|
|
127
|
+
*
|
|
128
|
+
* @param {I_UserCreation} userData - Data used to create the user.
|
|
129
|
+
* @returns {Promise<I_UserDisplay>} The created user payload returned by the API.
|
|
130
|
+
*/
|
|
107
131
|
async createUser(userData) {
|
|
108
132
|
return await this.request('/users/create', 'POST', userData);
|
|
109
133
|
}
|
|
134
|
+
/**
|
|
135
|
+
* Removes a user by ID.
|
|
136
|
+
*
|
|
137
|
+
* @param {string} userID - The ID of the user to remove.
|
|
138
|
+
* @returns {Promise<void>}
|
|
139
|
+
*/
|
|
110
140
|
async removeUser(userID) {
|
|
111
141
|
await this.request(`/users/remove/${userID}`, 'DELETE');
|
|
112
142
|
}
|
|
113
143
|
// Document Management Endpoints
|
|
144
|
+
/**
|
|
145
|
+
* Creates a new document.
|
|
146
|
+
*
|
|
147
|
+
* @param {I_DocumentEntry} document - The document payload to create.
|
|
148
|
+
* @returns {Promise<I_DocumentEntry>} The created document.
|
|
149
|
+
*/
|
|
114
150
|
async createDocument(document) {
|
|
115
151
|
return await this.request('/docs/create', 'POST', document);
|
|
116
152
|
}
|
|
153
|
+
/**
|
|
154
|
+
* Retrieves all documents visible to the authenticated user.
|
|
155
|
+
*
|
|
156
|
+
* @returns {Promise<I_DocumentEntry[]>} A list of document entries.
|
|
157
|
+
*/
|
|
117
158
|
async listDocuments() {
|
|
118
159
|
return await this.request('/docs/list', 'GET');
|
|
119
160
|
}
|
|
161
|
+
/**
|
|
162
|
+
* Fetches documents matching a query object.
|
|
163
|
+
*
|
|
164
|
+
* @param {I_DocumentQuery} queryObject - Query fields used for filtering.
|
|
165
|
+
* @returns {Promise<I_DocumentEntry[]>} Matching documents.
|
|
166
|
+
*/
|
|
120
167
|
async fetchDocuments(queryObject) {
|
|
121
168
|
return await this.request(`/docs/fetch/`, 'POST', queryObject);
|
|
122
169
|
}
|
|
170
|
+
/**
|
|
171
|
+
* Updates a document by ID.
|
|
172
|
+
*
|
|
173
|
+
* @param {string} documentID - The ID of the document to update.
|
|
174
|
+
* @param {I_DocumentEntry} documentData - Updated document payload.
|
|
175
|
+
* @returns {Promise<void>}
|
|
176
|
+
*/
|
|
123
177
|
async updateDocument(documentID, documentData) {
|
|
124
178
|
await this.request(`/docs/update/${documentID}`, 'PATCH', documentData);
|
|
125
179
|
}
|
|
180
|
+
/**
|
|
181
|
+
* Removes a document by ID.
|
|
182
|
+
*
|
|
183
|
+
* @param {string} documentID - The ID of the document to remove.
|
|
184
|
+
* @returns {Promise<void>}
|
|
185
|
+
*/
|
|
126
186
|
async removeDocument(documentID) {
|
|
127
187
|
await this.request(`/docs/remove/${documentID}`, 'DELETE');
|
|
128
188
|
}
|
|
129
189
|
// Data Structure Endpoints
|
|
190
|
+
/**
|
|
191
|
+
* Creates a new data structure.
|
|
192
|
+
*
|
|
193
|
+
* @param {I_StructureCreation} structure - Data structure payload to create.
|
|
194
|
+
* @returns {Promise<I_DataStructure>} The created data structure.
|
|
195
|
+
*/
|
|
130
196
|
async createStructure(structure) {
|
|
131
197
|
return await this.request('/structures/create', 'POST', structure);
|
|
132
198
|
}
|
|
199
|
+
/**
|
|
200
|
+
* Retrieves all data structures.
|
|
201
|
+
*
|
|
202
|
+
* @returns {Promise<I_DataStructure[]>} A list of data structures.
|
|
203
|
+
*/
|
|
133
204
|
async getStructures() {
|
|
134
205
|
return await this.request('/structures/list', 'GET');
|
|
135
206
|
}
|
|
207
|
+
/**
|
|
208
|
+
* Updates a data structure by ID.
|
|
209
|
+
*
|
|
210
|
+
* @param {string} structureID - The ID of the structure to update.
|
|
211
|
+
* @param {I_DataStructure} structureData - Updated structure payload.
|
|
212
|
+
* @returns {Promise<void>}
|
|
213
|
+
*/
|
|
136
214
|
async updateStructure(structureID, structureData) {
|
|
137
215
|
await this.request(`/structures/update/${structureID}`, 'PATCH', structureData);
|
|
138
216
|
}
|
|
217
|
+
/**
|
|
218
|
+
* Removes a data structure by ID.
|
|
219
|
+
*
|
|
220
|
+
* @param {string} structureID - The ID of the structure to remove.
|
|
221
|
+
* @returns {Promise<void>}
|
|
222
|
+
*/
|
|
139
223
|
async removeStructure(structureID) {
|
|
140
224
|
await this.request(`/structures/remove/${structureID}`, 'DELETE');
|
|
141
225
|
}
|
|
142
226
|
// Data Type Endpoints
|
|
227
|
+
/**
|
|
228
|
+
* Creates or writes a document type.
|
|
229
|
+
*
|
|
230
|
+
* @param {I_DocumentType} type - The type payload.
|
|
231
|
+
* @returns {Promise<I_DocumentType>} The created or updated type.
|
|
232
|
+
*/
|
|
143
233
|
async createType(type) {
|
|
144
234
|
return await this.request('/types/write', 'POST', type);
|
|
145
235
|
}
|
|
236
|
+
/**
|
|
237
|
+
* Removes a document type by ID.
|
|
238
|
+
*
|
|
239
|
+
* @param {string} typeID - The ID of the type to remove.
|
|
240
|
+
* @returns {Promise<void>}
|
|
241
|
+
*/
|
|
146
242
|
async removeType(typeID) {
|
|
147
243
|
return await this.request(`/types/remove/${typeID}`, 'DELETE');
|
|
148
244
|
}
|
|
245
|
+
/**
|
|
246
|
+
* Retrieves all document types.
|
|
247
|
+
*
|
|
248
|
+
* @returns {Promise<I_DocumentType[]>} A list of document types.
|
|
249
|
+
*/
|
|
149
250
|
async getTypes() {
|
|
150
251
|
return await this.request('/types/list', 'GET');
|
|
151
252
|
}
|
|
253
|
+
/**
|
|
254
|
+
* Updates a document type.
|
|
255
|
+
*
|
|
256
|
+
* @param {I_DocumentType} updatedType - The full type payload to persist.
|
|
257
|
+
* @returns {Promise<void>}
|
|
258
|
+
*/
|
|
152
259
|
async updateType(updatedType) {
|
|
153
260
|
await this.request(`/types/write`, 'POST', updatedType);
|
|
154
261
|
}
|
|
262
|
+
/**
|
|
263
|
+
* Sets or clears the authentication token used for API and WebSocket auth.
|
|
264
|
+
*
|
|
265
|
+
* @param {string | null} token - Bearer token to use, or null to clear it.
|
|
266
|
+
*/
|
|
155
267
|
setToken(token) {
|
|
156
268
|
console.log("Setting token to:", token ? "***token***" : "null");
|
|
157
269
|
const tokenChanged = this.authToken !== token;
|
|
@@ -180,9 +292,19 @@ export default class docPouchClient {
|
|
|
180
292
|
this.socket.disconnect();
|
|
181
293
|
}
|
|
182
294
|
}
|
|
295
|
+
/**
|
|
296
|
+
* Returns the package version of this client.
|
|
297
|
+
*
|
|
298
|
+
* @returns {string} The semantic version string.
|
|
299
|
+
*/
|
|
183
300
|
getVersion() {
|
|
184
301
|
return packetJson.version;
|
|
185
302
|
}
|
|
303
|
+
/**
|
|
304
|
+
* Logs socket diagnostics and attempts a reconnect when possible.
|
|
305
|
+
*
|
|
306
|
+
* @returns {void}
|
|
307
|
+
*/
|
|
186
308
|
debugSocketConnection() {
|
|
187
309
|
console.log("Socket connection debug info:");
|
|
188
310
|
console.log("- Connected:", this.socket.connected);
|
|
@@ -280,6 +402,17 @@ export default class docPouchClient {
|
|
|
280
402
|
this.connectionInProgress = false;
|
|
281
403
|
}
|
|
282
404
|
}
|
|
405
|
+
/**
|
|
406
|
+
* Sends an HTTP request to the configured docPouch backend.
|
|
407
|
+
*
|
|
408
|
+
* @template T
|
|
409
|
+
* @param {string} endpoint - Relative API endpoint (with or without leading slash).
|
|
410
|
+
* @param {string} method - HTTP method.
|
|
411
|
+
* @param {any} [body] - Optional JSON body.
|
|
412
|
+
* @param {boolean} [requiresAuth=true] - Whether the Authorization header should be attached.
|
|
413
|
+
* @returns {Promise<T>} Parsed JSON response body.
|
|
414
|
+
* @private
|
|
415
|
+
*/
|
|
283
416
|
async request(endpoint, method, body, requiresAuth = true) {
|
|
284
417
|
const headers = {
|
|
285
418
|
'Content-Type': 'application/json',
|
package/package.json
CHANGED
|
@@ -1,38 +1,38 @@
|
|
|
1
|
-
{
|
|
2
|
-
"name": "docpouch-client",
|
|
3
|
-
"version": "0.8.
|
|
4
|
-
"main": "dist/index.js",
|
|
5
|
-
"types": "dist/index.d.ts",
|
|
6
|
-
"exports": {
|
|
7
|
-
".": {
|
|
8
|
-
"import": "./dist/index.js",
|
|
9
|
-
"require": "./dist/index.js"
|
|
10
|
-
}
|
|
11
|
-
},
|
|
12
|
-
"type": "module",
|
|
13
|
-
"scripts": {
|
|
14
|
-
"build": "tsc",
|
|
15
|
-
"test": "jest"
|
|
16
|
-
},
|
|
17
|
-
"keywords": [
|
|
18
|
-
"docPouch",
|
|
19
|
-
"API"
|
|
20
|
-
],
|
|
21
|
-
"author": "Jan Frecè",
|
|
22
|
-
"license": "MIT",
|
|
23
|
-
"description": "A small class to more easily access the docPouch API",
|
|
24
|
-
"repository": {
|
|
25
|
-
"type": "git",
|
|
26
|
-
"url": "https://github.com/BFH-JTF/docpouch-client"
|
|
27
|
-
},
|
|
28
|
-
"devDependencies": {
|
|
29
|
-
"@types/jest": "^30.0.0",
|
|
30
|
-
"@types/node": "^24.3.0",
|
|
31
|
-
"jest": "^30.0.5",
|
|
32
|
-
"ts-jest": "^29.4.1",
|
|
33
|
-
"typescript": "^5.9.2"
|
|
34
|
-
},
|
|
35
|
-
"dependencies": {
|
|
36
|
-
"socket.io-client": "^4.8.1"
|
|
37
|
-
}
|
|
38
|
-
}
|
|
1
|
+
{
|
|
2
|
+
"name": "docpouch-client",
|
|
3
|
+
"version": "0.8.16",
|
|
4
|
+
"main": "dist/index.js",
|
|
5
|
+
"types": "dist/index.d.ts",
|
|
6
|
+
"exports": {
|
|
7
|
+
".": {
|
|
8
|
+
"import": "./dist/index.js",
|
|
9
|
+
"require": "./dist/index.js"
|
|
10
|
+
}
|
|
11
|
+
},
|
|
12
|
+
"type": "module",
|
|
13
|
+
"scripts": {
|
|
14
|
+
"build": "tsc",
|
|
15
|
+
"test": "jest"
|
|
16
|
+
},
|
|
17
|
+
"keywords": [
|
|
18
|
+
"docPouch",
|
|
19
|
+
"API"
|
|
20
|
+
],
|
|
21
|
+
"author": "Jan Frecè",
|
|
22
|
+
"license": "MIT",
|
|
23
|
+
"description": "A small class to more easily access the docPouch API",
|
|
24
|
+
"repository": {
|
|
25
|
+
"type": "git",
|
|
26
|
+
"url": "https://github.com/BFH-JTF/docpouch-client"
|
|
27
|
+
},
|
|
28
|
+
"devDependencies": {
|
|
29
|
+
"@types/jest": "^30.0.0",
|
|
30
|
+
"@types/node": "^24.3.0",
|
|
31
|
+
"jest": "^30.0.5",
|
|
32
|
+
"ts-jest": "^29.4.1",
|
|
33
|
+
"typescript": "^5.9.2"
|
|
34
|
+
},
|
|
35
|
+
"dependencies": {
|
|
36
|
+
"socket.io-client": "^4.8.1"
|
|
37
|
+
}
|
|
38
|
+
}
|