@jcbuisson/express-x 2.1.11 → 2.1.13

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": "@jcbuisson/express-x",
3
- "version": "2.1.11",
3
+ "version": "2.1.13",
4
4
  "description": "",
5
5
  "type": "module",
6
6
  "main": "src/index.mjs",
@@ -1,6 +1,8 @@
1
1
 
2
2
  import bcrypt from 'bcryptjs'
3
3
 
4
+ import { EXError } from './server.mjs'
5
+
4
6
  /*
5
7
  * Add a timestamp property of name `field` with current time as value
6
8
  */
@@ -34,13 +36,6 @@ export function protect(field) {
34
36
  }
35
37
  }
36
38
 
37
- class NotAuthenticatedError extends Error {
38
- constructor(message) {
39
- super(message)
40
- this.code = 'not-authenticated'
41
- }
42
- }
43
-
44
39
  export const isNotExpired = async (context) => {
45
40
  // do nothing if it's not a client call from a ws connexion
46
41
  if (!context.socket) return
@@ -61,10 +56,10 @@ export const isNotExpired = async (context) => {
61
56
  // send an event to the client (typical client handling: logout)
62
57
  context.socket.emit('expired')
63
58
  // throw exception
64
- throw new NotAuthenticatedError("Session expired")
59
+ throw new EXError('not-authenticated', "Session expired")
65
60
  }
66
61
  } else {
67
- throw new NotAuthenticatedError("No expiresAt in socket.data")
62
+ throw new EXError('not-authenticated', "No expiresAt in socket.data")
68
63
  }
69
64
  }
70
65
 
@@ -74,7 +69,7 @@ export const isNotExpired = async (context) => {
74
69
  export const isAuthenticated = async (context) => {
75
70
  // do nothing if it's not a client call from a ws connexion
76
71
  if (!context.socket) return
77
- if (!context.socket.data.user) throw new NotAuthenticatedError('no user in socket.data')
72
+ if (!context.socket.data.user) throw new EXError('not-authenticated', 'no user in socket.data')
78
73
  }
79
74
 
80
75
  /*
@@ -83,4 +78,4 @@ export const isAuthenticated = async (context) => {
83
78
  export const extendExpiration = (duration) => async (context) => {
84
79
  const now = new Date()
85
80
  context.socket.data.expiresAt = new Date(now.getTime() + duration)
86
- }
81
+ }
package/src/server.mjs CHANGED
@@ -5,6 +5,13 @@ import { Server } from "socket.io"
5
5
 
6
6
  // UTILISER L'ACKNOWLEDGEMENT : https://socket.io/docs/v4/#acknowledgements
7
7
 
8
+ export default class EXError extends Error {
9
+ constructor(code, message) {
10
+ super(message)
11
+ this.code = code
12
+ }
13
+ }
14
+
8
15
  export function expressX(config) {
9
16
 
10
17
  const services = {}