@dnax/core 0.60.3 → 0.60.5

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/app/hono.ts CHANGED
@@ -99,7 +99,9 @@ function HonoInstance(): typeof app {
99
99
  return asyncLocalStorage.run(new Map(), async () => {
100
100
  let cookie = getCookie(c);
101
101
  let session = sessionStorage();
102
- var token = jwt.getToken("Bearer", c.req.header()["authorization"]) || "";
102
+ var token =
103
+ jwt.getToken("Bearer", c.req.header()["authorization"]) || null;
104
+
103
105
  var { decode, valid, error } = jwt.verify(token);
104
106
  let sessionData = {};
105
107
  if (valid && decode && decode?.session) {
@@ -1,5 +1,4 @@
1
1
  import { Cfg } from "../../config";
2
- import { Server } from "socket.io";
3
2
  import consola from "consola";
4
3
  import { Glob } from "bun";
5
4
  import path from "path";
@@ -5,13 +5,16 @@ import { v4 } from "uuid";
5
5
  const wsClients = new Map<string, ServerWebSocket>();
6
6
  const wsEvents: optionsIo[] = [];
7
7
 
8
+ type _clbFunc = (data: any) => void;
9
+
8
10
  /**
9
11
  * reason for disconnection
10
12
  */
11
13
  type reasonType = any;
12
14
  export type callbackType = (
13
15
  socket: socketIoType,
14
- data: any | reasonType
16
+ data: any | reasonType,
17
+ clb?: _clbFunc
15
18
  ) => void;
16
19
 
17
20
  class Io {
@@ -75,7 +78,6 @@ function webSocketServer(server: Server): WebSocketHandler {
75
78
  let id = v4();
76
79
  ws.id = id;
77
80
  wsClients.set(id, ws);
78
-
79
81
  // set Id to client and emit it
80
82
  ws.send(JSON.stringify({ type: "setId", id: id }));
81
83
  // run all listenners event for connection
@@ -127,6 +129,17 @@ function webSocketServer(server: Server): WebSocketHandler {
127
129
  (e) => e.event == options?.event && e?.type == "on"
128
130
  );
129
131
 
132
+ // callback to
133
+ let clb_ = null;
134
+ if (options?.uuid) {
135
+ clb_ = (data: any) => {
136
+ ws.send(
137
+ JSON.stringify({ type: "emit", event: options?.uuid, data })
138
+ );
139
+ };
140
+ } else {
141
+ clb_ = () => {};
142
+ }
130
143
  // run all listeners function if matchs
131
144
  evs?.map((ev) => {
132
145
  ws.token = options?.token || null;
@@ -141,9 +154,17 @@ function webSocketServer(server: Server): WebSocketHandler {
141
154
  });
142
155
  },
143
156
  emit: (event: string, data: any) =>
144
- ws.send(JSON.stringify({ type: "emit", event, data })),
157
+ ws.send(
158
+ JSON.stringify({
159
+ type: "emit",
160
+ event,
161
+ data,
162
+ uuid: options?.uuid,
163
+ })
164
+ ),
145
165
  },
146
- options.data
166
+ options?.data,
167
+ clb_
147
168
  );
148
169
  }
149
170
  });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@dnax/core",
3
- "version": "0.60.3",
3
+ "version": "0.60.5",
4
4
  "module": "index.ts",
5
5
  "type": "module",
6
6
  "bin": {
package/utils/index.ts CHANGED
@@ -28,7 +28,15 @@ function copy(data: object): object | any {
28
28
  }
29
29
 
30
30
  const jwt = {
31
- verify: (token: string): { decode: any; valid: boolean; error: any } => {
31
+ verify: (
32
+ token: string | null | undefined
33
+ ): { decode: any; valid: boolean; error: any } => {
34
+ if (!token)
35
+ return {
36
+ decode: null,
37
+ valid: false,
38
+ error: "Token required",
39
+ };
32
40
  const JWT_SECRET = String(Cfg.server?.jwt?.secret);
33
41
  let decode = null;
34
42
  let valid = true;