@live-change/user-service 0.2.32 → 0.2.37
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/contactOrUserProperty.js +13 -1
- package/package.json +4 -4
- package/sessionOrUserItem.js +31 -26
- package/sessionOrUserProperty.js +13 -13
package/contactOrUserProperty.js
CHANGED
|
@@ -107,6 +107,18 @@ definition.processor(function(service, app) {
|
|
|
107
107
|
extendedIdentifiers[key+'Type'] = contactProperty[key+'Type']
|
|
108
108
|
extendedIdentifiers[key] = contactProperty[key]
|
|
109
109
|
}
|
|
110
|
+
await service.trigger({
|
|
111
|
+
type: 'contactOrUserOwned' + modelName + 'Moved',
|
|
112
|
+
from: {
|
|
113
|
+
contactOrUserType: contactType,
|
|
114
|
+
contactOrUser: contact
|
|
115
|
+
},
|
|
116
|
+
to: {
|
|
117
|
+
contactOrUserType: 'user_User',
|
|
118
|
+
contactOrUser: user
|
|
119
|
+
},
|
|
120
|
+
...extendedIdentifiers
|
|
121
|
+
})
|
|
110
122
|
emit({
|
|
111
123
|
type: transferEventName,
|
|
112
124
|
from: {
|
|
@@ -120,7 +132,7 @@ definition.processor(function(service, app) {
|
|
|
120
132
|
...extendedIdentifiers
|
|
121
133
|
}
|
|
122
134
|
})
|
|
123
|
-
}
|
|
135
|
+
} // else ignore
|
|
124
136
|
}
|
|
125
137
|
}
|
|
126
138
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@live-change/user-service",
|
|
3
|
-
"version": "0.2.
|
|
3
|
+
"version": "0.2.37",
|
|
4
4
|
"description": "",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"scripts": {
|
|
@@ -21,9 +21,9 @@
|
|
|
21
21
|
"url": "https://www.viamage.com/"
|
|
22
22
|
},
|
|
23
23
|
"dependencies": {
|
|
24
|
-
"@live-change/framework": "0.6.
|
|
25
|
-
"@live-change/relations-plugin": "0.6.
|
|
24
|
+
"@live-change/framework": "0.6.5",
|
|
25
|
+
"@live-change/relations-plugin": "0.6.5",
|
|
26
26
|
"pluralize": "8.0.0"
|
|
27
27
|
},
|
|
28
|
-
"gitHead": "
|
|
28
|
+
"gitHead": "f3bc615d20a0112c7cc76d55ba1cbefb53b84f01"
|
|
29
29
|
}
|
package/sessionOrUserItem.js
CHANGED
|
@@ -10,7 +10,7 @@ definition.processor(function(service, app) {
|
|
|
10
10
|
for(let modelName in service.models) {
|
|
11
11
|
const model = service.models[modelName]
|
|
12
12
|
if(model.sessionOrUserItem) {
|
|
13
|
-
if (model.properties.
|
|
13
|
+
if (model.properties.sessionOrUser) throw new Error('user property already exists!!!')
|
|
14
14
|
const originalModelProperties = { ...model.properties }
|
|
15
15
|
const modelProperties = Object.keys(model.properties)
|
|
16
16
|
const defaults = App.utils.generateDefault(model.properties)
|
|
@@ -26,8 +26,13 @@ definition.processor(function(service, app) {
|
|
|
26
26
|
//console.log("USER ITEM", model)
|
|
27
27
|
|
|
28
28
|
if(model.itemOfAny) throw new Error("model " + modelName + " already have owner")
|
|
29
|
+
|
|
30
|
+
const extendedWith = config.extendedWith
|
|
31
|
+
? (Array.isArray(config.extendedWith) ? config.extendedWith : [config.extendedWith])
|
|
32
|
+
: []
|
|
29
33
|
model.itemOfAny = {
|
|
30
|
-
...config
|
|
34
|
+
...config,
|
|
35
|
+
to: ['sessionOrUser', ...extendedWith]
|
|
31
36
|
}
|
|
32
37
|
|
|
33
38
|
/// TODO: merge on signedIn trigger
|
|
@@ -43,7 +48,7 @@ definition.processor(function(service, app) {
|
|
|
43
48
|
properties: App.rangeProperties,
|
|
44
49
|
daoPath(range, { client, context }) {
|
|
45
50
|
const owner = client.user ? ['user_User', client.user] : ['session_Session', client.session]
|
|
46
|
-
const path = modelRuntime().indexRangePath('
|
|
51
|
+
const path = modelRuntime().indexRangePath('bySessionOrUser', owner, range )
|
|
47
52
|
return path
|
|
48
53
|
}
|
|
49
54
|
})
|
|
@@ -58,14 +63,14 @@ definition.processor(function(service, app) {
|
|
|
58
63
|
properties: App.rangeProperties,
|
|
59
64
|
daoPath(range, { client, context }) {
|
|
60
65
|
const owner = client.user ? ['user_User', client.user] : ['session_Session', client.session]
|
|
61
|
-
return modelRuntime().sortedIndexRangePath('
|
|
66
|
+
return modelRuntime().sortedIndexRangePath('bySsessionOrUser' + sortFieldUc, owner, App.extractRange(range))
|
|
62
67
|
}
|
|
63
68
|
})
|
|
64
69
|
}
|
|
65
70
|
}
|
|
66
71
|
|
|
67
72
|
if(config.ownerCreateAccess || config.ownerWriteAccess) {
|
|
68
|
-
const eventName = '
|
|
73
|
+
const eventName = 'sessionOrUserOwned' + modelName + 'Created'
|
|
69
74
|
const actionName = 'createMy' + modelName
|
|
70
75
|
service.actions[actionName] = new ActionDefinition({
|
|
71
76
|
name: actionName,
|
|
@@ -84,11 +89,11 @@ definition.processor(function(service, app) {
|
|
|
84
89
|
const entity = await modelRuntime().get(id)
|
|
85
90
|
if(entity) throw 'exists'
|
|
86
91
|
const identifiers = client.user ? {
|
|
87
|
-
|
|
88
|
-
|
|
92
|
+
sessionOrUserType: 'user_User',
|
|
93
|
+
sessionOrUser: client.user,
|
|
89
94
|
} : {
|
|
90
|
-
|
|
91
|
-
|
|
95
|
+
sessionOrUserType: 'session_Session',
|
|
96
|
+
sessionOrUser: client.session,
|
|
92
97
|
}
|
|
93
98
|
emit({
|
|
94
99
|
type: eventName,
|
|
@@ -101,7 +106,7 @@ definition.processor(function(service, app) {
|
|
|
101
106
|
})
|
|
102
107
|
}
|
|
103
108
|
if(config.ownerUpdateAccess || config.ownerWriteAccess) {
|
|
104
|
-
const eventName = '
|
|
109
|
+
const eventName = 'sessionOrUserOwned' + modelName + 'Updated'
|
|
105
110
|
const actionName = 'updateMy' + modelName
|
|
106
111
|
service.actions[actionName] = new ActionDefinition({
|
|
107
112
|
name: actionName,
|
|
@@ -119,11 +124,11 @@ definition.processor(function(service, app) {
|
|
|
119
124
|
async execute(properties, { client, service }, emit) {
|
|
120
125
|
const entity = await modelRuntime().get(properties[modelPropertyName])
|
|
121
126
|
if(!entity) throw 'not_found'
|
|
122
|
-
if(entity.
|
|
123
|
-
if(entity.
|
|
127
|
+
if(entity.sessionOrUserType == 'user_User') {
|
|
128
|
+
if(entity.sessionOrUser != client.user) throw 'not_authorized'
|
|
124
129
|
}
|
|
125
|
-
if(entity.
|
|
126
|
-
if(entity.
|
|
130
|
+
if(entity.sessionOrUserType == 'session_Session') {
|
|
131
|
+
if(entity.sessionOrUser != client.session) throw 'not_authorized'
|
|
127
132
|
}
|
|
128
133
|
let updateObject = {}
|
|
129
134
|
for(const propertyName of writeableProperties) {
|
|
@@ -134,11 +139,11 @@ definition.processor(function(service, app) {
|
|
|
134
139
|
const merged = App.utils.mergeDeep({}, entity, updateObject)
|
|
135
140
|
await App.validation.validate(merged, validators, { source: action, action, service, app, client })
|
|
136
141
|
const identifiers = client.user ? {
|
|
137
|
-
|
|
138
|
-
|
|
142
|
+
sessionOrUserType: 'user_User',
|
|
143
|
+
sessionOrUser: client.user,
|
|
139
144
|
} : {
|
|
140
|
-
|
|
141
|
-
|
|
145
|
+
sessionOrUserType: 'session_Session',
|
|
146
|
+
sessionOrUser: client.session,
|
|
142
147
|
}
|
|
143
148
|
emit({
|
|
144
149
|
type: eventName,
|
|
@@ -168,18 +173,18 @@ definition.processor(function(service, app) {
|
|
|
168
173
|
async execute(properties, { client, service }, emit) {
|
|
169
174
|
const entity = await modelRuntime().get(properties[modelPropertyName])
|
|
170
175
|
if(!entity) throw 'not_found'
|
|
171
|
-
if(entity.
|
|
172
|
-
if(entity.
|
|
176
|
+
if(entity.sessionOrUserType == 'user_User') {
|
|
177
|
+
if(entity.sessionOrUser != client.user) throw 'not_authorized'
|
|
173
178
|
}
|
|
174
|
-
if(entity.
|
|
175
|
-
if(entity.
|
|
179
|
+
if(entity.sessionOrUserType == 'session_Session') {
|
|
180
|
+
if(entity.sessionOrUser != client.session) throw 'not_authorized'
|
|
176
181
|
}
|
|
177
182
|
const identifiers = client.user ? {
|
|
178
|
-
|
|
179
|
-
|
|
183
|
+
sessionOrUserType: 'user_User',
|
|
184
|
+
sessionOrUser: client.user,
|
|
180
185
|
} : {
|
|
181
|
-
|
|
182
|
-
|
|
186
|
+
sessionOrUserType: 'session_Session',
|
|
187
|
+
sessionOrUser: client.session,
|
|
183
188
|
}
|
|
184
189
|
emit({
|
|
185
190
|
type: eventName,
|
package/sessionOrUserProperty.js
CHANGED
|
@@ -137,11 +137,11 @@ definition.processor(function(service, app) {
|
|
|
137
137
|
const data = App.utils.mergeDeep({}, defaults, newObject)
|
|
138
138
|
await App.validation.validate(data, validators, { source: action, action, service, app, client })
|
|
139
139
|
const identifiers = client.user ? {
|
|
140
|
-
|
|
141
|
-
|
|
140
|
+
sessionOrUserType: 'user_User',
|
|
141
|
+
sessionOrUser: client.user,
|
|
142
142
|
} : {
|
|
143
|
-
|
|
144
|
-
|
|
143
|
+
sessionOrUserType: 'session_Session',
|
|
144
|
+
sessionOrUser: client.session,
|
|
145
145
|
}
|
|
146
146
|
emit({
|
|
147
147
|
type: eventName,
|
|
@@ -180,11 +180,11 @@ definition.processor(function(service, app) {
|
|
|
180
180
|
const merged = App.utils.mergeDeep({}, entity, updateObject)
|
|
181
181
|
await App.validation.validate(merged, validators, { source: action, action, service, app, client })
|
|
182
182
|
const identifiers = client.user ? {
|
|
183
|
-
|
|
184
|
-
|
|
183
|
+
sessionOrUserType: 'user_User',
|
|
184
|
+
sessionOrUser: client.user,
|
|
185
185
|
} : {
|
|
186
|
-
|
|
187
|
-
|
|
186
|
+
sessionOrUserType: 'session_Session',
|
|
187
|
+
sessionOrUser: client.session,
|
|
188
188
|
}
|
|
189
189
|
emit({
|
|
190
190
|
type: eventName,
|
|
@@ -211,11 +211,11 @@ definition.processor(function(service, app) {
|
|
|
211
211
|
const entity = await modelRuntime().get(id)
|
|
212
212
|
if (!entity) throw 'not_found'
|
|
213
213
|
const identifiers = client.user ? {
|
|
214
|
-
|
|
215
|
-
|
|
214
|
+
sessionOrUserType: 'user_User',
|
|
215
|
+
sessionOrUser: client.user,
|
|
216
216
|
} : {
|
|
217
|
-
|
|
218
|
-
|
|
217
|
+
sessionOrUserType: 'session_Session',
|
|
218
|
+
sessionOrUser: client.session,
|
|
219
219
|
}
|
|
220
220
|
emit({
|
|
221
221
|
type: eventName,
|
|
@@ -228,4 +228,4 @@ definition.processor(function(service, app) {
|
|
|
228
228
|
}
|
|
229
229
|
}
|
|
230
230
|
|
|
231
|
-
})
|
|
231
|
+
})
|