@live-change/message-authentication-service 0.2.5 → 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 +58 -27
  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
  }
@@ -196,7 +209,8 @@ definition.action({
196
209
  action,
197
210
  contactType,
198
211
  contact,
199
- secrets
212
+ secrets,
213
+ ...authentication.messageData
200
214
  }
201
215
  })
202
216
  return {
@@ -234,11 +248,12 @@ definition.trigger({
234
248
  properties: {
235
249
  ...contactProperties
236
250
  },
237
- async execute({ contactType, contact }, { client, service }, emit) {
251
+ async execute({ contactType, contact, session }, { client, service }, emit) {
238
252
  const contactTypeUpperCase = contactType[0].toUpperCase() + contactType.slice(1)
239
253
  const user = await service.trigger({
240
254
  type: 'signIn' + contactTypeUpperCase,
241
255
  [contactType]: contact,
256
+ session
242
257
  })
243
258
  return user
244
259
  }
@@ -259,54 +274,70 @@ for(const contactType of config.contactTypes) {
259
274
  }
260
275
  }
261
276
 
262
- if(contactConfig.signUp || config.signUp || contactConfig.signIn || config.signIn) {
277
+ if(contactConfig.signUp || config.signUp) {
263
278
  definition.action({
264
- name: 'signIn' + contactTypeUpperCaseName,
279
+ name: 'signUp' + contactTypeUpperCaseName,
265
280
  waitForEvents: true,
266
281
  properties: {
267
282
  ...contactTypeProperties
268
283
  },
269
284
  async execute({ [contactTypeName]: contact }, { client, service }, emit) {
270
-
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
+ })
271
296
  }
272
297
  })
273
298
  }
274
299
 
275
- if(contactConfig.connect || config.connect ) {
300
+ if(contactConfig.signUp || config.signUp || contactConfig.signIn || config.signIn) {
276
301
  definition.action({
277
- name: 'connect',
302
+ name: 'signIn' + contactTypeUpperCaseName,
303
+ waitForEvents: true,
278
304
  properties: {
279
305
  ...contactTypeProperties
280
306
  },
281
307
  async execute({ [contactTypeName]: contact }, { client, service }, emit) {
282
-
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
+ })
283
323
  }
284
324
  })
285
325
  }
286
326
 
287
- if(contactConfig.signUp || config.signUp) {
327
+ if(contactConfig.connect || config.connect ) {
288
328
  definition.action({
289
- name: 'signUp' + contactTypeUpperCaseName,
290
- waitForEvents: true,
329
+ name: 'connect',
291
330
  properties: {
292
331
  ...contactTypeProperties
293
332
  },
294
333
  async execute({ [contactTypeName]: contact }, { client, service }, emit) {
295
- await service.trigger({
296
- type: 'checkNew' + contactTypeUName,
297
- [contactType]: contact,
298
- })
299
- return service.triggerService(definition.name, {
300
- type: 'authenticateWithMessage',
301
- contactType,
302
- contact,
303
- action: 'signUpWithMessage',
304
- targetPage: config.signUpTargetPage || { name: 'user:signUpFinished' }
305
- })
334
+
306
335
  }
307
336
  })
308
337
  }
309
338
 
339
+
340
+
310
341
  if(contactConfig.signUp || config.signUp) {
311
342
  definition.action({
312
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.5",
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": "e9f8af40d836388f6847cf958c1d941dc8e273b1"
27
+ "gitHead": "2491e82b350403cf187887e8f06d140e0c362860"
28
28
  }