@live-change/session-service 0.9.197 → 0.9.199
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/index.js +3 -1
- package/localIdValidator.js +9 -14
- package/package.json +4 -4
- package/sessionItem.js +45 -4
- package/sessionProperty.js +12 -3
package/index.js
CHANGED
|
@@ -2,6 +2,7 @@ import App from '@live-change/framework'
|
|
|
2
2
|
const app = App.app()
|
|
3
3
|
import definition from './definition.js'
|
|
4
4
|
import { Session } from './model.js'
|
|
5
|
+
import localIdValidator from './localIdValidator.js'
|
|
5
6
|
|
|
6
7
|
definition.view({
|
|
7
8
|
name: 'currentSession',
|
|
@@ -76,8 +77,9 @@ definition.trigger({
|
|
|
76
77
|
}
|
|
77
78
|
})
|
|
78
79
|
|
|
80
|
+
definition.validator('localId', localIdValidator)
|
|
81
|
+
|
|
79
82
|
import './authenticator.js'
|
|
80
|
-
import './localIdValidator.js'
|
|
81
83
|
import './sessionProperty.js'
|
|
82
84
|
import './sessionItem.js'
|
|
83
85
|
|
package/localIdValidator.js
CHANGED
|
@@ -1,16 +1,11 @@
|
|
|
1
|
-
import definition from './definition.js'
|
|
2
1
|
import { decodeUid } from "@live-change/uid"
|
|
3
2
|
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
return "sessionFingerPrintMismatch"
|
|
14
|
-
}
|
|
15
|
-
|
|
16
|
-
})
|
|
3
|
+
export default (settings) => (value, context) => {
|
|
4
|
+
if (!value) return
|
|
5
|
+
//console.log("VALIDATE LOCAL ID", value, "=>", decodeUid(value), "BY", context.client)
|
|
6
|
+
const { date, number, at } = decodeUid(value)
|
|
7
|
+
if (at.length < 16) return "tooShortSessionFingerprint"
|
|
8
|
+
if (context.client.session && at === context.client.session.slice(0, at.length)) return
|
|
9
|
+
if (context.client.user && at === context.client.user.slice(0, at.length)) return
|
|
10
|
+
return "sessionFingerPrintMismatch"
|
|
11
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@live-change/session-service",
|
|
3
|
-
"version": "0.9.
|
|
3
|
+
"version": "0.9.199",
|
|
4
4
|
"description": "",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"scripts": {
|
|
@@ -22,9 +22,9 @@
|
|
|
22
22
|
},
|
|
23
23
|
"type": "module",
|
|
24
24
|
"dependencies": {
|
|
25
|
-
"@live-change/framework": "^0.9.
|
|
26
|
-
"@live-change/relations-plugin": "^0.9.
|
|
25
|
+
"@live-change/framework": "^0.9.199",
|
|
26
|
+
"@live-change/relations-plugin": "^0.9.199",
|
|
27
27
|
"pluralize": "^8.0.0"
|
|
28
28
|
},
|
|
29
|
-
"gitHead": "
|
|
29
|
+
"gitHead": "1900043a10cf9ad49b9cc33a539fb973706de962"
|
|
30
30
|
}
|
package/sessionItem.js
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import definition from './definition.js'
|
|
2
|
+
import App from '@live-change/framework'
|
|
2
3
|
import {
|
|
3
4
|
PropertyDefinition, ViewDefinition, IndexDefinition, ActionDefinition, EventDefinition
|
|
4
5
|
} from '@live-change/framework'
|
|
@@ -32,8 +33,11 @@ definition.processor(function(service, app) {
|
|
|
32
33
|
...config
|
|
33
34
|
}
|
|
34
35
|
|
|
36
|
+
if (!model.ownerCrud) model.ownerCrud = {}
|
|
37
|
+
|
|
35
38
|
if(config.sessionReadAccess) {
|
|
36
39
|
const viewName = 'mySession' + pluralize(modelName)
|
|
40
|
+
model.ownerCrud.range ??= viewName
|
|
37
41
|
service.views[viewName] = new ViewDefinition({
|
|
38
42
|
name: viewName,
|
|
39
43
|
access: config.sessionReadAccess,
|
|
@@ -57,11 +61,32 @@ definition.processor(function(service, app) {
|
|
|
57
61
|
}
|
|
58
62
|
}
|
|
59
63
|
|
|
64
|
+
if(config.sessionReadAccess) {
|
|
65
|
+
const viewName = 'mySession' + modelName
|
|
66
|
+
model.ownerCrud.read ??= viewName
|
|
67
|
+
service.views[viewName] = new ViewDefinition({
|
|
68
|
+
name: viewName,
|
|
69
|
+
async access(params, context) {
|
|
70
|
+
if(!context.client.session) return false
|
|
71
|
+
if(context.visibilityTest) return true
|
|
72
|
+
const data = await modelRuntime().get(params[modelPropertyName])
|
|
73
|
+
if(data.session !== context.client.session) return false
|
|
74
|
+
return config.sessionReadAccess ? config.sessionReadAccess(params, context) : true
|
|
75
|
+
},
|
|
76
|
+
properties: App.rangeProperties,
|
|
77
|
+
daoPath(params, { client, context }) {
|
|
78
|
+
const path = modelRuntime().path(params[modelPropertyName])
|
|
79
|
+
return path
|
|
80
|
+
}
|
|
81
|
+
})
|
|
82
|
+
}
|
|
83
|
+
|
|
60
84
|
if(config.sessionCreateAccess || config.sessionWriteAccess) {
|
|
61
85
|
const eventName = modelName + 'Created'
|
|
62
86
|
const actionName = 'createMySession' + modelName
|
|
63
87
|
service.actions[actionName] = new ActionDefinition({
|
|
64
88
|
name: actionName,
|
|
89
|
+
skipValidation: true,
|
|
65
90
|
access: config.sessionCreateAccess || config.sessionWriteAccess,
|
|
66
91
|
properties: {
|
|
67
92
|
...originalModelProperties,
|
|
@@ -76,17 +101,29 @@ definition.processor(function(service, app) {
|
|
|
76
101
|
const id = properties[modelPropertyName] || app.generateUid()
|
|
77
102
|
const entity = await modelRuntime().get(id)
|
|
78
103
|
if(entity) throw app.logicError("exists")
|
|
104
|
+
let newObject = {}
|
|
105
|
+
for(const propertyName of writeableProperties) {
|
|
106
|
+
if(properties.hasOwnProperty(propertyName)) {
|
|
107
|
+
newObject[propertyName] = properties[propertyName]
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
const data = App.utils.mergeDeep({},
|
|
111
|
+
App.computeDefaults(model, properties, { client, service }), newObject)
|
|
112
|
+
await App.validation.validate(data, validators, validationContext)
|
|
79
113
|
emit({
|
|
80
114
|
type: eventName,
|
|
81
115
|
[modelPropertyName]: id,
|
|
82
116
|
identifiers: {
|
|
83
117
|
session: client.session,
|
|
84
118
|
},
|
|
85
|
-
data
|
|
119
|
+
data
|
|
86
120
|
})
|
|
87
121
|
return id
|
|
88
122
|
}
|
|
89
123
|
})
|
|
124
|
+
model.ownerCrud.create ??= actionName
|
|
125
|
+
const action = service.actions[actionName]
|
|
126
|
+
const validators = App.validation.getValidators(action, service, action)
|
|
90
127
|
}
|
|
91
128
|
if(config.sessionUpdateAccess || config.sessionWriteAccess) {
|
|
92
129
|
const eventName = modelName + 'Updated'
|
|
@@ -114,18 +151,21 @@ definition.processor(function(service, app) {
|
|
|
114
151
|
updateObject[propertyName] = properties[propertyName]
|
|
115
152
|
}
|
|
116
153
|
}
|
|
117
|
-
const
|
|
118
|
-
|
|
154
|
+
const computedUpdates = App.computeUpdates(model, { ...entity, ...properties }, { client, service })
|
|
155
|
+
const data = App.utils.mergeDeep({}, updateObject, computedUpdates)
|
|
156
|
+
const merged = App.utils.mergeDeep({}, entity, data)
|
|
157
|
+
await App.validation.validate({ ...merged, [modelPropertyName]: entity.id }, validators, validationContext)
|
|
119
158
|
emit({
|
|
120
159
|
type: eventName,
|
|
121
160
|
[modelPropertyName]: entity.id,
|
|
122
161
|
identifiers: {
|
|
123
162
|
session: client.session,
|
|
124
163
|
},
|
|
125
|
-
data
|
|
164
|
+
data
|
|
126
165
|
})
|
|
127
166
|
}
|
|
128
167
|
})
|
|
168
|
+
model.ownerCrud.update ??= actionName
|
|
129
169
|
const action = service.actions[actionName]
|
|
130
170
|
const validators = App.validation.getValidators(action, service, action)
|
|
131
171
|
}
|
|
@@ -156,6 +196,7 @@ definition.processor(function(service, app) {
|
|
|
156
196
|
})
|
|
157
197
|
}
|
|
158
198
|
})
|
|
199
|
+
model.ownerCrud.delete ??= actionName
|
|
159
200
|
}
|
|
160
201
|
}
|
|
161
202
|
}
|
package/sessionProperty.js
CHANGED
|
@@ -28,8 +28,11 @@ definition.processor(function(service, app) {
|
|
|
28
28
|
...config
|
|
29
29
|
}
|
|
30
30
|
|
|
31
|
+
if (!model.ownerCrud) model.ownerCrud = {}
|
|
32
|
+
|
|
31
33
|
if(config.sessionReadAccess) {
|
|
32
34
|
const viewName = 'mySession' + modelName
|
|
35
|
+
model.ownerCrud.read ??= viewName
|
|
33
36
|
service.views[viewName] = new ViewDefinition({
|
|
34
37
|
name: viewName,
|
|
35
38
|
access: config.sessionReadAccess,
|
|
@@ -85,6 +88,7 @@ definition.processor(function(service, app) {
|
|
|
85
88
|
})
|
|
86
89
|
}
|
|
87
90
|
})
|
|
91
|
+
model.ownerCrud.create ??= actionName
|
|
88
92
|
const action = service.actions[actionName]
|
|
89
93
|
const validators = App.validation.getValidators(action, service, action)
|
|
90
94
|
}
|
|
@@ -110,17 +114,21 @@ definition.processor(function(service, app) {
|
|
|
110
114
|
updateObject[propertyName] = properties[propertyName]
|
|
111
115
|
}
|
|
112
116
|
}
|
|
113
|
-
const
|
|
114
|
-
|
|
117
|
+
const computedUpdates = App.computeUpdates(model, { ...entity, ...properties }, { client, service })
|
|
118
|
+
const data = App.utils.mergeDeep({}, updateObject, computedUpdates)
|
|
119
|
+
const merged = App.utils.mergeDeep({}, entity, data)
|
|
120
|
+
await App.validation.validate({ session: client.session, ...merged }, validators,
|
|
121
|
+
validationContext)
|
|
115
122
|
emit({
|
|
116
123
|
type: eventName,
|
|
117
124
|
identifiers: {
|
|
118
125
|
session: client.session
|
|
119
126
|
},
|
|
120
|
-
data
|
|
127
|
+
data
|
|
121
128
|
})
|
|
122
129
|
}
|
|
123
130
|
})
|
|
131
|
+
model.ownerCrud.update ??= actionName
|
|
124
132
|
const action = service.actions[actionName]
|
|
125
133
|
const validators = App.validation.getValidators(action, service, action)
|
|
126
134
|
}
|
|
@@ -144,6 +152,7 @@ definition.processor(function(service, app) {
|
|
|
144
152
|
})
|
|
145
153
|
}
|
|
146
154
|
})
|
|
155
|
+
model.ownerCrud.reset ??= actionName
|
|
147
156
|
}
|
|
148
157
|
|
|
149
158
|
}
|