@aicore/cocodb-ws-client 1.0.4 → 1.0.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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@aicore/cocodb-ws-client",
3
- "version": "1.0.4",
3
+ "version": "1.0.6",
4
4
  "description": "Websocket client for cocoDb",
5
5
  "main": "src/index.js",
6
6
  "type": "module",
@@ -59,7 +59,11 @@
59
59
  "mocha": "10.0.0"
60
60
  },
61
61
  "dependencies": {
62
- "ws": "8.9.0",
63
- "@aicore/libcommonutils": "1.0.18"
62
+ "@aicore/libcommonutils": "1.0.18",
63
+ "ws": "8.9.0"
64
+ },
65
+ "optionalDependencies": {
66
+ "bufferutil": "4.0.6",
67
+ "utf-8-validate": "5.0.9"
64
68
  }
65
69
  }
@@ -2,20 +2,26 @@ import {WS} from "./WebSocket.js";
2
2
  import {isString, isObject, isStringEmpty, COCO_DB_FUNCTIONS} from "@aicore/libcommonutils";
3
3
 
4
4
  let client = null;
5
- const WEBSOCKET_ENDPOINT_COCO_DB = '/ws';
5
+ const WEBSOCKET_ENDPOINT_COCO_DB = '/ws/';
6
6
  const ID_TO_RESOLVE_REJECT_MAP = {};
7
7
  let id = 0;
8
8
 
9
9
  // @INCLUDE_IN_API_DOCS
10
10
 
11
+ /**
12
+ * It creates a websocket connection to the cocoDbServiceEndPoint and listens for messages
13
+ * @param {string} cocoDbServiceEndPoint - The URL of the coco-db service.
14
+ * @param {string} authKey - The authKey is a base64 encoded string of the username and password.
15
+ */
11
16
  export function init(cocoDbServiceEndPoint, authKey) {
12
- if (isStringEmpty(cocoDbServiceEndPoint)) {
17
+ if (isStringEmpty(cocoDbServiceEndPoint) || !(cocoDbServiceEndPoint.startsWith('ws://')
18
+ || cocoDbServiceEndPoint.startsWith('wss://'))) {
13
19
  throw new Error('Please provide valid cocoDbServiceEndPoint');
14
20
  }
15
21
  if (isStringEmpty(authKey)) {
16
22
  throw new Error('Please provide valid authKey');
17
23
  }
18
- client = new WS.WebSocket(`ws://${cocoDbServiceEndPoint}${WEBSOCKET_ENDPOINT_COCO_DB}`, {
24
+ client = new WS.WebSocket(cocoDbServiceEndPoint.trim() + WEBSOCKET_ENDPOINT_COCO_DB, {
19
25
  perMessageDeflate: false,
20
26
  headers: {
21
27
  Authorization: `Basic ${authKey}`
@@ -40,6 +46,10 @@ export function init(cocoDbServiceEndPoint, authKey) {
40
46
  });
41
47
  }
42
48
 
49
+ /**
50
+ * It closes the connection to the server
51
+ * @returns The function close() is being returned.
52
+ */
43
53
  export function close() {
44
54
  if (!client) {
45
55
  return;
@@ -47,6 +57,10 @@ export function close() {
47
57
  client.terminate();
48
58
  }
49
59
 
60
+ /**
61
+ * It returns a string representation of the next integer in a sequence
62
+ * @returns {string} A function that increments the id variable and returns the new value as a hexadecimal string.
63
+ */
50
64
  function getId() {
51
65
  id++;
52
66
  return id.toString(16);