@live-change/message-authentication-service 0.2.2 → 0.2.6

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.
Files changed (2) hide show
  1. package/index.js +70 -32
  2. package/package.json +2 -2
package/index.js CHANGED
@@ -41,11 +41,18 @@ const targetProperties = {
41
41
  }
42
42
  }
43
43
 
44
+ const messageProperties = {
45
+ messageData: {
46
+ type: Object
47
+ }
48
+ }
49
+
44
50
  const Authentication = definition.model({
45
51
  name: 'Authentication',
46
52
  properties: {
47
53
  ...contactProperties,
48
54
  ...targetProperties,
55
+ ...messageProperties,
49
56
  state: {
50
57
  type: "String",
51
58
  validation: ['nonEmpty'],
@@ -69,11 +76,12 @@ definition.view({
69
76
 
70
77
  definition.event({
71
78
  name: 'authenticationCreated',
72
- execute({ authentication, contactType, contact, action, actionProperties, targetPage }) {
79
+ execute({ authentication, contactType, contact, action, actionProperties, targetPage, messageData }) {
73
80
  return Authentication.create({
74
81
  id: authentication,
75
82
  contactType, contact,
76
83
  action, actionProperties, targetPage,
84
+ messageData,
77
85
  state: 'created'
78
86
  })
79
87
  }
@@ -91,9 +99,11 @@ definition.trigger({
91
99
  waitForEvents: true,
92
100
  properties: {
93
101
  ...contactProperties,
94
- ...targetProperties
102
+ ...targetProperties,
103
+ ...messageProperties
95
104
  },
96
- async execute({ contactType, contact, action, actionProperties, targetPage }, { client, service }, emit) {
105
+ async execute({ contactType, contact, action, actionProperties, targetPage, messageData },
106
+ { client, service }, emit) {
97
107
  const authentication = app.generateUid()
98
108
  const secrets = await service.trigger({
99
109
  type: 'authenticationSecret',
@@ -107,7 +117,8 @@ definition.trigger({
107
117
  action,
108
118
  contactType,
109
119
  contact,
110
- secrets
120
+ secrets,
121
+ ...messageData
111
122
  }
112
123
  })
113
124
  emit({
@@ -117,9 +128,11 @@ definition.trigger({
117
128
  contact,
118
129
  action,
119
130
  actionProperties,
120
- targetPage
131
+ targetPage,
132
+ messageData
121
133
  })
122
134
  return {
135
+ type: 'sent',
123
136
  authentication,
124
137
  secrets: secrets.map(({ secret, ...notSecret }) => notSecret)
125
138
  }
@@ -137,15 +150,19 @@ definition.action({
137
150
  secret: {
138
151
  type: String,
139
152
  validation: ['nonEmpty']
153
+ },
154
+ authentication: {
155
+ type: Authentication
140
156
  }
141
157
  },
142
- async execute({ secretType, secret }, { client, service }, emit) {
158
+ async execute({ secretType, secret, authentication = undefined }, { client, service }, emit) {
143
159
  const secretTypeUpperCase = secretType[0].toUpperCase() + secretType.slice(1)
144
160
  const checkResults = await service.trigger({
145
161
  type: 'check' + secretTypeUpperCase + 'Secret',
146
- secret
162
+ secret,
163
+ authentication
147
164
  })
148
- const authentication = checkResults[0]
165
+ authentication = checkResults[0]
149
166
  const authenticationData = await Authentication.get(authentication)
150
167
  if(authenticationData.state == 'used') throw 'authenticationUsed'
151
168
  const actionName = authenticationData.action
@@ -153,14 +170,17 @@ definition.action({
153
170
  type: actionName+'Authenticated',
154
171
  ...authenticationData.actionProperties,
155
172
  contactType: authenticationData.contactType,
156
- contact: autoValidation.contact,
173
+ contact: authenticationData.contact,
157
174
  session: client.session
158
175
  })
159
176
  emit({
160
177
  type: 'authenticationUsed',
161
178
  authentication
162
179
  })
163
- return actionResults[0]
180
+ return {
181
+ result: actionResults[0],
182
+ targetPage: authenticationData.targetPage
183
+ }
164
184
  }
165
185
  })
166
186
 
@@ -189,7 +209,8 @@ definition.action({
189
209
  action,
190
210
  contactType,
191
211
  contact,
192
- secrets
212
+ secrets,
213
+ ...authentication.messageData
193
214
  }
194
215
  })
195
216
  return {
@@ -227,11 +248,12 @@ definition.trigger({
227
248
  properties: {
228
249
  ...contactProperties
229
250
  },
230
- async execute({ contactType, contact }, { client, service }, emit) {
251
+ async execute({ contactType, contact, session }, { client, service }, emit) {
231
252
  const contactTypeUpperCase = contactType[0].toUpperCase() + contactType.slice(1)
232
253
  const user = await service.trigger({
233
254
  type: 'signIn' + contactTypeUpperCase,
234
255
  [contactType]: contact,
256
+ session
235
257
  })
236
258
  return user
237
259
  }
@@ -252,54 +274,70 @@ for(const contactType of config.contactTypes) {
252
274
  }
253
275
  }
254
276
 
255
- if(contactConfig.signUp || config.signUp || contactConfig.signIn || config.signIn) {
277
+ if(contactConfig.signUp || config.signUp) {
256
278
  definition.action({
257
- name: 'signIn' + contactTypeUpperCaseName,
279
+ name: 'signUp' + contactTypeUpperCaseName,
258
280
  waitForEvents: true,
259
281
  properties: {
260
282
  ...contactTypeProperties
261
283
  },
262
284
  async execute({ [contactTypeName]: contact }, { client, service }, emit) {
263
-
285
+ await service.trigger({
286
+ type: 'checkNew' + contactTypeUName,
287
+ [contactType]: contact,
288
+ })
289
+ return service.triggerService(definition.name, {
290
+ type: 'authenticateWithMessage',
291
+ contactType,
292
+ contact,
293
+ action: 'signUpWithMessage',
294
+ targetPage: config.signUpTargetPage || { name: 'user:signUpFinished' }
295
+ })
264
296
  }
265
297
  })
266
298
  }
267
299
 
268
- if(contactConfig.connect || config.connect ) {
300
+ if(contactConfig.signUp || config.signUp || contactConfig.signIn || config.signIn) {
269
301
  definition.action({
270
- name: 'connect',
302
+ name: 'signIn' + contactTypeUpperCaseName,
303
+ waitForEvents: true,
271
304
  properties: {
272
305
  ...contactTypeProperties
273
306
  },
274
307
  async execute({ [contactTypeName]: contact }, { client, service }, emit) {
275
-
308
+ const contactData = await service.trigger({
309
+ type: 'get' + contactTypeUName,
310
+ [contactType]: contact,
311
+ })
312
+ const messageData = {
313
+ user: contactData.user
314
+ }
315
+ return service.triggerService(definition.name, {
316
+ type: 'authenticateWithMessage',
317
+ contactType,
318
+ contact,
319
+ messageData,
320
+ action: 'signInWithMessage',
321
+ targetPage: config.signInTargetPage || { name: 'user:signInFinished' }
322
+ })
276
323
  }
277
324
  })
278
325
  }
279
326
 
280
- if(contactConfig.signUp || config.signUp) {
327
+ if(contactConfig.connect || config.connect ) {
281
328
  definition.action({
282
- name: 'signUp' + contactTypeUpperCaseName,
283
- waitForEvents: true,
329
+ name: 'connect',
284
330
  properties: {
285
331
  ...contactTypeProperties
286
332
  },
287
333
  async execute({ [contactTypeName]: contact }, { client, service }, emit) {
288
- await service.trigger({
289
- type: 'checkNew' + contactTypeUName,
290
- [contactType]: contact,
291
- })
292
- return service.triggerService(definition.name, {
293
- type: 'authenticateWithMessage',
294
- contactType,
295
- contact,
296
- action: 'signUpWithMessage',
297
- targetPage: config.signUpTargetPage || { name: 'user:signUpFinished' }
298
- })
334
+
299
335
  }
300
336
  })
301
337
  }
302
338
 
339
+
340
+
303
341
  if(contactConfig.signUp || config.signUp) {
304
342
  definition.action({
305
343
  name: 'signInOrSignUp' + contactTypeUpperCaseName,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@live-change/message-authentication-service",
3
- "version": "0.2.2",
3
+ "version": "0.2.6",
4
4
  "description": "",
5
5
  "main": "index.js",
6
6
  "scripts": {
@@ -24,5 +24,5 @@
24
24
  "@live-change/framework": "^0.5.7",
25
25
  "nodemailer": "^6.7.2"
26
26
  },
27
- "gitHead": "7691357c7569a18373668691eb6a81a9e161194d"
27
+ "gitHead": "2491e82b350403cf187887e8f06d140e0c362860"
28
28
  }