@live-change/session-service 0.9.198 → 0.9.200

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 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
 
@@ -1,16 +1,11 @@
1
- import definition from './definition.js'
2
1
  import { decodeUid } from "@live-change/uid"
3
2
 
4
- definition.processor(function(service, app) {
5
-
6
- service.validators.localId = (settings) => (value, context) => {
7
- if (!value) return
8
- //console.log("VALIDATE LOCAL ID", value, "=>", decodeUid(value), "BY", context.client)
9
- const {date, number, at} = decodeUid(value)
10
- if (at.length < 16) return "tooShortSessionFingerprint"
11
- if (context.client.session && at === context.client.session.slice(0, at.length)) return
12
- if (context.client.user && at === context.client.user.slice(0, at.length)) return
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.198",
3
+ "version": "0.9.200",
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.198",
26
- "@live-change/relations-plugin": "^0.9.198",
25
+ "@live-change/framework": "^0.9.200",
26
+ "@live-change/relations-plugin": "^0.9.200",
27
27
  "pluralize": "^8.0.0"
28
28
  },
29
- "gitHead": "7e485dcbaa2af7fb17052a40238210dc8bdf0c09"
29
+ "gitHead": "a509834e600a546297faa7d1534b6f52e66d2e66"
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,6 +61,26 @@ 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
@@ -97,6 +121,7 @@ definition.processor(function(service, app) {
97
121
  return id
98
122
  }
99
123
  })
124
+ model.ownerCrud.create ??= actionName
100
125
  const action = service.actions[actionName]
101
126
  const validators = App.validation.getValidators(action, service, action)
102
127
  }
@@ -129,7 +154,7 @@ definition.processor(function(service, app) {
129
154
  const computedUpdates = App.computeUpdates(model, { ...entity, ...properties }, { client, service })
130
155
  const data = App.utils.mergeDeep({}, updateObject, computedUpdates)
131
156
  const merged = App.utils.mergeDeep({}, entity, data)
132
- await App.validation.validate(merged, validators, validationContext)
157
+ await App.validation.validate({ ...merged, [modelPropertyName]: entity.id }, validators, validationContext)
133
158
  emit({
134
159
  type: eventName,
135
160
  [modelPropertyName]: entity.id,
@@ -140,6 +165,7 @@ definition.processor(function(service, app) {
140
165
  })
141
166
  }
142
167
  })
168
+ model.ownerCrud.update ??= actionName
143
169
  const action = service.actions[actionName]
144
170
  const validators = App.validation.getValidators(action, service, action)
145
171
  }
@@ -170,6 +196,7 @@ definition.processor(function(service, app) {
170
196
  })
171
197
  }
172
198
  })
199
+ model.ownerCrud.delete ??= actionName
173
200
  }
174
201
  }
175
202
  }
@@ -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
  }
@@ -124,6 +128,7 @@ definition.processor(function(service, app) {
124
128
  })
125
129
  }
126
130
  })
131
+ model.ownerCrud.update ??= actionName
127
132
  const action = service.actions[actionName]
128
133
  const validators = App.validation.getValidators(action, service, action)
129
134
  }
@@ -147,6 +152,7 @@ definition.processor(function(service, app) {
147
152
  })
148
153
  }
149
154
  })
155
+ model.ownerCrud.reset ??= actionName
150
156
  }
151
157
 
152
158
  }