docpouch-client 0.8.5 → 0.8.6

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 ADDED
@@ -0,0 +1,305 @@
1
+ # docpouch-client
2
+
3
+ A TypeScript client library for interacting with the [docPouch](https://github.com/BFH-JTF/doc-pouch) database API.
4
+
5
+ ## Description
6
+
7
+ docpouch-client provides a simple and intuitive interface to access the docPouch API, allowing you to manage users,
8
+ documents, data structures, and document types. It also supports real-time synchronization via WebSockets.
9
+
10
+ ## Installation
11
+
12
+ ```bash
13
+ npm install docpouch-client
14
+ ```
15
+
16
+ ## Usage
17
+
18
+ ### Initializing the Client
19
+
20
+ ```typescript
21
+ import docPouchClient from 'docpouch-client';
22
+
23
+ // Initialize the client with the server URL
24
+ const client = new docPouchClient('https://your-docpouch-server.com', 80);
25
+
26
+ // Initialize with a callback for real-time updates
27
+ const client = new docPouchClient('https://your-docpouch-server.com', 80,
28
+ (event, data) => {
29
+ console.log(`Received event: ${event}`, data);
30
+ }
31
+ );
32
+ ```
33
+
34
+ ### Authentication
35
+
36
+ ```typescript
37
+ // Login to get an authentication token
38
+ const loginResponse = await client.login({
39
+ name: 'username',
40
+ password: 'password'
41
+ });
42
+
43
+ if (loginResponse) {
44
+ console.log('Login successful!');
45
+ console.log(`Token: ${loginResponse.token}`);
46
+ } else {
47
+ console.log('Login failed');
48
+ }
49
+
50
+ // Set an existing token
51
+ client.setToken('your-auth-token');
52
+ ```
53
+
54
+ ### User Management
55
+
56
+ ```typescript
57
+ // List all users
58
+ const users = await client.listUsers();
59
+
60
+ // Create a new user
61
+ const newUser = await client.createUser({
62
+ name: 'newuser',
63
+ password: 'password',
64
+ department: 'IT',
65
+ group: 'Developers',
66
+ isAdmin: false
67
+ });
68
+
69
+ // Update a user
70
+ await client.updateUser('user-id', {
71
+ department: 'Engineering',
72
+ group: 'Frontend'
73
+ });
74
+
75
+ // Remove a user
76
+ await client.removeUser('user-id');
77
+ ```
78
+
79
+ ### Document Management
80
+
81
+ ```typescript
82
+ // Create a new document
83
+ const newDocument = await client.createDocument({
84
+ type: 17,
85
+ subType: 11,
86
+ title: "Mission Statement",
87
+ content: "{\"msg\": \"We strive for a world that...\"}",
88
+ shareWithGroup: false,
89
+ shareWithDepartment: false
90
+ });
91
+
92
+ // Update a document
93
+ await client.updateDocument('document-id', {
94
+ title: 'Updated Mission Statement',
95
+ content: '{"msg": "Our updated mission..."}'
96
+ });
97
+
98
+ // Delete a document
99
+ await client.deleteDocument('document-id');
100
+
101
+ // Fetch documents by query
102
+ const documents = await client.fetchDocuments([
103
+ {type: 17, subType: 11}
104
+ ]);
105
+ ```
106
+
107
+ ### Data Structure Management
108
+
109
+ ```typescript
110
+ // Create a new data structure
111
+ const newStructure = await client.createDataStructure({
112
+ title: "Data resulting from Vision-Mission-Value-Canvas",
113
+ fields: [
114
+ {
115
+ name: "Mission value statement",
116
+ type: "string"
117
+ },
118
+ // Add more fields as needed
119
+ ]
120
+ });
121
+
122
+ // Update a data structure
123
+ await client.updateDataStructure('structure-id', {
124
+ title: 'Updated Structure Title',
125
+ fields: [
126
+ {name: 'New Field Name', type: 'number'}
127
+ ]
128
+ });
129
+
130
+ // Delete a data structure
131
+ await client.deleteDataStructure('structure-id');
132
+
133
+ // List all data structures
134
+ const structures = await client.listDataStructures();
135
+ ```
136
+
137
+ ### Document Type Management
138
+
139
+ ```typescript
140
+ // List all document types
141
+ const docTypes = await client.listDocumentTypes();
142
+
143
+ // Create or update a document type
144
+ const newDocType = await client.createOrUpdateDocumentType({
145
+ name: "HR Wages",
146
+ description: "HR Wage information Document listing wages per personnel ID",
147
+ type: 14,
148
+ subType: 2,
149
+ defaultStructureID: 'structure-id'
150
+ });
151
+
152
+ // Delete a document type
153
+ await client.deleteDocumentType('doc-type-id');
154
+ ```
155
+
156
+ ## API Reference
157
+
158
+ ### Client Class
159
+
160
+ #### Constructor
161
+
162
+ - `new docPouchClient(baseUrl: string, port: number, callback?: (event: string, data: any) => void)`
163
+
164
+ #### Methods
165
+
166
+ - `login(credentials: { name: string, password: string }): Promise<{ token: string } | null>`
167
+ - `setToken(token: string): void`
168
+ - `listUsers(): Promise<UserDisplay[]>`
169
+ - `createUser(userData: UserCreation): Promise<UserDisplay>`
170
+ - `updateUser(id: string, userData: UserUpdate): Promise<void>`
171
+ - `removeUser(id: string): Promise<void>`
172
+ - `createDocument(docData: NewDocument): Promise<Document>`
173
+ - `updateDocument(id: string, docData: Partial<Document>): Promise<void>`
174
+ - `deleteDocument(id: string): Promise<void>`
175
+ - `fetchDocuments(query: DocumentQuery[]): Promise<Document[]>`
176
+ - `createDataStructure(structureData: DataStructureCreation): Promise<DataStructure>`
177
+ - `updateDataStructure(id: string, structureData: Partial<DataStructure>): Promise<void>`
178
+ - `deleteDataStructure(id: string): Promise<void>`
179
+ - `listDataStructures(): Promise<DataStructure[]>`
180
+ - `listDocumentTypes(): Promise<DocumentTypeEdit[]>`
181
+ - `createOrUpdateDocumentType(typeData: DocumentTypeEdit): Promise<void>`
182
+ - `deleteDocumentType(id: string): Promise<void>`
183
+
184
+ ## Types
185
+
186
+ ### UserDisplay
187
+
188
+ ```typescript
189
+ {
190
+ _id: number;
191
+ name: string;
192
+ email ? : string;
193
+ department: string;
194
+ group: string;
195
+ }
196
+ ```
197
+
198
+ ### UserCreation
199
+
200
+ ```typescript
201
+ {
202
+ name: string;
203
+ password: string;
204
+ email ? : string;
205
+ department: string;
206
+ group: string;
207
+ isAdmin: boolean;
208
+ }
209
+ ```
210
+
211
+ ### UserUpdate
212
+
213
+ ```typescript
214
+ {
215
+ name ? : string;
216
+ password ? : string;
217
+ email ? : string;
218
+ isAdmin ? : boolean;
219
+ department ? : string;
220
+ group ? : string;
221
+ }
222
+ ```
223
+
224
+ ### Document
225
+
226
+ ```typescript
227
+ {
228
+ _id: string;
229
+ type: number;
230
+ subType: number;
231
+ title: string;
232
+ content: string;
233
+ shareWithGroup: boolean;
234
+ shareWithDepartment: boolean;
235
+ }
236
+ ```
237
+
238
+ ### NewDocument
239
+
240
+ ```typescript
241
+ {
242
+ type: number;
243
+ subType: number;
244
+ title: string;
245
+ content: string;
246
+ shareWithGroup: boolean;
247
+ shareWithDepartment: boolean;
248
+ }
249
+ ```
250
+
251
+ ### DocumentQuery
252
+
253
+ ```typescript
254
+ {
255
+ _id ? : string;
256
+ type ? : number;
257
+ subType ? : number;
258
+ title ? : string;
259
+ description ? : string;
260
+ shareWithGroup ? : boolean;
261
+ shareWithDepartment ? : boolean;
262
+ }
263
+ ```
264
+
265
+ ### DataStructure
266
+
267
+ ```typescript
268
+ {
269
+ _id: number;
270
+ title: string;
271
+ fields: DataField[];
272
+ }
273
+ ```
274
+
275
+ ### DataStructureCreation
276
+
277
+ ```typescript
278
+ {
279
+ title: string;
280
+ fields: DataField[];
281
+ }
282
+ ```
283
+
284
+ ### DataField
285
+
286
+ ```typescript
287
+ {
288
+ name: string;
289
+ type: 'number' | 'string' | 'boolean' | 'array' | 'structure';
290
+ items ? : string; // For array and structure types
291
+ }
292
+ ```
293
+
294
+ ### DocumentTypeEdit
295
+
296
+ ```typescript
297
+ {
298
+ _id ? : string;
299
+ name: string;
300
+ description ? : string;
301
+ type: number;
302
+ subType: number;
303
+ defaultStructureID ? : string;
304
+ }
305
+ ```
package/dist/index.js CHANGED
@@ -94,7 +94,7 @@ export default class docPouchClient {
94
94
  if (this.realTimeSync) {
95
95
  this.initWebSocket();
96
96
  }
97
- return { token: response.token, isAdmin: response.isAdmin };
97
+ return { token: response.token, isAdmin: response.isAdmin, userName: response.userName };
98
98
  }
99
99
  return null;
100
100
  }
package/dist/types.d.ts CHANGED
@@ -14,6 +14,7 @@ export interface I_UserCreation {
14
14
  isAdmin: boolean;
15
15
  }
16
16
  export interface I_UserUpdate {
17
+ _id: string;
17
18
  name?: string;
18
19
  password?: string;
19
20
  email?: string;
@@ -31,6 +32,7 @@ export interface I_UserDisplay {
31
32
  export interface I_LoginResponse {
32
33
  token: string;
33
34
  isAdmin: boolean;
35
+ userName: string;
34
36
  }
35
37
  export interface I_DocumentEntry extends I_DocumentCreationOwned {
36
38
  _id: string;
@@ -41,6 +43,8 @@ export interface I_DocumentCreation {
41
43
  type: number;
42
44
  subType: number;
43
45
  content: any;
46
+ shareWithGroup: boolean;
47
+ shareWithDepartment: boolean;
44
48
  }
45
49
  export interface I_DocumentCreationOwned extends I_DocumentCreation {
46
50
  owner: string;
@@ -56,33 +60,36 @@ export interface I_DocumentQuery {
56
60
  title?: string;
57
61
  type?: number;
58
62
  subType?: number;
63
+ shareWithGroup?: boolean;
64
+ shareWithDepartment?: boolean;
59
65
  }
60
66
  export interface I_DataStructure {
61
67
  _id?: string | undefined;
62
68
  name: string;
63
69
  description: string;
64
- reference?: any;
65
- fields: any[];
70
+ fields: I_StructureField[];
71
+ }
72
+ export interface I_StructureField {
73
+ name: string;
74
+ type: string;
75
+ items?: string;
66
76
  }
67
77
  export interface I_StructureEntry {
68
78
  _id?: string;
69
79
  name: string;
70
80
  description: string;
71
- reference?: any;
72
- fields: any[];
81
+ fields: I_StructureField[];
73
82
  }
74
83
  export interface I_StructureCreation {
75
84
  name: string;
76
85
  description?: string;
77
- reference?: any;
78
- fields: any[];
86
+ fields: I_StructureField[];
79
87
  }
80
88
  export interface I_StructureUpdate {
81
89
  _id: string;
82
90
  name?: string;
83
91
  description?: string;
84
- reference?: any;
85
- fields?: any[];
92
+ fields?: I_StructureField[];
86
93
  }
87
94
  export interface I_DocumentType {
88
95
  _id?: string;
@@ -92,7 +99,7 @@ export interface I_DocumentType {
92
99
  description?: string;
93
100
  defaultStructureID?: string;
94
101
  }
95
- export type I_EventString = 'subscribe' | 'unsubscribe' | 'heartbeatPong' | "heartbeatPing" | "newDocument" | "newStructure" | "newUser" | "removedID" | "changedDocument" | "changedStructure" | "changedUser" | "confirmSubscription" | "confirmUnsubscription" | "removedUser" | "removedStructure" | "removedDocument";
102
+ export type I_EventString = 'heartbeatPong' | "heartbeatPing" | "newDocument" | "newStructure" | "newUser" | "newType" | "removedID" | "changedDocument" | "changedStructure" | "changedUser" | "changedType" | "removedUser" | "removedStructure" | "removedDocument" | "removedType";
96
103
  export interface I_WsMessage {
97
104
  newDocument?: I_DocumentEntry;
98
105
  newStructure?: I_StructureEntry;
@@ -105,4 +112,5 @@ export interface I_WsMessage {
105
112
  confirmUnsubscription?: boolean;
106
113
  heartbeatPing?: number;
107
114
  heartbeatPong?: number;
115
+ newType?: I_DocumentType;
108
116
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "docpouch-client",
3
- "version": "0.8.5",
3
+ "version": "0.8.6",
4
4
  "main": "dist/index.js",
5
5
  "types": "dist/index.d.ts",
6
6
  "exports": {
@@ -23,8 +23,8 @@
23
23
  "description": "A small class to more easily access the docPouch API",
24
24
  "devDependencies": {
25
25
  "@types/jest": "^30.0.0",
26
- "@types/node": "^24.0.3",
27
- "jest": "^30.0.2",
26
+ "@types/node": "^24.0.7",
27
+ "jest": "^30.0.3",
28
28
  "ts-jest": "^29.4.0"
29
29
  },
30
30
  "dependencies": {
package/src/index.ts CHANGED
@@ -134,7 +134,7 @@ export default class docPouchClient {
134
134
  this.initWebSocket();
135
135
  }
136
136
 
137
- return {token: response.token, isAdmin: response.isAdmin};
137
+ return {token: response.token, isAdmin: response.isAdmin, userName: response.userName};
138
138
  }
139
139
  return null;
140
140
  }
@@ -195,7 +195,7 @@ export default class docPouchClient {
195
195
 
196
196
  // Data Type Endpoints
197
197
  async createType(type: I_DocumentType): Promise<I_DocumentType> {
198
- return await this.request<I_DocumentType>('/types/write', 'PATCH', type);
198
+ return await this.request<I_DocumentType>('/types/write', 'POST', type);
199
199
  }
200
200
 
201
201
  async removeType(typeID: string) {
@@ -207,7 +207,7 @@ export default class docPouchClient {
207
207
  }
208
208
 
209
209
  async updateType(updatedType: I_DocumentType): Promise<void> {
210
- await this.request<void>(`/types/write`, 'PATCH', updatedType);
210
+ await this.request<void>(`/types/write`, 'POST', updatedType);
211
211
  }
212
212
 
213
213
  setToken(token: string | null): void {
package/src/types.ts CHANGED
@@ -20,6 +20,7 @@ export interface I_UserCreation {
20
20
  }
21
21
 
22
22
  export interface I_UserUpdate {
23
+ _id: string;
23
24
  name?: string;
24
25
  password?: string;
25
26
  email?: string;
@@ -39,6 +40,7 @@ export interface I_UserDisplay {
39
40
  export interface I_LoginResponse {
40
41
  token: string;
41
42
  isAdmin: boolean;
43
+ userName: string;
42
44
  }
43
45
 
44
46
  // Document related types
@@ -52,8 +54,11 @@ export interface I_DocumentCreation {
52
54
  type: number;
53
55
  subType: number;
54
56
  content: any;
57
+ shareWithGroup: boolean;
58
+ shareWithDepartment: boolean;
55
59
  }
56
60
 
61
+
57
62
  export interface I_DocumentCreationOwned extends I_DocumentCreation {
58
63
  owner: string;
59
64
  }
@@ -70,38 +75,44 @@ export interface I_DocumentQuery {
70
75
  title?: string;
71
76
  type?: number;
72
77
  subType?: number;
78
+ shareWithGroup?: boolean;
79
+ shareWithDepartment?: boolean;
73
80
  }
74
81
 
82
+
75
83
  // Structure related types
76
84
  export interface I_DataStructure {
77
85
  _id?: string | undefined;
78
86
  name: string;
79
87
  description: string;
80
- reference?: any;
81
- fields: any[];
88
+ fields: I_StructureField[];
89
+ }
90
+
91
+ export interface I_StructureField {
92
+ name: string;
93
+ type: string;
94
+ items?: string;
82
95
  }
83
96
 
84
97
  export interface I_StructureEntry {
85
98
  _id?: string;
86
99
  name: string;
87
100
  description: string;
88
- reference?: any;
89
- fields: any[];
101
+ fields: I_StructureField[];
90
102
  }
91
103
 
104
+
92
105
  export interface I_StructureCreation {
93
106
  name: string;
94
107
  description?: string;
95
- reference?: any;
96
- fields: any[];
108
+ fields: I_StructureField[];
97
109
  }
98
110
 
99
111
  export interface I_StructureUpdate {
100
112
  _id: string;
101
113
  name?: string;
102
114
  description?: string;
103
- reference?: any;
104
- fields?: any[];
115
+ fields?: I_StructureField[];
105
116
  }
106
117
 
107
118
  // Document type related types
@@ -115,9 +126,9 @@ export interface I_DocumentType {
115
126
  }
116
127
 
117
128
  // WebSocket-related types
118
- export type I_EventString = 'subscribe' | 'unsubscribe' | 'heartbeatPong' | "heartbeatPing" | "newDocument" | "newStructure" |
119
- "newUser" | "removedID" | "changedDocument" | "changedStructure" | "changedUser" | "confirmSubscription" |
120
- "confirmUnsubscription" | "removedUser" | "removedStructure" | "removedDocument";
129
+ export type I_EventString = 'heartbeatPong' | "heartbeatPing" | "newDocument" | "newStructure" |
130
+ "newUser" | "newType" | "removedID" | "changedDocument" | "changedStructure" | "changedUser" | "changedType" |
131
+ "removedUser" | "removedStructure" | "removedDocument" | "removedType";
121
132
 
122
133
  export interface I_WsMessage {
123
134
  newDocument?: I_DocumentEntry;
@@ -131,4 +142,5 @@ export interface I_WsMessage {
131
142
  confirmUnsubscription?: boolean;
132
143
  heartbeatPing?: number;
133
144
  heartbeatPong?: number;
145
+ newType?: I_DocumentType;
134
146
  }