@jcbuisson/express-x 2.0.0 → 2.0.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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@jcbuisson/express-x",
3
- "version": "2.0.0",
3
+ "version": "2.0.2",
4
4
  "description": "",
5
5
  "type": "module",
6
6
  "main": "src/index.mjs",
@@ -35,14 +35,13 @@ export function protect(field) {
35
35
  }
36
36
 
37
37
  /*
38
- * Does nothing for calls which are not client-side with websocket transport
38
+ * Does nothing for calls which are not client-side
39
39
  * Check if the 'expireAt' key in socket.data is met
40
40
  * If it is met, throw an error (which will be sent back to the calling server or client) and reset socket.data
41
41
  * If not, do nothing. If needed, an application-level hook may automatically extend the expiration data at each service call
42
42
  */
43
43
  export const isNotExpired = async (context) => {
44
- // return context
45
- if (context.caller !== 'client' || context.transport !== 'ws') return
44
+ if (context.caller !== 'client') return
46
45
 
47
46
  const expireAt = context.socket.data.expireAt
48
47
  if (expireAt) {
package/src/index.mjs CHANGED
@@ -1,6 +1,6 @@
1
1
 
2
2
  import { expressX } from './server.mjs'
3
- import { hashPassword, protect, isNotExpired } from './common-hooks.mjs'
3
+ import { addTimestamp, hashPassword, protect, isNotExpired } from './common-hooks.mjs'
4
4
 
5
5
  export {
6
6
  expressX,
package/src/server.mjs CHANGED
@@ -253,6 +253,12 @@ export function expressX(config) {
253
253
  socket.leave(channelName)
254
254
  }
255
255
 
256
+ // There is a need for events sent outside any service method call, for example on unsolicited-by-frontend backend state change
257
+ async function sendAppEvent(channelName, type, value) {
258
+ console.log('sendAppEvent', channelName, type, value)
259
+ io.to(channelName).emit('app-event', { type, value })
260
+ }
261
+
256
262
  // enhance `app` with objects and methods
257
263
  return Object.assign(app, {
258
264
  io,
@@ -263,6 +269,7 @@ export function expressX(config) {
263
269
  hooks,
264
270
  joinChannel,
265
271
  leaveChannel,
272
+ sendAppEvent,
266
273
  })
267
274
 
268
275
  }