@jcbuisson/express-x-client 1.0.1 → 1.0.3
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 +1 -1
- package/src/{expressx-client.js → express-x-client.js} +26 -20
- package/.adminjs/.entry.js +0 -1
- package/.env +0 -2
package/package.json
CHANGED
|
@@ -1,22 +1,22 @@
|
|
|
1
1
|
|
|
2
|
-
import { io } from 'socket.io-client'
|
|
3
2
|
import { v4 } from 'uuid'
|
|
4
3
|
|
|
5
|
-
function expressxClient() {
|
|
6
|
-
|
|
7
|
-
const socket = io()
|
|
4
|
+
function expressxClient(socket) {
|
|
8
5
|
|
|
9
6
|
const waitingPromises = {}
|
|
10
7
|
const action2service2handlers = {}
|
|
8
|
+
const serviceActions = {}
|
|
11
9
|
|
|
12
10
|
// on connection
|
|
13
11
|
socket.on("connected", async (connectionId) => {
|
|
14
12
|
console.log('connected', connectionId)
|
|
15
|
-
|
|
16
|
-
|
|
13
|
+
|
|
14
|
+
// TODO: configurable
|
|
15
|
+
const accessToken = window.sessionStorage.getItem('feathers-jwt')
|
|
16
|
+
if (accessToken) {
|
|
17
17
|
// disconnect/reconnect: reauthenticate
|
|
18
|
-
console.log('reauthenticate with',
|
|
19
|
-
serviceMethodRequest('authenticate', '
|
|
18
|
+
console.log('reauthenticate with', accessToken)
|
|
19
|
+
serviceMethodRequest('authenticate', 'reauthenticate', accessToken)
|
|
20
20
|
}
|
|
21
21
|
})
|
|
22
22
|
|
|
@@ -41,7 +41,7 @@ function expressxClient() {
|
|
|
41
41
|
if (handler) handler(result)
|
|
42
42
|
})
|
|
43
43
|
|
|
44
|
-
async function serviceMethodRequest(name, action,
|
|
44
|
+
async function serviceMethodRequest(name, action, ...args) {
|
|
45
45
|
const uid = v4()
|
|
46
46
|
const promise = new Promise((resolve, reject) => {
|
|
47
47
|
waitingPromises[uid] = [resolve, reject]
|
|
@@ -50,33 +50,39 @@ function expressxClient() {
|
|
|
50
50
|
uid,
|
|
51
51
|
name,
|
|
52
52
|
action,
|
|
53
|
-
|
|
53
|
+
args,
|
|
54
54
|
})
|
|
55
55
|
return promise
|
|
56
56
|
}
|
|
57
57
|
|
|
58
58
|
function service(name) {
|
|
59
|
-
|
|
60
|
-
create: (data) => serviceMethodRequest(name, 'create', [data]),
|
|
61
|
-
get: (id) => serviceMethodRequest(name, 'create', [id]),
|
|
62
|
-
patch: (id, data) => serviceMethodRequest(name, 'create', [id, data]),
|
|
63
|
-
update: (id, data) => serviceMethodRequest(name, 'update', [id, data]),
|
|
64
|
-
remove: (id) => serviceMethodRequest(name, 'remove', [id]),
|
|
65
|
-
find: (data) => serviceMethodRequest(name, 'find', [data]),
|
|
66
|
-
|
|
59
|
+
const service = {
|
|
67
60
|
// associate a handler to a pub/sub event for this service
|
|
68
61
|
on: (action, handler) => {
|
|
69
62
|
if (!action2service2handlers[action]) action2service2handlers[action] = {}
|
|
70
63
|
const serviceHandlers = action2service2handlers[action]
|
|
71
64
|
serviceHandlers[name] = handler
|
|
72
|
-
console.log('action2service2handlers', action2service2handlers)
|
|
73
65
|
},
|
|
74
66
|
}
|
|
67
|
+
const handler = {
|
|
68
|
+
get(service, action) {
|
|
69
|
+
if (!(action in service)) {
|
|
70
|
+
service[action] = (...args) => serviceMethodRequest(name, action, ...args)
|
|
71
|
+
}
|
|
72
|
+
return service[action]
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
return new Proxy(service, handler)
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
function logout() {
|
|
79
|
+
// TODO: configurable
|
|
80
|
+
window.sessionStorage.removeItem('feathers-jwt')
|
|
75
81
|
}
|
|
76
82
|
|
|
77
83
|
return {
|
|
78
84
|
service,
|
|
79
|
-
|
|
85
|
+
logout,
|
|
80
86
|
}
|
|
81
87
|
}
|
|
82
88
|
|
package/.adminjs/.entry.js
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
AdminJS.UserComponents = {}
|
package/.env
DELETED