docpouch-client 0.8.1 → 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 CHANGED
@@ -1,8 +1,10 @@
1
- import type { I_UserEntry, I_UserLogin, I_UserCreation, I_UserUpdate, I_UserDisplay, I_DocumentEntry, I_DataStructure, I_LoginResponse, I_DocumentQuery } 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
- constructor(baseUrl: string);
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[]>;
@@ -14,7 +16,7 @@ export default class Index {
14
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: I_DataStructure): Promise<I_DataStructure>;
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 = {
package/dist/types.d.ts CHANGED
@@ -39,6 +39,11 @@ 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
+ }
42
47
  export interface I_DocumentQuery {
43
48
  _id?: string;
44
49
  owner?: string;
@@ -66,3 +71,23 @@ export interface I_StructureCreation {
66
71
  reference?: any;
67
72
  fields: any[];
68
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.1",
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": ["docPouch", "API"],
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"
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
@@ -6,15 +6,32 @@ import type {
6
6
  I_UserDisplay,
7
7
  I_DocumentEntry,
8
8
  I_DataStructure,
9
- I_LoginResponse, I_DocumentQuery
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> {
@@ -80,7 +97,7 @@ export default class Index {
80
97
  }
81
98
 
82
99
  async fetchDocument(queryObject: I_DocumentQuery): Promise<I_DocumentEntry[]> {
83
- return await this.request<I_DocumentEntry[]>(`/docs/fetch/`, 'GET');
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: I_DataStructure): Promise<I_DataStructure> {
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 this.token;
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,12 @@ 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
+
55
67
  export interface I_DocumentQuery {
56
68
  _id?: string;
57
69
  owner?: string;
@@ -82,4 +94,31 @@ export interface I_StructureCreation {
82
94
  description?: string;
83
95
  reference?: any;
84
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;
85
124
  }
package/tsconfig.json CHANGED
@@ -12,6 +12,7 @@
12
12
  "rootDir": "./src",
13
13
  "declaration": true,
14
14
  "emitDeclarationOnly": false,
15
+ "resolveJsonModule": true
15
16
  },
16
17
  "include": ["**/*.ts", "**/*.tsx"],
17
18
  "exclude": ["node_modules", "**/*.test.ts", "**/*.types.ts", "./dist/**/*"]