@live-change/user-service 0.8.24 → 0.8.26

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.
@@ -195,8 +195,8 @@ definition.processor(function(service, app) {
195
195
  async execute(properties, { client, service }, emit) {
196
196
  const entity = await modelRuntime().get(properties[modelPropertyName])
197
197
  if(!entity) throw 'not_found'
198
- if(entity.ownerType == 'user_User') {
199
- if(entity.owner != client.user) throw 'not_authorized'
198
+ if(entity.ownerType === 'user_User') {
199
+ if(entity.owner !== client.user) throw 'not_authorized'
200
200
  } else throw 'not_authorized'
201
201
  let updateObject = {}
202
202
  for(const propertyName of writeableProperties) {
@@ -242,8 +242,8 @@ definition.processor(function(service, app) {
242
242
  async execute(properties, { client, service }, emit) {
243
243
  const entity = await modelRuntime().get(properties[modelPropertyName])
244
244
  if(!entity) throw 'not_found'
245
- if(entity.ownerType == 'user_User') {
246
- if(entity.owner != client.user) throw 'not_authorized'
245
+ if(entity.ownerType === 'user_User') {
246
+ if(entity.owner !== client.user) throw 'not_authorized'
247
247
  } else throw 'not_authorized'
248
248
  const identifiers = client.user ? {
249
249
  ownerType: 'user_User',
package/index.js CHANGED
@@ -20,6 +20,7 @@ definition.trigger({
20
20
  type: User
21
21
  },
22
22
  },
23
+ waitForEvents: true,
23
24
  async execute({ user }, { client, service }, emit) {
24
25
  if(!user) {
25
26
  user = app.generateUid()
@@ -44,6 +45,7 @@ definition.trigger({
44
45
  validation: ['nonEmpty']
45
46
  }
46
47
  },
48
+ waitForEvents: true,
47
49
  async execute({ user, session }, { client, service }, emit) {
48
50
  const userData = await User.get(user)
49
51
  if(!userData) throw 'userNotFound'
@@ -87,6 +89,7 @@ definition.trigger({
87
89
  validation: ['nonEmpty']
88
90
  }
89
91
  },
92
+ waitForEvents: true,
90
93
  async execute({ user, session }, { client, service }, emit) {
91
94
  if(!user) {
92
95
  user = app.generateUid()
@@ -106,6 +109,42 @@ definition.trigger({
106
109
  }
107
110
  })
108
111
 
112
+ definition.action({
113
+ name: 'switchUser',
114
+ properties: {
115
+ to: {
116
+ type: User
117
+ }
118
+ },
119
+ waitForEvents: true,
120
+ access: (params, { client }) => {
121
+ return client.roles && client.roles.includes('admin')
122
+ },
123
+ async execute({ user }, { client, service }, emit) {
124
+ const userData = await User.get(user)
125
+ if(!userData) throw 'userNotFound'
126
+ await service.trigger({
127
+ type: 'signedOut',
128
+ session: client.session,
129
+ user: client.user
130
+ })
131
+ emit({
132
+ type: "signedOut",
133
+ user: client.user,
134
+ session: client.session
135
+ })
136
+ const session = client.session
137
+ await service.trigger({
138
+ type: 'signedIn',
139
+ session, user
140
+ })
141
+ emit({
142
+ type: "signedIn",
143
+ user, session
144
+ })
145
+ }
146
+ })
147
+
109
148
  definition.action({
110
149
  name: 'deleteMe',
111
150
  properties: {
@@ -113,6 +152,7 @@ definition.action({
113
152
  access: (params, { client }) => {
114
153
  return !!client.user
115
154
  },
155
+ waitForEvents: true,
116
156
  async execute({ }, { client, service }, emit) {
117
157
  const user = client.user
118
158
  await service.trigger({
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@live-change/user-service",
3
- "version": "0.8.24",
3
+ "version": "0.8.26",
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.8.24",
26
- "@live-change/relations-plugin": "^0.8.24",
25
+ "@live-change/framework": "^0.8.26",
26
+ "@live-change/relations-plugin": "^0.8.26",
27
27
  "pluralize": "^8.0.0"
28
28
  },
29
- "gitHead": "63e942caccbcb1c9bfbd1a3ef1d097124514c5a7"
29
+ "gitHead": "e62696aa9fa6e5b86312dfb64c97efa300d41147"
30
30
  }
package/userItem.js CHANGED
@@ -113,7 +113,7 @@ definition.processor(function(service, app) {
113
113
  async execute(properties, { client, service }, emit) {
114
114
  const entity = await modelRuntime().get(properties[modelPropertyName])
115
115
  if(!entity) throw 'not_found'
116
- if(entity.user != client.user) throw 'not_authorized'
116
+ if(entity.user !== client.user) throw 'not_authorized'
117
117
  let updateObject = {}
118
118
  for(const propertyName of writeableProperties) {
119
119
  if(properties.hasOwnProperty(propertyName)) {
@@ -152,7 +152,7 @@ definition.processor(function(service, app) {
152
152
  async execute(properties, { client, service }, emit) {
153
153
  const entity = await modelRuntime().get(properties[modelPropertyName])
154
154
  if(!entity) throw 'not_found'
155
- if(entity.user != client.user) throw 'not_authorized'
155
+ if(entity.user !== client.user) throw 'not_authorized'
156
156
  emit({
157
157
  type: eventName,
158
158
  [modelPropertyName]: entity.id,