docpouch-client 0.8.0 → 0.8.2
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/dist/index.d.ts +6 -4
- package/dist/index.js +9 -3
- package/dist/types.d.ts +32 -0
- package/package.json +7 -3
- package/src/index.ts +30 -9
- package/src/types.ts +47 -0
- package/tsconfig.json +2 -1
package/dist/index.d.ts
CHANGED
|
@@ -1,8 +1,10 @@
|
|
|
1
|
-
import type { I_UserEntry, I_UserLogin, I_UserCreation, I_UserUpdate, I_UserDisplay, I_DocumentEntry, I_DataStructure, I_LoginResponse } from "./types.js";
|
|
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 } from "./types.js";
|
|
2
|
+
import { Manager } from "socket.io-client";
|
|
2
3
|
export default class Index {
|
|
3
4
|
baseUrl: string;
|
|
4
5
|
private token;
|
|
5
|
-
|
|
6
|
+
socketManager: Manager<import("@socket.io/component-emitter").DefaultEventsMap, import("@socket.io/component-emitter").DefaultEventsMap>;
|
|
7
|
+
constructor(baseUrl: string, callback?: (event: string, data: I_WsMessage) => void);
|
|
6
8
|
private request;
|
|
7
9
|
login(credentials: I_UserLogin): Promise<I_LoginResponse | null>;
|
|
8
10
|
listUsers(): Promise<I_UserEntry[]>;
|
|
@@ -11,10 +13,10 @@ export default class Index {
|
|
|
11
13
|
removeUser(userID: string): Promise<void>;
|
|
12
14
|
createDocument(document: I_DocumentEntry): Promise<I_DocumentEntry>;
|
|
13
15
|
listDocuments(): Promise<I_DocumentEntry[]>;
|
|
14
|
-
fetchDocument(
|
|
16
|
+
fetchDocument(queryObject: I_DocumentQuery): Promise<I_DocumentEntry[]>;
|
|
15
17
|
updateDocument(documentID: string, documentData: I_DocumentEntry): Promise<void>;
|
|
16
18
|
removeDocument(documentID: string): Promise<void>;
|
|
17
|
-
createStructure(structure:
|
|
19
|
+
createStructure(structure: I_StructureCreation): Promise<I_DataStructure>;
|
|
18
20
|
getStructures(): Promise<I_DataStructure[]>;
|
|
19
21
|
updateStructure(structureID: string, structureData: I_DataStructure): Promise<void>;
|
|
20
22
|
removeStructure(structureID: string): Promise<void>;
|
package/dist/index.js
CHANGED
|
@@ -1,9 +1,15 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const socket_io_client_1 = require("socket.io-client");
|
|
3
4
|
class Index {
|
|
4
|
-
constructor(baseUrl) {
|
|
5
|
+
constructor(baseUrl, callback) {
|
|
5
6
|
this.token = null;
|
|
6
7
|
this.baseUrl = baseUrl;
|
|
8
|
+
this.socketManager = new socket_io_client_1.Manager(baseUrl, { autoConnect: false });
|
|
9
|
+
if (callback) {
|
|
10
|
+
this.socketManager.connect();
|
|
11
|
+
this.socketManager.onAny((event, data) => callback(event, data));
|
|
12
|
+
}
|
|
7
13
|
}
|
|
8
14
|
async request(endpoint, method, body, requiresAuth = true) {
|
|
9
15
|
const headers = {
|
|
@@ -54,8 +60,8 @@ class Index {
|
|
|
54
60
|
async listDocuments() {
|
|
55
61
|
return await this.request('/docs/list', 'GET');
|
|
56
62
|
}
|
|
57
|
-
async fetchDocument(
|
|
58
|
-
return await this.request(`/docs/fetch
|
|
63
|
+
async fetchDocument(queryObject) {
|
|
64
|
+
return await this.request(`/docs/fetch/`, 'GET');
|
|
59
65
|
}
|
|
60
66
|
async updateDocument(documentID, documentData) {
|
|
61
67
|
await this.request(`/docs/update/${documentID}`, 'PATCH', documentData);
|
package/dist/types.d.ts
CHANGED
|
@@ -39,6 +39,18 @@ export interface I_DocumentCreation {
|
|
|
39
39
|
export interface I_DocumentCreationOwned extends I_DocumentCreation {
|
|
40
40
|
owner: string;
|
|
41
41
|
}
|
|
42
|
+
export interface I_DocumentUpdate extends I_DocumentQuery {
|
|
43
|
+
_id: string;
|
|
44
|
+
content?: any;
|
|
45
|
+
description?: string;
|
|
46
|
+
}
|
|
47
|
+
export interface I_DocumentQuery {
|
|
48
|
+
_id?: string;
|
|
49
|
+
owner?: string;
|
|
50
|
+
title?: string;
|
|
51
|
+
type?: number;
|
|
52
|
+
subType?: number;
|
|
53
|
+
}
|
|
42
54
|
export interface I_DataStructure {
|
|
43
55
|
_id?: string | undefined;
|
|
44
56
|
name: string;
|
|
@@ -59,3 +71,23 @@ export interface I_StructureCreation {
|
|
|
59
71
|
reference?: any;
|
|
60
72
|
fields: any[];
|
|
61
73
|
}
|
|
74
|
+
export interface I_StructureUpdate {
|
|
75
|
+
_id: string;
|
|
76
|
+
name?: string;
|
|
77
|
+
description?: string;
|
|
78
|
+
reference?: any;
|
|
79
|
+
fields?: any[];
|
|
80
|
+
}
|
|
81
|
+
export interface I_WsMessage {
|
|
82
|
+
newDocument?: I_DocumentEntry;
|
|
83
|
+
newStructure?: I_StructureEntry;
|
|
84
|
+
newUser?: I_UserEntry;
|
|
85
|
+
removedID?: string;
|
|
86
|
+
changedDocument?: I_DocumentUpdate;
|
|
87
|
+
changedStructure?: I_StructureUpdate;
|
|
88
|
+
changedUser?: I_UserUpdate;
|
|
89
|
+
confirmSubscription?: boolean;
|
|
90
|
+
confirmUnsubscription?: boolean;
|
|
91
|
+
ping?: number;
|
|
92
|
+
pong?: number;
|
|
93
|
+
}
|
package/package.json
CHANGED
|
@@ -1,17 +1,21 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "docpouch-client",
|
|
3
|
-
"version": "0.8.
|
|
3
|
+
"version": "0.8.2",
|
|
4
4
|
"main": "dist/index.js",
|
|
5
5
|
"types": "dist/index.d.ts",
|
|
6
6
|
"scripts": {
|
|
7
7
|
"build": "tsc"
|
|
8
8
|
},
|
|
9
|
-
"keywords": [
|
|
9
|
+
"keywords": [
|
|
10
|
+
"docPouch",
|
|
11
|
+
"API"
|
|
12
|
+
],
|
|
10
13
|
"author": "Jan Frecè",
|
|
11
14
|
"license": "MIT",
|
|
12
15
|
"description": "A small class to more easily access the docPouch API",
|
|
13
16
|
"devDependencies": {
|
|
14
|
-
"@types/node": "^22.15.
|
|
17
|
+
"@types/node": "^22.15.23",
|
|
18
|
+
"socket.io-client": "^4.8.1"
|
|
15
19
|
},
|
|
16
20
|
"dependencies": {
|
|
17
21
|
"typescript": "^5.8.3"
|
package/src/index.ts
CHANGED
|
@@ -1,20 +1,37 @@
|
|
|
1
|
-
import type {
|
|
1
|
+
import type {
|
|
2
2
|
I_UserEntry,
|
|
3
3
|
I_UserLogin,
|
|
4
4
|
I_UserCreation,
|
|
5
5
|
I_UserUpdate,
|
|
6
|
-
I_UserDisplay,
|
|
6
|
+
I_UserDisplay,
|
|
7
7
|
I_DocumentEntry,
|
|
8
|
-
I_DataStructure,
|
|
9
|
-
I_LoginResponse
|
|
8
|
+
I_DataStructure,
|
|
9
|
+
I_LoginResponse, I_DocumentQuery, I_StructureCreation, I_WsMessage, I_EventString
|
|
10
10
|
} from "./types.js";
|
|
11
|
+
import {io, Socket} from "socket.io-client";
|
|
12
|
+
import packetJson from '../package.json'
|
|
11
13
|
|
|
12
14
|
export default class Index {
|
|
13
15
|
baseUrl: string;
|
|
14
16
|
private token: string | null = null;
|
|
17
|
+
socket: Socket
|
|
15
18
|
|
|
16
|
-
constructor(baseUrl: string) {
|
|
19
|
+
constructor(baseUrl: string, callback?: (event: I_EventString, data: I_WsMessage) => void) {
|
|
17
20
|
this.baseUrl = baseUrl;
|
|
21
|
+
|
|
22
|
+
this.socket = io(baseUrl, { autoConnect: false });
|
|
23
|
+
if (callback) {
|
|
24
|
+
this.socket.connect();
|
|
25
|
+
this.socket.onAny((event: I_EventString, data: I_WsMessage) => {
|
|
26
|
+
if (event === "heartbeatPing") {
|
|
27
|
+
console.log("Ping event received:", data);
|
|
28
|
+
this.socket.emit("heartbeatPong", Date.now());
|
|
29
|
+
}
|
|
30
|
+
else {
|
|
31
|
+
callback(event, data);
|
|
32
|
+
}
|
|
33
|
+
});
|
|
34
|
+
}
|
|
18
35
|
}
|
|
19
36
|
|
|
20
37
|
private async request<T>(endpoint: string, method: string, body?: any, requiresAuth: boolean = true): Promise<T> {
|
|
@@ -79,8 +96,8 @@ export default class Index {
|
|
|
79
96
|
return await this.request<I_DocumentEntry[]>('/docs/list', 'GET');
|
|
80
97
|
}
|
|
81
98
|
|
|
82
|
-
async fetchDocument(
|
|
83
|
-
return await this.request<I_DocumentEntry>(`/docs/fetch
|
|
99
|
+
async fetchDocument(queryObject: I_DocumentQuery): Promise<I_DocumentEntry[]> {
|
|
100
|
+
return await this.request<I_DocumentEntry[]>(`/docs/fetch/`, 'POST', queryObject);
|
|
84
101
|
}
|
|
85
102
|
|
|
86
103
|
async updateDocument(documentID: string, documentData: I_DocumentEntry): Promise<void> {
|
|
@@ -92,7 +109,7 @@ export default class Index {
|
|
|
92
109
|
}
|
|
93
110
|
|
|
94
111
|
// Data Structure Endpoints
|
|
95
|
-
async createStructure(structure:
|
|
112
|
+
async createStructure(structure: I_StructureCreation): Promise<I_DataStructure> {
|
|
96
113
|
return await this.request<I_DataStructure>('/structures/create', 'POST', structure);
|
|
97
114
|
}
|
|
98
115
|
|
|
@@ -113,7 +130,11 @@ export default class Index {
|
|
|
113
130
|
}
|
|
114
131
|
|
|
115
132
|
getToken() {
|
|
116
|
-
return
|
|
133
|
+
return packetJson.version;
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
getVersion() {
|
|
137
|
+
return "0.0.1";
|
|
117
138
|
}
|
|
118
139
|
}
|
|
119
140
|
|
package/src/types.ts
CHANGED
|
@@ -14,6 +14,8 @@ export interface I_UserCreation {
|
|
|
14
14
|
name: string;
|
|
15
15
|
password: string;
|
|
16
16
|
email?: string;
|
|
17
|
+
department: string;
|
|
18
|
+
group: string;
|
|
17
19
|
isAdmin: boolean;
|
|
18
20
|
}
|
|
19
21
|
|
|
@@ -21,12 +23,16 @@ export interface I_UserUpdate {
|
|
|
21
23
|
name?: string;
|
|
22
24
|
password?: string;
|
|
23
25
|
email?: string;
|
|
26
|
+
department?: string;
|
|
27
|
+
group?: string;
|
|
24
28
|
isAdmin?: boolean;
|
|
25
29
|
}
|
|
26
30
|
|
|
27
31
|
export interface I_UserDisplay {
|
|
28
32
|
_id: string;
|
|
29
33
|
username: string;
|
|
34
|
+
department: string;
|
|
35
|
+
group: string;
|
|
30
36
|
email?: string;
|
|
31
37
|
}
|
|
32
38
|
|
|
@@ -52,6 +58,20 @@ export interface I_DocumentCreationOwned extends I_DocumentCreation {
|
|
|
52
58
|
owner: string;
|
|
53
59
|
}
|
|
54
60
|
|
|
61
|
+
export interface I_DocumentUpdate extends I_DocumentQuery{
|
|
62
|
+
_id: string;
|
|
63
|
+
content?: any;
|
|
64
|
+
description?: string;
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
export interface I_DocumentQuery {
|
|
68
|
+
_id?: string;
|
|
69
|
+
owner?: string;
|
|
70
|
+
title?: string;
|
|
71
|
+
type?: number;
|
|
72
|
+
subType?: number;
|
|
73
|
+
}
|
|
74
|
+
|
|
55
75
|
// Structure related types
|
|
56
76
|
export interface I_DataStructure {
|
|
57
77
|
_id?: string | undefined;
|
|
@@ -74,4 +94,31 @@ export interface I_StructureCreation {
|
|
|
74
94
|
description?: string;
|
|
75
95
|
reference?: any;
|
|
76
96
|
fields: any[];
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
export interface I_StructureUpdate {
|
|
100
|
+
_id: string;
|
|
101
|
+
name?: string;
|
|
102
|
+
description?: string;
|
|
103
|
+
reference?: any;
|
|
104
|
+
fields?: any[];
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
// WebSocket-related types
|
|
108
|
+
export type I_EventString = 'subscribe' | 'unsubscribe' | 'heartbeatPong' | "heartbeatPing" | "newDocument" | "newStructure" |
|
|
109
|
+
"newUser" | "removedID" | "changedDocument" | "changedStructure" | "changedUser" | "confirmSubscription" |
|
|
110
|
+
"confirmUnsubscription";
|
|
111
|
+
|
|
112
|
+
export interface I_WsMessage {
|
|
113
|
+
newDocument?: I_DocumentEntry;
|
|
114
|
+
newStructure?: I_StructureEntry;
|
|
115
|
+
newUser?: I_UserEntry;
|
|
116
|
+
removedID?: string;
|
|
117
|
+
changedDocument?: I_DocumentUpdate;
|
|
118
|
+
changedStructure?: I_StructureUpdate;
|
|
119
|
+
changedUser?: I_UserUpdate;
|
|
120
|
+
confirmSubscription?: boolean;
|
|
121
|
+
confirmUnsubscription?: boolean;
|
|
122
|
+
heartbeatPing?: number;
|
|
123
|
+
heartbeatPong?: number;
|
|
77
124
|
}
|
package/tsconfig.json
CHANGED
|
@@ -12,7 +12,8 @@
|
|
|
12
12
|
"rootDir": "./src",
|
|
13
13
|
"declaration": true,
|
|
14
14
|
"emitDeclarationOnly": false,
|
|
15
|
+
"resolveJsonModule": true
|
|
15
16
|
},
|
|
16
17
|
"include": ["**/*.ts", "**/*.tsx"],
|
|
17
|
-
"exclude": ["node_modules", "**/*.test.ts", "**/*.types.ts"]
|
|
18
|
+
"exclude": ["node_modules", "**/*.test.ts", "**/*.types.ts", "./dist/**/*"]
|
|
18
19
|
}
|