docpouch-client 0.8.6 → 0.8.8
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/package.json +8 -4
- package/src/index.ts +147 -11
- package/tsconfig.json +5 -1
- package/dist/index.d.ts +0 -93
- package/dist/index.js +0 -308
- package/dist/types.d.ts +0 -116
- package/dist/types.js +0 -2
- package/src/types.ts +0 -146
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "docpouch-client",
|
|
3
|
-
"version": "0.8.
|
|
3
|
+
"version": "0.8.8",
|
|
4
4
|
"main": "dist/index.js",
|
|
5
5
|
"types": "dist/index.d.ts",
|
|
6
6
|
"exports": {
|
|
@@ -21,14 +21,18 @@
|
|
|
21
21
|
"author": "Jan Frecè",
|
|
22
22
|
"license": "MIT",
|
|
23
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
|
+
},
|
|
24
28
|
"devDependencies": {
|
|
25
29
|
"@types/jest": "^30.0.0",
|
|
26
30
|
"@types/node": "^24.0.7",
|
|
27
31
|
"jest": "^30.0.3",
|
|
28
|
-
"ts-jest": "^29.4.0"
|
|
32
|
+
"ts-jest": "^29.4.0",
|
|
33
|
+
"typescript": "^5.8.3"
|
|
29
34
|
},
|
|
30
35
|
"dependencies": {
|
|
31
|
-
"socket.io-client": "^4.8.1"
|
|
32
|
-
"typescript": "^5.8.3"
|
|
36
|
+
"socket.io-client": "^4.8.1"
|
|
33
37
|
}
|
|
34
38
|
}
|
package/src/index.ts
CHANGED
|
@@ -1,13 +1,3 @@
|
|
|
1
|
-
import type {
|
|
2
|
-
I_UserEntry,
|
|
3
|
-
I_UserLogin,
|
|
4
|
-
I_UserCreation,
|
|
5
|
-
I_UserUpdate,
|
|
6
|
-
I_UserDisplay,
|
|
7
|
-
I_DocumentEntry,
|
|
8
|
-
I_DataStructure,
|
|
9
|
-
I_LoginResponse, I_DocumentQuery, I_StructureCreation, I_WsMessage, I_EventString, I_DocumentType
|
|
10
|
-
} from "./types.js";
|
|
11
1
|
import {io, Socket} from "socket.io-client";
|
|
12
2
|
import packetJson from '../package.json'
|
|
13
3
|
|
|
@@ -393,5 +383,151 @@ export default class docPouchClient {
|
|
|
393
383
|
|
|
394
384
|
return await response.json() as T;
|
|
395
385
|
}
|
|
396
|
-
|
|
386
|
+
}
|
|
387
|
+
|
|
388
|
+
// Common type definitions for both frontend and backend
|
|
389
|
+
|
|
390
|
+
// User related types
|
|
391
|
+
export interface I_UserEntry extends I_UserCreation {
|
|
392
|
+
_id: string;
|
|
393
|
+
}
|
|
394
|
+
|
|
395
|
+
export interface I_UserLogin {
|
|
396
|
+
name: string;
|
|
397
|
+
password: string;
|
|
398
|
+
}
|
|
399
|
+
|
|
400
|
+
export interface I_UserCreation {
|
|
401
|
+
name: string;
|
|
402
|
+
password: string;
|
|
403
|
+
email?: string;
|
|
404
|
+
department: string;
|
|
405
|
+
group: string;
|
|
406
|
+
isAdmin: boolean;
|
|
407
|
+
}
|
|
408
|
+
|
|
409
|
+
export interface I_UserUpdate {
|
|
410
|
+
_id: string;
|
|
411
|
+
name?: string;
|
|
412
|
+
password?: string;
|
|
413
|
+
email?: string;
|
|
414
|
+
department?: string;
|
|
415
|
+
group?: string;
|
|
416
|
+
isAdmin?: boolean;
|
|
417
|
+
}
|
|
418
|
+
|
|
419
|
+
export interface I_UserDisplay {
|
|
420
|
+
_id: string;
|
|
421
|
+
username: string;
|
|
422
|
+
department: string;
|
|
423
|
+
group: string;
|
|
424
|
+
email?: string;
|
|
425
|
+
}
|
|
426
|
+
|
|
427
|
+
export interface I_LoginResponse {
|
|
428
|
+
token: string;
|
|
429
|
+
isAdmin: boolean;
|
|
430
|
+
userName: string;
|
|
431
|
+
}
|
|
432
|
+
|
|
433
|
+
// Document related types
|
|
434
|
+
export interface I_DocumentEntry extends I_DocumentCreationOwned {
|
|
435
|
+
_id: string;
|
|
436
|
+
}
|
|
437
|
+
|
|
438
|
+
export interface I_DocumentCreation {
|
|
439
|
+
title: string;
|
|
440
|
+
description?: string;
|
|
441
|
+
type: number;
|
|
442
|
+
subType: number;
|
|
443
|
+
content: any;
|
|
444
|
+
shareWithGroup: boolean;
|
|
445
|
+
shareWithDepartment: boolean;
|
|
446
|
+
}
|
|
447
|
+
|
|
448
|
+
|
|
449
|
+
export interface I_DocumentCreationOwned extends I_DocumentCreation {
|
|
450
|
+
owner: string;
|
|
451
|
+
}
|
|
452
|
+
|
|
453
|
+
export interface I_DocumentUpdate extends I_DocumentQuery {
|
|
454
|
+
_id: string;
|
|
455
|
+
content?: any;
|
|
456
|
+
description?: string;
|
|
457
|
+
}
|
|
458
|
+
|
|
459
|
+
export interface I_DocumentQuery {
|
|
460
|
+
_id?: string;
|
|
461
|
+
owner?: string;
|
|
462
|
+
title?: string;
|
|
463
|
+
type?: number;
|
|
464
|
+
subType?: number;
|
|
465
|
+
shareWithGroup?: boolean;
|
|
466
|
+
shareWithDepartment?: boolean;
|
|
467
|
+
}
|
|
468
|
+
|
|
469
|
+
|
|
470
|
+
// Structure related types
|
|
471
|
+
export interface I_DataStructure {
|
|
472
|
+
_id?: string | undefined;
|
|
473
|
+
name: string;
|
|
474
|
+
description: string;
|
|
475
|
+
fields: I_StructureField[];
|
|
476
|
+
}
|
|
477
|
+
|
|
478
|
+
export interface I_StructureField {
|
|
479
|
+
name: string;
|
|
480
|
+
type: string;
|
|
481
|
+
items?: string;
|
|
482
|
+
}
|
|
483
|
+
|
|
484
|
+
export interface I_StructureEntry {
|
|
485
|
+
_id?: string;
|
|
486
|
+
name: string;
|
|
487
|
+
description: string;
|
|
488
|
+
fields: I_StructureField[];
|
|
489
|
+
}
|
|
490
|
+
|
|
491
|
+
|
|
492
|
+
export interface I_StructureCreation {
|
|
493
|
+
name: string;
|
|
494
|
+
description?: string;
|
|
495
|
+
fields: I_StructureField[];
|
|
496
|
+
}
|
|
497
|
+
|
|
498
|
+
export interface I_StructureUpdate {
|
|
499
|
+
_id?: string;
|
|
500
|
+
name?: string;
|
|
501
|
+
description?: string;
|
|
502
|
+
fields?: I_StructureField[];
|
|
503
|
+
}
|
|
504
|
+
|
|
505
|
+
// Document type related types
|
|
506
|
+
export interface I_DocumentType {
|
|
507
|
+
_id?: string;
|
|
508
|
+
type: number;
|
|
509
|
+
subType: number;
|
|
510
|
+
name: string;
|
|
511
|
+
description?: string;
|
|
512
|
+
defaultStructureID?: string;
|
|
513
|
+
}
|
|
514
|
+
|
|
515
|
+
// WebSocket-related types
|
|
516
|
+
export type I_EventString = 'heartbeatPong' | "heartbeatPing" | "newDocument" | "newStructure" |
|
|
517
|
+
"newUser" | "newType" | "removedID" | "changedDocument" | "changedStructure" | "changedUser" | "changedType" |
|
|
518
|
+
"removedUser" | "removedStructure" | "removedDocument" | "removedType";
|
|
519
|
+
|
|
520
|
+
export interface I_WsMessage {
|
|
521
|
+
newDocument?: I_DocumentEntry;
|
|
522
|
+
newStructure?: I_StructureEntry;
|
|
523
|
+
newUser?: I_UserEntry;
|
|
524
|
+
removedID?: string;
|
|
525
|
+
changedDocument?: I_DocumentUpdate;
|
|
526
|
+
changedStructure?: I_StructureUpdate;
|
|
527
|
+
changedUser?: I_UserUpdate;
|
|
528
|
+
confirmSubscription?: boolean;
|
|
529
|
+
confirmUnsubscription?: boolean;
|
|
530
|
+
heartbeatPing?: number;
|
|
531
|
+
heartbeatPong?: number;
|
|
532
|
+
newType?: I_DocumentType;
|
|
397
533
|
}
|
package/tsconfig.json
CHANGED
package/dist/index.d.ts
DELETED
|
@@ -1,93 +0,0 @@
|
|
|
1
|
-
import type { I_UserEntry, I_UserLogin, I_UserCreation, I_UserUpdate, I_UserDisplay, I_DocumentEntry, I_DataStructure, I_LoginResponse, I_DocumentQuery, I_StructureCreation, I_WsMessage, I_EventString, I_DocumentType } from "./types.js";
|
|
2
|
-
import { Socket } from "socket.io-client";
|
|
3
|
-
/**
|
|
4
|
-
* Client for interacting with docPouch API.
|
|
5
|
-
*/
|
|
6
|
-
export default class docPouchClient {
|
|
7
|
-
/**
|
|
8
|
-
* The base URL of the server.
|
|
9
|
-
*
|
|
10
|
-
* @type {string}
|
|
11
|
-
*/
|
|
12
|
-
baseUrl: string;
|
|
13
|
-
/**
|
|
14
|
-
* Socket.IO socket instance for real-time communication with the server.
|
|
15
|
-
*
|
|
16
|
-
* @type {Socket}
|
|
17
|
-
*/
|
|
18
|
-
socket: Socket;
|
|
19
|
-
/**
|
|
20
|
-
* Callback function to handle socket events.
|
|
21
|
-
*
|
|
22
|
-
* @type {(event: I_EventString, data: I_WsMessage) => void}
|
|
23
|
-
*/
|
|
24
|
-
callbackFunction: ((event: I_EventString, data: I_WsMessage) => void) | undefined;
|
|
25
|
-
/**
|
|
26
|
-
* Flag indicating whether real-time synchronization is enabled.
|
|
27
|
-
*
|
|
28
|
-
* @type {boolean}
|
|
29
|
-
*/
|
|
30
|
-
realTimeSync: boolean;
|
|
31
|
-
/**
|
|
32
|
-
* Authentication token used to authorize requests.
|
|
33
|
-
*
|
|
34
|
-
* @private
|
|
35
|
-
* @type {string | null}
|
|
36
|
-
*/
|
|
37
|
-
private authToken;
|
|
38
|
-
/**
|
|
39
|
-
* Flag indicating whether a connection attempt is in progress.
|
|
40
|
-
*
|
|
41
|
-
* @private
|
|
42
|
-
* @type {boolean}
|
|
43
|
-
*/
|
|
44
|
-
private connectionInProgress;
|
|
45
|
-
/**
|
|
46
|
-
* Creates an instance of docPouchClient.
|
|
47
|
-
*
|
|
48
|
-
* @param {string} host - The base URL for the server.
|
|
49
|
-
* @param {number} [port=80] - The port number to connect to (default is 80).
|
|
50
|
-
* @param {(event: I_EventString, data: I_WsMessage) => void} [callback] - Optional callback function for socket events.
|
|
51
|
-
*/
|
|
52
|
-
constructor(host: string, port?: number, callback?: (event: I_EventString, data: I_WsMessage) => void);
|
|
53
|
-
/**
|
|
54
|
-
* Sets the real-time synchronization status.
|
|
55
|
-
*
|
|
56
|
-
* @param {boolean} newRealTimeSync - The new real-time sync setting (true/false).
|
|
57
|
-
*/
|
|
58
|
-
setRealTimeSync(newRealTimeSync: boolean): void;
|
|
59
|
-
login(credentials: I_UserLogin): Promise<I_LoginResponse | null>;
|
|
60
|
-
listUsers(): Promise<I_UserEntry[]>;
|
|
61
|
-
updateUser(userID: string, userData: I_UserUpdate): Promise<void>;
|
|
62
|
-
createUser(userData: I_UserCreation): Promise<I_UserDisplay>;
|
|
63
|
-
removeUser(userID: string): Promise<void>;
|
|
64
|
-
createDocument(document: I_DocumentEntry): Promise<I_DocumentEntry>;
|
|
65
|
-
listDocuments(): Promise<I_DocumentEntry[]>;
|
|
66
|
-
fetchDocument(queryObject: I_DocumentQuery): Promise<I_DocumentEntry[]>;
|
|
67
|
-
updateDocument(documentID: string, documentData: I_DocumentEntry): Promise<void>;
|
|
68
|
-
removeDocument(documentID: string): Promise<void>;
|
|
69
|
-
createStructure(structure: I_StructureCreation): Promise<I_DataStructure>;
|
|
70
|
-
getStructures(): Promise<I_DataStructure[]>;
|
|
71
|
-
updateStructure(structureID: string, structureData: I_DataStructure): Promise<void>;
|
|
72
|
-
removeStructure(structureID: string): Promise<void>;
|
|
73
|
-
createType(type: I_DocumentType): Promise<I_DocumentType>;
|
|
74
|
-
removeType(typeID: string): Promise<void>;
|
|
75
|
-
getTypes(): Promise<I_DocumentType[]>;
|
|
76
|
-
updateType(updatedType: I_DocumentType): Promise<void>;
|
|
77
|
-
setToken(token: string | null): void;
|
|
78
|
-
getVersion(): string;
|
|
79
|
-
debugSocketConnection(): void;
|
|
80
|
-
/**
|
|
81
|
-
* Sets up permanent socket listeners for the client.
|
|
82
|
-
*
|
|
83
|
-
* @private
|
|
84
|
-
*/
|
|
85
|
-
private setupPermanentSocketListeners;
|
|
86
|
-
/**
|
|
87
|
-
* Initializes the WebSocket connection with the server.
|
|
88
|
-
*
|
|
89
|
-
* @private
|
|
90
|
-
*/
|
|
91
|
-
private initWebSocket;
|
|
92
|
-
private request;
|
|
93
|
-
}
|
package/dist/index.js
DELETED
|
@@ -1,308 +0,0 @@
|
|
|
1
|
-
import { io } from "socket.io-client";
|
|
2
|
-
import packetJson from '../package.json';
|
|
3
|
-
/**
|
|
4
|
-
* Client for interacting with docPouch API.
|
|
5
|
-
*/
|
|
6
|
-
export default class docPouchClient {
|
|
7
|
-
/**
|
|
8
|
-
* Creates an instance of docPouchClient.
|
|
9
|
-
*
|
|
10
|
-
* @param {string} host - The base URL for the server.
|
|
11
|
-
* @param {number} [port=80] - The port number to connect to (default is 80).
|
|
12
|
-
* @param {(event: I_EventString, data: I_WsMessage) => void} [callback] - Optional callback function for socket events.
|
|
13
|
-
*/
|
|
14
|
-
constructor(host, port = 80, callback) {
|
|
15
|
-
/**
|
|
16
|
-
* Flag indicating whether real-time synchronization is enabled.
|
|
17
|
-
*
|
|
18
|
-
* @type {boolean}
|
|
19
|
-
*/
|
|
20
|
-
this.realTimeSync = false;
|
|
21
|
-
/**
|
|
22
|
-
* Authentication token used to authorize requests.
|
|
23
|
-
*
|
|
24
|
-
* @private
|
|
25
|
-
* @type {string | null}
|
|
26
|
-
*/
|
|
27
|
-
this.authToken = null;
|
|
28
|
-
/**
|
|
29
|
-
* Flag indicating whether a connection attempt is in progress.
|
|
30
|
-
*
|
|
31
|
-
* @private
|
|
32
|
-
* @type {boolean}
|
|
33
|
-
*/
|
|
34
|
-
this.connectionInProgress = false;
|
|
35
|
-
this.baseUrl = host;
|
|
36
|
-
const socketUrl = host.includes('://') ? host : `https://${host}`;
|
|
37
|
-
const socketUrlWithPort = socketUrl.includes(':') && !socketUrl.endsWith(':')
|
|
38
|
-
? socketUrl
|
|
39
|
-
: `${socketUrl}:${port}`;
|
|
40
|
-
console.log(`Initializing Socket.IO with URL: ${socketUrlWithPort}, path: /socket.io`);
|
|
41
|
-
this.socket = io(`${socketUrlWithPort}`, {
|
|
42
|
-
autoConnect: false,
|
|
43
|
-
transports: ['websocket'], // Try websocket only first
|
|
44
|
-
reconnection: true,
|
|
45
|
-
reconnectionAttempts: 5,
|
|
46
|
-
reconnectionDelay: 1000,
|
|
47
|
-
forceNew: true, // Force a new connection
|
|
48
|
-
auth: {
|
|
49
|
-
token: null // Will be set later
|
|
50
|
-
},
|
|
51
|
-
path: '/socket.io'
|
|
52
|
-
});
|
|
53
|
-
this.callbackFunction = callback;
|
|
54
|
-
this.setupPermanentSocketListeners();
|
|
55
|
-
}
|
|
56
|
-
/**
|
|
57
|
-
* Sets the real-time synchronization status.
|
|
58
|
-
*
|
|
59
|
-
* @param {boolean} newRealTimeSync - The new real-time sync setting (true/false).
|
|
60
|
-
*/
|
|
61
|
-
setRealTimeSync(newRealTimeSync) {
|
|
62
|
-
console.log(`Setting realtime sync to: ${newRealTimeSync}. Current setting: ${this.realTimeSync}`);
|
|
63
|
-
// Skip if the setting isn't changing
|
|
64
|
-
if (newRealTimeSync === this.realTimeSync) {
|
|
65
|
-
console.log("Realtime sync setting unchanged, skipping");
|
|
66
|
-
return;
|
|
67
|
-
}
|
|
68
|
-
this.realTimeSync = newRealTimeSync;
|
|
69
|
-
if (newRealTimeSync && this.authToken) {
|
|
70
|
-
console.log("Activating realtime updates");
|
|
71
|
-
// Ensure we're not in the middle of another connection attempt
|
|
72
|
-
if (this.connectionInProgress) {
|
|
73
|
-
console.log("Connection already in progress, waiting before initializing");
|
|
74
|
-
setTimeout(() => this.initWebSocket(), 500);
|
|
75
|
-
}
|
|
76
|
-
else {
|
|
77
|
-
this.initWebSocket();
|
|
78
|
-
}
|
|
79
|
-
}
|
|
80
|
-
else if (!newRealTimeSync) {
|
|
81
|
-
console.log("Deactivating realtime updates");
|
|
82
|
-
if (this.socket.connected) {
|
|
83
|
-
console.log("Disconnecting socket");
|
|
84
|
-
this.socket.disconnect();
|
|
85
|
-
}
|
|
86
|
-
}
|
|
87
|
-
}
|
|
88
|
-
// User Administration Endpoints
|
|
89
|
-
async login(credentials) {
|
|
90
|
-
const response = await this.request('/users/login', 'POST', credentials, false);
|
|
91
|
-
if (response.token) {
|
|
92
|
-
this.authToken = response.token;
|
|
93
|
-
// Reconnect websocket with new token if realtime sync is enabled
|
|
94
|
-
if (this.realTimeSync) {
|
|
95
|
-
this.initWebSocket();
|
|
96
|
-
}
|
|
97
|
-
return { token: response.token, isAdmin: response.isAdmin, userName: response.userName };
|
|
98
|
-
}
|
|
99
|
-
return null;
|
|
100
|
-
}
|
|
101
|
-
async listUsers() {
|
|
102
|
-
return await this.request('/users/list', 'GET');
|
|
103
|
-
}
|
|
104
|
-
async updateUser(userID, userData) {
|
|
105
|
-
await this.request(`/users/update/${userID}`, 'PATCH', userData);
|
|
106
|
-
}
|
|
107
|
-
async createUser(userData) {
|
|
108
|
-
return await this.request('/users/create', 'POST', userData);
|
|
109
|
-
}
|
|
110
|
-
async removeUser(userID) {
|
|
111
|
-
await this.request(`/users/remove/${userID}`, 'DELETE');
|
|
112
|
-
}
|
|
113
|
-
// Document Management Endpoints
|
|
114
|
-
async createDocument(document) {
|
|
115
|
-
return await this.request('/docs/create', 'POST', document);
|
|
116
|
-
}
|
|
117
|
-
async listDocuments() {
|
|
118
|
-
return await this.request('/docs/list', 'GET');
|
|
119
|
-
}
|
|
120
|
-
async fetchDocument(queryObject) {
|
|
121
|
-
return await this.request(`/docs/fetch/`, 'POST', queryObject);
|
|
122
|
-
}
|
|
123
|
-
async updateDocument(documentID, documentData) {
|
|
124
|
-
await this.request(`/docs/update/${documentID}`, 'PATCH', documentData);
|
|
125
|
-
}
|
|
126
|
-
async removeDocument(documentID) {
|
|
127
|
-
await this.request(`/docs/remove/${documentID}`, 'DELETE');
|
|
128
|
-
}
|
|
129
|
-
// Data Structure Endpoints
|
|
130
|
-
async createStructure(structure) {
|
|
131
|
-
return await this.request('/structures/create', 'POST', structure);
|
|
132
|
-
}
|
|
133
|
-
async getStructures() {
|
|
134
|
-
return await this.request('/structures/list', 'GET');
|
|
135
|
-
}
|
|
136
|
-
async updateStructure(structureID, structureData) {
|
|
137
|
-
await this.request(`/structures/update/${structureID}`, 'PATCH', structureData);
|
|
138
|
-
}
|
|
139
|
-
async removeStructure(structureID) {
|
|
140
|
-
await this.request(`/structures/remove/${structureID}`, 'DELETE');
|
|
141
|
-
}
|
|
142
|
-
// Data Type Endpoints
|
|
143
|
-
async createType(type) {
|
|
144
|
-
return await this.request('/types/write', 'PATCH', type);
|
|
145
|
-
}
|
|
146
|
-
async removeType(typeID) {
|
|
147
|
-
return await this.request(`/types/remove/${typeID}`, 'DELETE');
|
|
148
|
-
}
|
|
149
|
-
async getTypes() {
|
|
150
|
-
return await this.request('/types/list', 'GET');
|
|
151
|
-
}
|
|
152
|
-
async updateType(updatedType) {
|
|
153
|
-
await this.request(`/types/write`, 'PATCH', updatedType);
|
|
154
|
-
}
|
|
155
|
-
setToken(token) {
|
|
156
|
-
console.log("Setting token to:", token ? "***token***" : "null");
|
|
157
|
-
const tokenChanged = this.authToken !== token;
|
|
158
|
-
this.authToken = token;
|
|
159
|
-
if (!tokenChanged) {
|
|
160
|
-
console.log("Token unchanged, no need to reconnect");
|
|
161
|
-
return;
|
|
162
|
-
}
|
|
163
|
-
// If we have a new token and realtime sync is enabled
|
|
164
|
-
if (token && this.realTimeSync) {
|
|
165
|
-
console.log("New token set, will initialize WebSocket");
|
|
166
|
-
// Ensure any existing connection is closed first
|
|
167
|
-
if (this.socket.connected) {
|
|
168
|
-
console.log("Disconnecting existing socket before reconnecting with new token");
|
|
169
|
-
this.socket.disconnect();
|
|
170
|
-
}
|
|
171
|
-
// Wait a moment for the disconnect to complete
|
|
172
|
-
setTimeout(() => {
|
|
173
|
-
console.log("Initializing WebSocket with new token");
|
|
174
|
-
this.initWebSocket();
|
|
175
|
-
}, 300);
|
|
176
|
-
}
|
|
177
|
-
// If token was cleared or realtime sync is disabled
|
|
178
|
-
else if (this.socket.connected) {
|
|
179
|
-
console.log("Token cleared or realtime sync disabled, disconnecting");
|
|
180
|
-
this.socket.disconnect();
|
|
181
|
-
}
|
|
182
|
-
}
|
|
183
|
-
getVersion() {
|
|
184
|
-
return packetJson.version;
|
|
185
|
-
}
|
|
186
|
-
debugSocketConnection() {
|
|
187
|
-
console.log("Socket connection debug info:");
|
|
188
|
-
console.log("- Connected:", this.socket.connected);
|
|
189
|
-
console.log("- Socket ID:", this.socket.id);
|
|
190
|
-
console.log("- Auth token present:", !!this.authToken);
|
|
191
|
-
console.log("- Connection in progress:", this.connectionInProgress);
|
|
192
|
-
console.log("- Realtime sync enabled:", this.realTimeSync);
|
|
193
|
-
console.log("- Socket options:", this.socket.io.opts);
|
|
194
|
-
// Try to force reconnection
|
|
195
|
-
if (!this.socket.connected && this.authToken && this.realTimeSync) {
|
|
196
|
-
console.log("Attempting to force reconnection...");
|
|
197
|
-
this.socket.auth = { token: this.authToken };
|
|
198
|
-
this.socket.connect();
|
|
199
|
-
}
|
|
200
|
-
}
|
|
201
|
-
/**
|
|
202
|
-
* Sets up permanent socket listeners for the client.
|
|
203
|
-
*
|
|
204
|
-
* @private
|
|
205
|
-
*/
|
|
206
|
-
setupPermanentSocketListeners() {
|
|
207
|
-
// These are permanent listeners that won't be removed
|
|
208
|
-
this.socket.on('connect_error', (error) => {
|
|
209
|
-
console.error('Socket connection error:', error.message);
|
|
210
|
-
this.connectionInProgress = false;
|
|
211
|
-
});
|
|
212
|
-
this.socket.on('connect', () => {
|
|
213
|
-
console.log('Socket connected successfully with ID:', this.socket.id);
|
|
214
|
-
this.connectionInProgress = false;
|
|
215
|
-
});
|
|
216
|
-
this.socket.on('disconnect', (reason) => {
|
|
217
|
-
console.log('Socket disconnected. Reason:', reason);
|
|
218
|
-
this.connectionInProgress = false;
|
|
219
|
-
});
|
|
220
|
-
this.socket.on('error', (error) => {
|
|
221
|
-
console.error('Socket error:', error);
|
|
222
|
-
this.connectionInProgress = false;
|
|
223
|
-
});
|
|
224
|
-
}
|
|
225
|
-
/**
|
|
226
|
-
* Initializes the WebSocket connection with the server.
|
|
227
|
-
*
|
|
228
|
-
* @private
|
|
229
|
-
*/
|
|
230
|
-
initWebSocket() {
|
|
231
|
-
console.log("initWebSocket called. Auth token present:", !!this.authToken, "Connection in progress:", this.connectionInProgress, "Socket connected:", this.socket.connected);
|
|
232
|
-
if (!this.authToken) {
|
|
233
|
-
console.log("Skipping WebSocket initialization: No auth token");
|
|
234
|
-
return;
|
|
235
|
-
}
|
|
236
|
-
if (this.connectionInProgress) {
|
|
237
|
-
console.log("Connection already in progress, skipping initialization");
|
|
238
|
-
return;
|
|
239
|
-
}
|
|
240
|
-
if (this.socket.connected) {
|
|
241
|
-
console.log("Socket already connected with ID:", this.socket.id);
|
|
242
|
-
return;
|
|
243
|
-
}
|
|
244
|
-
this.connectionInProgress = true;
|
|
245
|
-
try {
|
|
246
|
-
console.log("Setting up WebSocket connection with token");
|
|
247
|
-
// Update the auth token
|
|
248
|
-
this.socket.auth = { token: this.authToken };
|
|
249
|
-
// Remove any dynamic event listeners that might have been added
|
|
250
|
-
this.socket.offAny();
|
|
251
|
-
// Set up event handler for application events
|
|
252
|
-
this.socket.onAny((event, data) => {
|
|
253
|
-
if (event === "heartbeatPing") {
|
|
254
|
-
console.log("Ping event received:", data);
|
|
255
|
-
this.socket.emit("heartbeatPong", Date.now());
|
|
256
|
-
}
|
|
257
|
-
else if (this.callbackFunction) {
|
|
258
|
-
this.callbackFunction(event, data);
|
|
259
|
-
}
|
|
260
|
-
});
|
|
261
|
-
// Connect to the server
|
|
262
|
-
console.log("Connecting socket with auth token");
|
|
263
|
-
this.socket.connect();
|
|
264
|
-
// Add a timeout to detect if connection is taking too long
|
|
265
|
-
setTimeout(() => {
|
|
266
|
-
if (this.connectionInProgress) {
|
|
267
|
-
console.warn("Socket connection attempt timed out after 5 seconds");
|
|
268
|
-
this.connectionInProgress = false;
|
|
269
|
-
// If we're still not connected after the timeout, try again with polling
|
|
270
|
-
if (!this.socket.connected) {
|
|
271
|
-
console.log("Retrying connection with polling transport");
|
|
272
|
-
this.socket.io.opts.transports = ['polling', 'websocket'];
|
|
273
|
-
this.socket.connect();
|
|
274
|
-
}
|
|
275
|
-
}
|
|
276
|
-
}, 5000);
|
|
277
|
-
}
|
|
278
|
-
catch (error) {
|
|
279
|
-
console.error('Error in initWebSocket:', error);
|
|
280
|
-
this.connectionInProgress = false;
|
|
281
|
-
}
|
|
282
|
-
}
|
|
283
|
-
async request(endpoint, method, body, requiresAuth = true) {
|
|
284
|
-
const headers = {
|
|
285
|
-
'Content-Type': 'application/json',
|
|
286
|
-
};
|
|
287
|
-
if (requiresAuth && this.authToken)
|
|
288
|
-
headers['Authorization'] = `Bearer ${this.authToken}`;
|
|
289
|
-
if (this.socket.id)
|
|
290
|
-
headers['X-Socket-ID'] = this.socket.id;
|
|
291
|
-
const options = {
|
|
292
|
-
method,
|
|
293
|
-
headers,
|
|
294
|
-
body: body ? JSON.stringify(body) : undefined
|
|
295
|
-
};
|
|
296
|
-
const normalizedEndpoint = endpoint.startsWith('/') ? endpoint : `/${endpoint}`;
|
|
297
|
-
const normalizedBaseUrl = this.baseUrl.endsWith('/') ? this.baseUrl.slice(0, -1) : this.baseUrl;
|
|
298
|
-
const url = `${normalizedBaseUrl}${normalizedEndpoint}`;
|
|
299
|
-
const response = await fetch(url, options);
|
|
300
|
-
if (!response.ok) {
|
|
301
|
-
if (response.status === 401 || response.status === 403) {
|
|
302
|
-
this.authToken = null;
|
|
303
|
-
}
|
|
304
|
-
throw new Error(`API error: ${response.status} ${response.statusText}`);
|
|
305
|
-
}
|
|
306
|
-
return await response.json();
|
|
307
|
-
}
|
|
308
|
-
}
|
package/dist/types.d.ts
DELETED
|
@@ -1,116 +0,0 @@
|
|
|
1
|
-
export interface I_UserEntry extends I_UserCreation {
|
|
2
|
-
_id: string;
|
|
3
|
-
}
|
|
4
|
-
export interface I_UserLogin {
|
|
5
|
-
name: string;
|
|
6
|
-
password: string;
|
|
7
|
-
}
|
|
8
|
-
export interface I_UserCreation {
|
|
9
|
-
name: string;
|
|
10
|
-
password: string;
|
|
11
|
-
email?: string;
|
|
12
|
-
department: string;
|
|
13
|
-
group: string;
|
|
14
|
-
isAdmin: boolean;
|
|
15
|
-
}
|
|
16
|
-
export interface I_UserUpdate {
|
|
17
|
-
_id: string;
|
|
18
|
-
name?: string;
|
|
19
|
-
password?: string;
|
|
20
|
-
email?: string;
|
|
21
|
-
department?: string;
|
|
22
|
-
group?: string;
|
|
23
|
-
isAdmin?: boolean;
|
|
24
|
-
}
|
|
25
|
-
export interface I_UserDisplay {
|
|
26
|
-
_id: string;
|
|
27
|
-
username: string;
|
|
28
|
-
department: string;
|
|
29
|
-
group: string;
|
|
30
|
-
email?: string;
|
|
31
|
-
}
|
|
32
|
-
export interface I_LoginResponse {
|
|
33
|
-
token: string;
|
|
34
|
-
isAdmin: boolean;
|
|
35
|
-
userName: string;
|
|
36
|
-
}
|
|
37
|
-
export interface I_DocumentEntry extends I_DocumentCreationOwned {
|
|
38
|
-
_id: string;
|
|
39
|
-
}
|
|
40
|
-
export interface I_DocumentCreation {
|
|
41
|
-
title: string;
|
|
42
|
-
description?: string;
|
|
43
|
-
type: number;
|
|
44
|
-
subType: number;
|
|
45
|
-
content: any;
|
|
46
|
-
shareWithGroup: boolean;
|
|
47
|
-
shareWithDepartment: boolean;
|
|
48
|
-
}
|
|
49
|
-
export interface I_DocumentCreationOwned extends I_DocumentCreation {
|
|
50
|
-
owner: string;
|
|
51
|
-
}
|
|
52
|
-
export interface I_DocumentUpdate extends I_DocumentQuery {
|
|
53
|
-
_id: string;
|
|
54
|
-
content?: any;
|
|
55
|
-
description?: string;
|
|
56
|
-
}
|
|
57
|
-
export interface I_DocumentQuery {
|
|
58
|
-
_id?: string;
|
|
59
|
-
owner?: string;
|
|
60
|
-
title?: string;
|
|
61
|
-
type?: number;
|
|
62
|
-
subType?: number;
|
|
63
|
-
shareWithGroup?: boolean;
|
|
64
|
-
shareWithDepartment?: boolean;
|
|
65
|
-
}
|
|
66
|
-
export interface I_DataStructure {
|
|
67
|
-
_id?: string | undefined;
|
|
68
|
-
name: string;
|
|
69
|
-
description: string;
|
|
70
|
-
fields: I_StructureField[];
|
|
71
|
-
}
|
|
72
|
-
export interface I_StructureField {
|
|
73
|
-
name: string;
|
|
74
|
-
type: string;
|
|
75
|
-
items?: string;
|
|
76
|
-
}
|
|
77
|
-
export interface I_StructureEntry {
|
|
78
|
-
_id?: string;
|
|
79
|
-
name: string;
|
|
80
|
-
description: string;
|
|
81
|
-
fields: I_StructureField[];
|
|
82
|
-
}
|
|
83
|
-
export interface I_StructureCreation {
|
|
84
|
-
name: string;
|
|
85
|
-
description?: string;
|
|
86
|
-
fields: I_StructureField[];
|
|
87
|
-
}
|
|
88
|
-
export interface I_StructureUpdate {
|
|
89
|
-
_id: string;
|
|
90
|
-
name?: string;
|
|
91
|
-
description?: string;
|
|
92
|
-
fields?: I_StructureField[];
|
|
93
|
-
}
|
|
94
|
-
export interface I_DocumentType {
|
|
95
|
-
_id?: string;
|
|
96
|
-
type: number;
|
|
97
|
-
subType: number;
|
|
98
|
-
name: string;
|
|
99
|
-
description?: string;
|
|
100
|
-
defaultStructureID?: string;
|
|
101
|
-
}
|
|
102
|
-
export type I_EventString = 'heartbeatPong' | "heartbeatPing" | "newDocument" | "newStructure" | "newUser" | "newType" | "removedID" | "changedDocument" | "changedStructure" | "changedUser" | "changedType" | "removedUser" | "removedStructure" | "removedDocument" | "removedType";
|
|
103
|
-
export interface I_WsMessage {
|
|
104
|
-
newDocument?: I_DocumentEntry;
|
|
105
|
-
newStructure?: I_StructureEntry;
|
|
106
|
-
newUser?: I_UserEntry;
|
|
107
|
-
removedID?: string;
|
|
108
|
-
changedDocument?: I_DocumentUpdate;
|
|
109
|
-
changedStructure?: I_StructureUpdate;
|
|
110
|
-
changedUser?: I_UserUpdate;
|
|
111
|
-
confirmSubscription?: boolean;
|
|
112
|
-
confirmUnsubscription?: boolean;
|
|
113
|
-
heartbeatPing?: number;
|
|
114
|
-
heartbeatPong?: number;
|
|
115
|
-
newType?: I_DocumentType;
|
|
116
|
-
}
|
package/dist/types.js
DELETED
package/src/types.ts
DELETED
|
@@ -1,146 +0,0 @@
|
|
|
1
|
-
// Common type definitions for both frontend and backend
|
|
2
|
-
|
|
3
|
-
// User related types
|
|
4
|
-
export interface I_UserEntry extends I_UserCreation{
|
|
5
|
-
_id: string;
|
|
6
|
-
}
|
|
7
|
-
|
|
8
|
-
export interface I_UserLogin {
|
|
9
|
-
name: string;
|
|
10
|
-
password: string;
|
|
11
|
-
}
|
|
12
|
-
|
|
13
|
-
export interface I_UserCreation {
|
|
14
|
-
name: string;
|
|
15
|
-
password: string;
|
|
16
|
-
email?: string;
|
|
17
|
-
department: string;
|
|
18
|
-
group: string;
|
|
19
|
-
isAdmin: boolean;
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
export interface I_UserUpdate {
|
|
23
|
-
_id: string;
|
|
24
|
-
name?: string;
|
|
25
|
-
password?: string;
|
|
26
|
-
email?: string;
|
|
27
|
-
department?: string;
|
|
28
|
-
group?: string;
|
|
29
|
-
isAdmin?: boolean;
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
export interface I_UserDisplay {
|
|
33
|
-
_id: string;
|
|
34
|
-
username: string;
|
|
35
|
-
department: string;
|
|
36
|
-
group: string;
|
|
37
|
-
email?: string;
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
export interface I_LoginResponse {
|
|
41
|
-
token: string;
|
|
42
|
-
isAdmin: boolean;
|
|
43
|
-
userName: string;
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
// Document related types
|
|
47
|
-
export interface I_DocumentEntry extends I_DocumentCreationOwned{
|
|
48
|
-
_id: string;
|
|
49
|
-
}
|
|
50
|
-
|
|
51
|
-
export interface I_DocumentCreation {
|
|
52
|
-
title: string;
|
|
53
|
-
description?: string;
|
|
54
|
-
type: number;
|
|
55
|
-
subType: number;
|
|
56
|
-
content: any;
|
|
57
|
-
shareWithGroup: boolean;
|
|
58
|
-
shareWithDepartment: boolean;
|
|
59
|
-
}
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
export interface I_DocumentCreationOwned extends I_DocumentCreation {
|
|
63
|
-
owner: string;
|
|
64
|
-
}
|
|
65
|
-
|
|
66
|
-
export interface I_DocumentUpdate extends I_DocumentQuery{
|
|
67
|
-
_id: string;
|
|
68
|
-
content?: any;
|
|
69
|
-
description?: string;
|
|
70
|
-
}
|
|
71
|
-
|
|
72
|
-
export interface I_DocumentQuery {
|
|
73
|
-
_id?: string;
|
|
74
|
-
owner?: string;
|
|
75
|
-
title?: string;
|
|
76
|
-
type?: number;
|
|
77
|
-
subType?: number;
|
|
78
|
-
shareWithGroup?: boolean;
|
|
79
|
-
shareWithDepartment?: boolean;
|
|
80
|
-
}
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
// Structure related types
|
|
84
|
-
export interface I_DataStructure {
|
|
85
|
-
_id?: string | undefined;
|
|
86
|
-
name: string;
|
|
87
|
-
description: string;
|
|
88
|
-
fields: I_StructureField[];
|
|
89
|
-
}
|
|
90
|
-
|
|
91
|
-
export interface I_StructureField {
|
|
92
|
-
name: string;
|
|
93
|
-
type: string;
|
|
94
|
-
items?: string;
|
|
95
|
-
}
|
|
96
|
-
|
|
97
|
-
export interface I_StructureEntry {
|
|
98
|
-
_id?: string;
|
|
99
|
-
name: string;
|
|
100
|
-
description: string;
|
|
101
|
-
fields: I_StructureField[];
|
|
102
|
-
}
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
export interface I_StructureCreation {
|
|
106
|
-
name: string;
|
|
107
|
-
description?: string;
|
|
108
|
-
fields: I_StructureField[];
|
|
109
|
-
}
|
|
110
|
-
|
|
111
|
-
export interface I_StructureUpdate {
|
|
112
|
-
_id: string;
|
|
113
|
-
name?: string;
|
|
114
|
-
description?: string;
|
|
115
|
-
fields?: I_StructureField[];
|
|
116
|
-
}
|
|
117
|
-
|
|
118
|
-
// Document type related types
|
|
119
|
-
export interface I_DocumentType {
|
|
120
|
-
_id?: string;
|
|
121
|
-
type: number;
|
|
122
|
-
subType: number;
|
|
123
|
-
name: string;
|
|
124
|
-
description?: string;
|
|
125
|
-
defaultStructureID?: string;
|
|
126
|
-
}
|
|
127
|
-
|
|
128
|
-
// WebSocket-related types
|
|
129
|
-
export type I_EventString = 'heartbeatPong' | "heartbeatPing" | "newDocument" | "newStructure" |
|
|
130
|
-
"newUser" | "newType" | "removedID" | "changedDocument" | "changedStructure" | "changedUser" | "changedType" |
|
|
131
|
-
"removedUser" | "removedStructure" | "removedDocument" | "removedType";
|
|
132
|
-
|
|
133
|
-
export interface I_WsMessage {
|
|
134
|
-
newDocument?: I_DocumentEntry;
|
|
135
|
-
newStructure?: I_StructureEntry;
|
|
136
|
-
newUser?: I_UserEntry;
|
|
137
|
-
removedID?: string;
|
|
138
|
-
changedDocument?: I_DocumentUpdate;
|
|
139
|
-
changedStructure?: I_StructureUpdate;
|
|
140
|
-
changedUser?: I_UserUpdate;
|
|
141
|
-
confirmSubscription?: boolean;
|
|
142
|
-
confirmUnsubscription?: boolean;
|
|
143
|
-
heartbeatPing?: number;
|
|
144
|
-
heartbeatPong?: number;
|
|
145
|
-
newType?: I_DocumentType;
|
|
146
|
-
}
|