@live-change/framework 0.5.12 → 0.5.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/lib/App.js +1 -1
- package/lib/runtime/ApiServer.js +10 -10
- package/lib/runtime/LiveDao.js +14 -20
- package/package.json +1 -1
package/lib/App.js
CHANGED
|
@@ -73,7 +73,7 @@ class App {
|
|
|
73
73
|
this.databaseName = config?.db?.name || 'test'
|
|
74
74
|
|
|
75
75
|
this.instanceId = randomString(4)
|
|
76
|
-
this.uidGenerator = uidGenerator(this.instanceId)
|
|
76
|
+
this.uidGenerator = uidGenerator(this.instanceId, this.config.uidBorders)
|
|
77
77
|
|
|
78
78
|
this.activeTimeouts = new Set()
|
|
79
79
|
}
|
package/lib/runtime/ApiServer.js
CHANGED
|
@@ -28,24 +28,24 @@ class ApiServer {
|
|
|
28
28
|
|
|
29
29
|
async daoFactory(credentialsp, ip) {
|
|
30
30
|
let credentials = { ...credentialsp, ip, roles: [] }
|
|
31
|
+
const allAuthenticators = []
|
|
31
32
|
if(this.config.authenticators) {
|
|
32
33
|
const auth = Array.isArray(this.config.authenticators)
|
|
33
34
|
? this.config.authenticators : [this.config.authenticators]
|
|
34
|
-
|
|
35
|
-
if(authenticator && authenticator.prepareCredentials)
|
|
36
|
-
await authenticator.prepareCredentials(credentials, this.config)
|
|
37
|
-
}
|
|
35
|
+
allAuthenticators.push(...auth.filter(a => !!a))
|
|
38
36
|
}
|
|
39
37
|
for(const service of this.config.services) {
|
|
40
|
-
console.log("SERIVCE AUTH", service.name, service.authenticators)
|
|
38
|
+
//console.log("SERIVCE AUTH", service.name, service.authenticators)
|
|
41
39
|
if(service.authenticators) {
|
|
42
|
-
|
|
43
|
-
if(authenticator && authenticator.prepareCredentials)
|
|
44
|
-
await authenticator.prepareCredentials(credentials, this.config)
|
|
45
|
-
}
|
|
40
|
+
allAuthenticators.push(...service.authenticators.filter(a => !!a))
|
|
46
41
|
}
|
|
47
42
|
}
|
|
48
|
-
const
|
|
43
|
+
for(const authenticator of allAuthenticators) {
|
|
44
|
+
if(authenticator.prepareCredentials) {
|
|
45
|
+
await authenticator.prepareCredentials(credentials, this.config)
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
const dao = new this.DaoConstructor({ ...this.config, authenticators: allAuthenticators }, { ...credentials })
|
|
49
49
|
await dao.start()
|
|
50
50
|
return dao
|
|
51
51
|
}
|
package/lib/runtime/LiveDao.js
CHANGED
|
@@ -11,21 +11,7 @@ class LiveDao extends LcDao.DaoProxy {
|
|
|
11
11
|
|
|
12
12
|
this.authenticators = []
|
|
13
13
|
if(this.config.authenticators) {
|
|
14
|
-
|
|
15
|
-
? this.config.authenticators : [this.config.authenticators]
|
|
16
|
-
for(const authenticator of auth) {
|
|
17
|
-
if(authenticator && authenticator.authenticatorObservable)
|
|
18
|
-
this.authenticators.push(authenticator)
|
|
19
|
-
}
|
|
20
|
-
}
|
|
21
|
-
for(const service of this.config.services) {
|
|
22
|
-
console.log("SERIVCE AUTH", service.name, service.authenticators)
|
|
23
|
-
if(service.authenticators) {
|
|
24
|
-
for(const authenticator of service.authenticators) {
|
|
25
|
-
if(authenticator && authenticator.authenticatorObservable)
|
|
26
|
-
this.authenticators.push(authenticator)
|
|
27
|
-
}
|
|
28
|
-
}
|
|
14
|
+
this.authenticators = this.config.authenticators.filter(a => a.credentialsObservable)
|
|
29
15
|
}
|
|
30
16
|
|
|
31
17
|
this.currentDao = null
|
|
@@ -48,8 +34,8 @@ class LiveDao extends LcDao.DaoProxy {
|
|
|
48
34
|
for(const credentialsObserver of this.credentialsObservations) {
|
|
49
35
|
credentials = {
|
|
50
36
|
...credentials,
|
|
51
|
-
...
|
|
52
|
-
roles: [...credentials.roles, ...credentialsObserver.credentials.roles]
|
|
37
|
+
...credentialsObserver.credentials,
|
|
38
|
+
roles: [...credentials.roles, ...(credentialsObserver.credentials.roles || [])]
|
|
53
39
|
}
|
|
54
40
|
}
|
|
55
41
|
return credentials
|
|
@@ -57,13 +43,21 @@ class LiveDao extends LcDao.DaoProxy {
|
|
|
57
43
|
|
|
58
44
|
async start() {
|
|
59
45
|
this.credentialsObservations = this.authenticators.map(authenticator => {
|
|
60
|
-
const
|
|
46
|
+
const result = authenticator.credentialsObservable(this.initialCredentials)
|
|
47
|
+
const observable = result.then ? new LcDao.ObservablePromiseProxy(result) : result
|
|
61
48
|
const observer = {
|
|
62
|
-
set: (
|
|
63
|
-
|
|
49
|
+
set: (data) => {
|
|
50
|
+
console.log("NEW CREDENTIALS", data)
|
|
51
|
+
if(data) {
|
|
52
|
+
const { id, ...newCredentials } = data
|
|
53
|
+
state.credentials = newCredentials
|
|
54
|
+
} else {
|
|
55
|
+
state.credentials = {}
|
|
56
|
+
}
|
|
64
57
|
this.refreshCredentials()
|
|
65
58
|
}
|
|
66
59
|
}
|
|
60
|
+
observable.observe(observer)
|
|
67
61
|
const promise = waitForSignal(observable)
|
|
68
62
|
const state = {
|
|
69
63
|
observable, observer, promise, credentials: {}
|